Skip to content

Commit a069bfb

Browse files
committed
chore: more translations
1 parent d0adcd3 commit a069bfb

File tree

8 files changed

+148
-59
lines changed

8 files changed

+148
-59
lines changed

lang/en/general.json

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,26 @@
11
{
2+
"changelog": "UnderScript Change Log",
3+
"changelog.loading": "Please wait",
4+
"changelog.unavailable": "Unavailable at this time",
5+
"message.hidden": "Message Ignored",
6+
"message.removed": "$1 {{PLURAL:$1|Message|Messages}} Ignored",
27
"deck.average": "Average gold cost",
38
"passive": "Passive",
4-
"reconnecting": "Reconnecting..."
9+
"reconnecting": "Reconnecting...",
10+
"profile": "Profile",
11+
"message": "Message",
12+
"ignore": "Ignore",
13+
"unignore": "Unignore",
14+
"mention": "Mention",
15+
"mute": "Mute",
16+
"refresh": "Refresh Page",
17+
"update.current": "Current: $1",
18+
"update.new": "Update to $1",
19+
"update.open": "Show Updates",
20+
"updates": "Pending Updates",
21+
"dismiss": "Dismiss",
22+
"open": "Open",
23+
"undo": "Undo",
24+
"update": "Update",
25+
"unknown": "Unknown"
526
}

lang/en/menu.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@
22
"menu": "Menu",
33
"menu.title": "MENU",
44
"changelog": "UnderScript Change Log",
5-
"updates": "Check for updates",
5+
"changelog.note": "Unavailable on this page",
6+
"update": "Check for updates",
7+
"update.note": "Last Checked: $1",
68
"gamelog": "Game Patch Notes",
79
"reload": "Reload Cards",
810
"settings": "Settings",
911
"settings.note": "Settings temporarily unavailable",
1012
"streamer.on": "Streamer Mode: On",
1113
"streamer.off": "Streamer Mode: Off",
1214
"surrender": "Surrender",
13-
"surrender.note": "You can't surrender before turn 5."
15+
"surrender.note": "You can't surrender before turn 5.",
16+
"update.checking.note": "Check for updats",
17+
"update.pending": "Show Pending Updates"
1418
}

lang/en/settings.json

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
"category.streamer": "Streamer Mode",
1818
"category.home": "Home",
1919
"category.library.crafting": "Crafting",
20+
"category.plugins": "Plugins",
21+
"category.updates": "Updates",
2022
"deck.average": "Disable deck average counter",
2123
"deck.preview": "Disable Deck Preview",
2224
"disable.border": "Disable Crafting Highlight",
@@ -26,11 +28,16 @@
2628
"disable.disenchant": "Disable Smart Disenchanting",
2729
"disable.disenchant.note": "Enable at own risk",
2830
"disable.emote": "Disable $1",
29-
"disable.rightclick": "Disable Chat Context (right click)",
30-
"disable.ignoreChat": "Disable",
31+
"chat.rightclick": "Disable Chat Context (right click)",
3132
"disable.links": "Use Original Link Detection",
3233
"disable.ping": "Disable Chat Ping {{STYLE:highlight|(highlighting)}}",
33-
"ignoreChat": "Behavior",
34+
"ignore": "Disable",
35+
"ignore.how": "Behavior",
36+
"ignore.option": [
37+
"remove",
38+
"hide",
39+
"none"
40+
],
3441
"import.shiny": "Prefer Shiny",
3542
"note.refresh": "Will require you to refresh the page.",
3643
"page.chat": "Chat",
@@ -44,13 +51,24 @@
4451
"safelink.trust": "Trust $1",
4552
"streamer": "Enable?",
4653
"streamer.note": "Enables a button on the menu, streamer mode is \"off\" by default.",
47-
"streamer.option.1": "Yes",
48-
"streamer.option.2": "Yes (silent)",
49-
"streamer.option.3": "No",
54+
"streamer.option": [
55+
"Yes",
56+
"Yes (silent)",
57+
"No"
58+
],
5059
"title": "UnderScript Configuration",
5160
"toast.bundle": "Enable bundle toast",
5261
"toast.cards": "Enable new Card toast",
5362
"toast.emotes": "Enable emote toast",
5463
"toast.pass": "Enable quest pass toast",
55-
"toast.skins": "Enable skin toast"
64+
"toast.skins": "Enable skin toast",
65+
"update": "Disable Auto Updates",
66+
"update.frequency": "Update Frequency",
67+
"update.frequency.option": [
68+
"Page Load (Not recommended)",
69+
"Hourly",
70+
"Daily"
71+
],
72+
"update.plugin": "Disable Auto Updates",
73+
"update.silent": "Run automatic updates in the background"
5674
}

