-
Notifications
You must be signed in to change notification settings - Fork 1
/
app-i18n.html
114 lines (88 loc) · 3.03 KB
/
app-i18n.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<!--
@license
Copyright (c) 2017 The expand.js authors. All rights reserved.
This code may only be used under the BSD style license found at https://expandjs.github.io/LICENSE.txt
The complete set of authors may be found at https://expandjs.github.io/AUTHORS.txt
The complete set of contributors may be found at https://expandjs.github.io/CONTRIBUTORS.txt
-->
<!--
A web component used to provide i18n support.
@element app-i18n
@since 1.0.0
@category functionality
@description A web component used to provide i18n support
@keywords expandjs, web app, web components
@homepage https://expandjs.com/components/app-i18n
@repository https://github.com/expandjs/app-behaviors
@source https://github.com/expandjs/app-behaviors/blob/master/app-i18n.html
@behavior xp-meta-behavior /bower_components/xp-elements/xp-meta-behavior.html
-->
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../expandjs/expandjs.html">
<link rel="import" href="../xp-elements/xp-meta-behavior.html">
<dom-module id="app-i18n">
<template strip-whitespace>
<style>
:host {
display: none !important;
}
</style>
<slot></slot>
</template>
<script>
Polymer({
// ELEMENT
is: 'app-i18n',
// BEHAVIORS
behaviors: [
Polymer.XPMetaBehavior
],
/*********************************************************************/
/**
* Fired when the i18n has been parsed.
*
* @event app-i18n
* @param {string} namespace
* @param {string} locale
* @param {Object} data
* @bubbles
*/
/*********************************************************************/
// OBSERVERS
observers: [
'_dataChanged(data)'
],
// PROPERTIES
properties: {
/**
* The i18n's locale.
*
* @attribute locale
* @type string
*/
locale: {
type: String
},
/**
* The i18n's namespace.
*
* @attribute namespace
* @type string
*/
namespace: {
type: String
}
},
/*********************************************************************/
// OBSERVER
_dataChanged() {
// Preventing
if (!this.data || !this.locale || !this.namespace) { return; }
// Setting
XP.set(window, `app.${this.namespace}.i18n.${this.locale}`, XP.freezeDeep(this.data));
// Firing
this.fire(`app-i18n`, {data: this.data, locale: this.locale, namespace: this.namespace}, {node: window});
}
});
</script>
</dom-module>