-
Notifications
You must be signed in to change notification settings - Fork 19
/
localize-behavior.html
76 lines (68 loc) · 2.14 KB
/
localize-behavior.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
<!--
@license
Copyright (c) 2016 Convoo All Rights Reserved.
Use of this source code is governed by a MIT license that can be found in the
LICENSE file or at https://github.com/convoo/login-fire/blob/master/LICENSE.
-->
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../app-localize-behavior/app-localize-behavior.html">
<link rel="import" href="./locales.html">
<script>
(function() {
'use strict';
window.Convoo = window.Convoo || {};
/**
* Behavior that brings localization ability to an element.
*
* @polymerBehavior Convoo.LocalizeBehavior
*/
Convoo.LocalizeBehaviorImpl = {
properties: {
/**
* Sets the language to use.
*
* @type {String}
*/
language: {
type: String,
value: 'en'
},
/**
* Path to an external file containing locales. If the value is set, the
* target file will be used instead of the default one _("locales.html")_.
*
* The target file must be in JSON format. Be sure the file is kept
* during the build of your project. By default, the Polymer build pipe
* loses JSON files during the optimization.
*
* For more detail about the file format, please read the
* <a href="https://github.com/PolymerElements/app-localize-behavior">AppLocalizeBehavior</a>
* documentation.
*
* @type {String}
*/
localesFile: {
type: String,
observer: '_localesFileChanged'
},
},
attached: function() {
if (!this.localesFile || this.localesFile.trim().length == 0) {
this.set('resources', window.Convoo._locales);
}
},
/**
* Loads locales file for internationalization.
*/
_localesFileChanged: function() {
if (this.localesFile && this.localesFile.trim().length != 0) {
this.loadResources(this.resolveUrl(this.localesFile));
}
}
};
Convoo.LocalizeBehavior = [
Polymer.AppLocalizeBehavior,
Convoo.LocalizeBehaviorImpl
];
}());
</script>