lang/en/toast.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"dismiss": "Dismiss",
55
"ignore": "You've ignored $1",
66
"info": "Did you know?",
7+
"ignore.info": "You can right click users in chat to display user options!",
78
"menu": "UnderScript has a menu, press ESC to open it!",
89
"new.bundle": "New Bundle Available",
910
"new.card": "{{PLURAL:$1|New Card|New Cards}}",
@@ -20,5 +21,11 @@
2021
"game.request.denied": "Notifications denied",
2122
"game.request.message": "UnderScript would like to notify you when a game is found.",
2223
"game.update": "Undercards Update",
23-
"undo": "Undo"
24+
"undo": "Undo",
25+
"update": "Update",
26+
"update.available": "{{PLURAL:$1|Update|$1 updates|0=No updates}} available.",
27+
"update.checking": "Checking for updates. Please wait.",
28+
"update.title": "[UnderScript] Update Available!",
29+
"update.text": "Version $1.",
30+
"updater": "UnderScript updater"
2431
}

src/base/underscript/translation.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1+
import Translation from 'src/structures/constants/translation';
2+
import clone from 'src/utils/clone';
13
import eventManager from 'src/utils/eventManager';
24

5+
/** @type {Map<string, Translation[]>} */
6+
const arrays = new Map();
7+
38
// TODO: include base underscript.json in script so we always have something to show?
49
const translations = (async () => {
510
const response = await fetch(
@@ -8,9 +13,17 @@ const translations = (async () => {
813
cache: 'default',
914
},
1015
);
11-
const text = await response.text();
16+
const data = await response.text();
17+
const text = typeof GM_getResourceText === 'undefined' ?
18+
data :
19+
GM_getResourceText('underscript.json') || data;
1220
return JSON.parse(text, function reviver(key, value) {
1321
if (Array.isArray(value)) {
22+
if (!arrays.has(key)) {
23+
arrays.set(key, value.map(
24+
(_, i) => new Translation(`${key}.${i + 1}`, { prefix: null }),
25+
));
26+
}
1427
value.forEach((val, i) => {
1528
this[`${key}.${i + 1}`] = val;
1629
});
@@ -24,3 +37,15 @@ eventManager.on('translation:loaded', async () => {
2437
await $.i18n().load(await translations);
2538
eventManager.singleton.emit('translation:underscript');
2639
});
40+
41+
export function getLength(key) {
42+
return arrays.get(key)?.length ?? 0;
43+
}
44+
45+
/**
46+
* @param {string} key
47+
* @returns {Translation[]}
48+
*/
49+
export function getTranslationArray(key) {
50+
return clone(arrays.get(key)) ?? [];
51+
}

src/hooks/updates.js

Lines changed: 45 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,14 @@ import * as settings from 'src/utils/settings';
77
import each from 'src/utils/each';
88
import wrap from 'src/utils/2.pokemon';
99
import Translation from 'src/structures/constants/translation';
10-
import { buttonCSS, scriptVersion } from 'src/utils/1.variables';
10+
import { buttonCSS, DAY, scriptVersion, HOUR, UNDERSCRIPT } from 'src/utils/1.variables';
1111
import sleep from 'src/utils/sleep';
1212
import createParser from 'src/utils/parser';
1313
import DialogHelper from 'src/utils/DialogHelper';
1414
import { getVersion } from 'src/utils/plugin';
1515
import compound from 'src/utils/compoundEvent';
16+
import { getTranslationArray } from 'src/base/underscript/translation';
1617

17-
const HOUR = 60 * 60 * 1000;
18-
const DAY = 24 * HOUR;
1918
const CHECKING = 'underscript.update.checking'; // TODO: change to setting?
2019
const LAST = 'underscript.update.last'; // TODO: change to setting?
2120
const PREFIX = 'underscript.pending.';
@@ -24,33 +23,43 @@ let autoTimeout;
2423
let toast;
2524

2625
export const disabled = settings.register({
27-
// TODO: translation
28-
name: 'Disable Auto Updates',
26+
name: Translation.Setting('update'),
2927
key: 'underscript.disable.updates',
30-
// TODO: translation
31-
category: 'Updates',
28+
category: Translation.CATEGORY_UPDATES,
3229
});
3330

3431
export const silent = settings.register({
35-
name: 'Run automatic updates in the background',
32+
name: Translation.Setting('update.silent'),
3633
key: 'underscript.updates.silent',
37-
category: 'Updates',
34+
category: Translation.CATEGORY_UPDATES,
3835
});
3936

37+
const keys = {
38+
frequency: Translation.Setting('update.frequency.option').key,
39+
toast: Translation.Toast('updater'),
40+
button: Translation.General('updater.open'),
41+
checking: Translation.Toast('update.checking'),
42+
update: Translation.Menu('update'),
43+
updateNote: Translation.Menu('update.note', 1),
44+
available: Translation.Toast('update.available', 1),
45+
title: Translation.General('updates'),
46+
updateCurrent: Translation.General('update.current', 1),
47+
updateNew: Translation.General('update.new', 1),
48+
};
49+
4050
const frequency = settings.register({
41-
// TODO: translation
42-
name: 'Update Frequency',
51+
name: Translation.Setting('update.frequency'),
4352
key: 'underscript.updates.frequency',
44-
// TODO: translation
45-
data: [
46-
['Page Load', 0],
47-
['Hourly', HOUR],
48-
['Daily', DAY],
49-
],
53+
data: () => {
54+
const tls = getTranslationArray(keys.frequency);
55+
return [0, HOUR, DAY].map((val, i) => (tls ? [
56+
tls[i],
57+
val,
58+
] : val));
59+
},
5060
default: HOUR,
5161
type: 'select',
52-
// TODO: translation
53-
category: 'Updates',
62+
category: Translation.CATEGORY_UPDATES,
5463
transform(value) {
5564
return Number(value) || 0;
5665
},
@@ -121,12 +130,11 @@ function notify(text, addButton = false) {
121130
toast.setText(text);
122131
} else {
123132
toast = Toast({
124-
// TODO: translation
125-
title: 'UnderScript updater',
133+
title: keys.toast.translate(),
126134
text,
127135
className: 'dismissable',
128136
buttons: addButton ? {
129-
text: 'Show Updates',
137+
text: keys.button.translate(),
130138
className: 'dismiss',
131139
css: buttonCSS,
132140
onclick: open,
@@ -162,11 +170,9 @@ async function check(auto = true) {
162170
const updateFound = [...pendingUpdates.values()].filter(({ announce = true }) => announce).length;
163171
if (updateFound) {
164172
finish();
165-
// TODO: translation
166-
notify('Updates available.', true);
173+
notify(keys.available.translate(updateFound), true);
167174
} else if (!auto && !pendingUpdates.size) {
168-
// TODO: translation
169-
notify('No updates available.');
175+
notify(keys.available.translate(0));
170176
sleep(3000).then(finish);
171177
} else {
172178
sleep(1000).then(finish);
@@ -193,33 +199,31 @@ function setup() {
193199

194200
const updateFound = [...pendingUpdates.values()].filter(({ announce = true }) => announce).length;
195201
if (updateFound) {
196-
notify('Updates available.', true);
202+
notify(keys.available.translate(updateFound), true);
197203
}
198204
}
199205

200206
function open() {
201207
dialog.open({
202-
title: 'Pending Updates', // TODO: translation
208+
title: keys.title,
203209
message: build,
204210
});
205211
}
206212

207213
menu.addButton({
208-
// TODO: translation
209-
text: 'Check for updates',
214+
text: Translation.Menu('update'),
210215
action() {
211216
check(false);
212217
},
213218
note() {
214219
const last = Number(localStorage.getItem(LAST));
215-
// TODO: translation
216-
return `Last Checked: ${last ? luxon.DateTime.fromMillis(last).toLocaleString(luxon.DateTime.DATETIME_FULL) : 'never'}`;
220+
const when = last ? luxon.DateTime.fromMillis(last).toLocaleString(luxon.DateTime.DATETIME_FULL) : 'never';
221+
return keys.updateNote.translate(when);
217222
},
218223
});
219224

220225
menu.addButton({
221-
// TODO: translation
222-
text: 'Show Pending Updates',
226+
text: Translation.Menu('update.pending'),
223227
action: open,
224228
// note() {},
225229
hidden() {
@@ -230,8 +234,7 @@ menu.addButton({
230234
eventManager.on(':update', (auto) => {
231235
toast?.close();
232236
if (auto && silent.value()) return;
233-
// TODO: translation
234-
notify('Checking for updates. Please wait.');
237+
notify(keys.checking.translate());
235238
});
236239

237240
// Load pending updates
@@ -254,7 +257,7 @@ function build() {
254257
function refreshButton() {
255258
if (addedRefresh) return;
256259
dialog.prependButton({
257-
label: 'Refresh Page',
260+
label: Translation.General('refresh').translate(),
258261
cssClass: 'btn-success',
259262
action() {
260263
location.reload();
@@ -269,7 +272,7 @@ function build() {
269272
version,
270273
}) {
271274
const button = $(`<a>`)
272-
.text(`Update to ${version}`) // TODO: translation
275+
.text(keys.updateNew.translate(version))
273276
.attr({
274277
href: url,
275278
rel: 'noreferrer',
@@ -284,21 +287,21 @@ function build() {
284287
});
285288
container.append($('<fieldset>').append(
286289
$('<legend>').text(name),
287-
$('<div>').text(`Current: ${currentVersion || 'unknown'}`),
290+
$('<div>').text(keys.updateCurrent.translate(currentVersion || Translation.UNKNOWN.translate())),
288291
button,
289292
));
290293
}
291-
const underscript = pendingUpdates.get('UnderScript');
294+
const underscript = pendingUpdates.get(UNDERSCRIPT);
292295
if (underscript) {
293296
add({
294297
...underscript,
295-
name: 'UnderScript',
298+
name: UNDERSCRIPT,
296299
currentVersion: scriptVersion,
297300
});
298301
}
299302
[...pendingUpdates.entries()].forEach(
300303
([name, data]) => {
301-
if (name === 'UnderScript') return;
304+
if (name === UNDERSCRIPT) return;
302305
add({
303306
...data,
304307
name,

0 commit comments

Comments
 (0)