-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
143 lines (132 loc) · 3.28 KB
/
index.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<!DOCTYPE html>
<html>
<head>
<title>Translations</title>
<script type="text/javascript" src="./vue.min.js"></script>
<style type="text/css">
.is-fullwidth {
width: 100%;
}
.is-inline-block {
display: inline-block;
}
.is-flex {
display: flex;
justify-content: space-around;
align-items: center;
}
.is-rtl {
text-align: right;
direction: rtl;
}
</style>
</head>
<body>
<div id="app" style="width: 100vw;">
<div class="is-fullwidth is-flex">
<div style="display: inline-block;">
<h1>Translations</h1>
</div>
<div style="display: inline-block;">
<button id="add-lang" @click="addLanguage">add language</button>
</div>
</div>
<hr>
<table class="is-fullwidth">
<thead>
<tr>
<th style="width: 300px;">key</th>
<th v-for="lang in languages">
{{ lang }}
<button @click="exportLangMessages(lang)">↑</button>
<button @click="promptLangMessages(lang)">↓</button>
</th>
</tr>
</thead>
<tbody>
<tr v-for="(message, key) in messages">
<td style="width: 300px;">{{ key }}</td>
<td v-for="lang in languages">
<input
class="{'is-rtl': lang === 'AR'}"
v-model="message[lang]" class="is-fullwidth">
</td>
</tr>
<tr style="background-color: red">
<td>
<input placeholder="new translation entry" type="text" v-model="newItem.key" class="is-fullwidth is-inline-block">
</td>
<td v-for="lang in languages">
<input type="text" v-model="newItem[lang]" class="is-fullwidth">
</td>
</tr>
<tr style="background-color: red">
<td style="text-align: center" :colspan="languages.length + 1">
<button class="is-fullwidth" :disabled="!newItem.key" @click="newTranslation">Add Key</button>
</td>
</tr>
</tbody>
</table>
<hr>
<h3>Clipboard</h3>
<input :value="clipboard" id="for-copy">
</div>
<script type="text/javascript">
var app = new Vue({
el: '#app',
data () {
return {
newItem: {key: ''},
messages: {},
languages: ['EN', 'AR'],
clipboard: ''
}
},
methods: {
newTranslation () {
if (this.newItem.key) {
this.messages[this.newItem.key] = this.newItem
delete this.messages[this.newItem.key].key
}
this.newItem = {}
},
exportLangMessages (lang) {
let acc = {}
for (let k in this.messages) {
if ((this.messages[k] || {})[lang]) {
acc[k] = this.messages[k][lang]
}
}
this.clipboard = JSON.stringify(acc);
document.execCommand("copy");
/* Get the text field */
var copyText = document.getElementById("for-copy");
/* Select the text field */
copyText.select();
copyText.setSelectionRange(0, 99999); /*For mobile devices*/
/* Copy the text inside the text field */
document.execCommand("copy");
/* Alert the copied text */
alert("messages copied for lang " + lang);
},
promptLangMessages (lang) {
let json = prompt('insert messages as JSON for ' + lang);
var lMessages = JSON.parse(json);
for (let k in lMessages) {
this.messages[k] = this.messages[k] || {}
this.messages[k][lang] = lMessages[k]
}
this.$forceUpdate()
},
addLanguage () {
let newLang = prompt('insert language code')
if (!newLang) {
return
}
this.languages.push(newLang.toUpperCase())
}
}
})
</script>
</body>
</html>