-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathx-languages.html
55 lines (55 loc) · 1.37 KB
/
x-languages.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
<link rel="import" href="bower_components/iron-ajax/iron-ajax.html">
<dom-module id="x-languages">
<style>
:host {
display: inline;
}
.detected-language {
color: gray;
border: 1px solid gray;
font-size: 10pt;
padding: 3px;
}
</style>
<template>
<iron-ajax id="ajax"
url="https://www.googleapis.com/language/translate/v2/languages"
handle-as="json"
on-response="handleResponse"></iron-ajax>
<select id="languages">
<template is="dom-repeat" items="{{languages}}" as="language">
<option value="{{language.language}}">{{language.name}}</option>
</template>
</select>
</template>
</dom-module>
<script>
(function () {
Polymer({
is: 'x-languages',
properties: {
target: {
type: String,
value: (navigator.browserLanguage || navigator.language ||
navigator.userLanguage).substr(0,2) || 'en',
notify: true
}
},
ready: function () {
this.$.ajax.params = {
"key": "AIzaSyCvmuME4nuAt6dsYwM6SKSvpYyn3a_DcnU",
"target": this.target
};
this.$.ajax.generateRequest();
var element = this.$.languages;
element.addEventListener('change', function () {
console.log(element.options[element.selectedIndex].value);
});
},
handleResponse: function (request) {
this.languages = request.detail.response.data.languages;
}
}
);
})();
</script>