Skip to content

Commit 871f792

Browse files
committed
Improve localization
1 parent 6168bb4 commit 871f792

File tree

12 files changed

+33
-53
lines changed

12 files changed

+33
-53
lines changed

api/feature.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@ class Feature {
88
});
99
this.data = finalFeature;
1010
this.msg = function (string) {
11-
if (this.data.translations) {
12-
return this.data.localesData[string];
13-
} else {
14-
throw new Error("Feature does not have locales set up.");
15-
}
11+
return this.data.localesData[`${this.data.id}/`+string] || `ScratchTools.${this.data.id}.${string}`;
1612
};
1713
this.getActiveUserstyles = function () {
1814
var styles = document.head.querySelectorAll(

extras/background.js

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -445,25 +445,30 @@ chrome.tabs.onUpdated.addListener(async function (tabId, info) {
445445
).json();
446446
featureData.id = feature.id;
447447
featureData.version = feature.version;
448-
if (featureData.translations) {
449-
if (chrome.i18n.getUILanguage().includes("-")) {
450-
var language = chrome.i18n.getUILanguage().split("-")[0];
451-
} else {
452-
var language = chrome.i18n.getUILanguage();
453-
}
454-
if (featureData.translations.includes(language)) {
455-
var localesData = await (
456-
await fetch(
457-
`/features/${featureData.id}/locales/${language}.json`
458-
)
459-
).json();
460-
} else {
461-
var localesData = await (
462-
await fetch(`/features/${featureData.id}/locales/en.json`)
448+
if (chrome.i18n.getUILanguage().includes("-")) {
449+
var language = chrome.i18n.getUILanguage().split("-")[0];
450+
} else {
451+
var language = chrome.i18n.getUILanguage();
452+
}
453+
let localesData = {};
454+
try {
455+
localesData = await (
456+
await fetch(
457+
`/feature-locales/${featureData.id}/${language}.json`
458+
)
459+
).json();
460+
} catch (err) {
461+
try {
462+
localesData = await (
463+
await fetch(`/feature-locales/${featureData.id}/en.json`)
463464
).json();
464-
}
465-
featureData.localesData = localesData;
465+
} catch (err) {}
466466
}
467+
let locales = {};
468+
Object.keys(localesData).forEach(function (el) {
469+
locales[`${featureData.id}/${el}`] = localesData[el];
470+
});
471+
featureData.localesData = locales;
467472
newFullData.push(featureData);
468473
} else {
469474
newFullData.push(feature);
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"save": "Save",
3+
"unsave": "Unsave",
4+
"watch-later": "Watch Later"
5+
}

features/isonline/data.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
"styles": [{ "file": "style.css", "runOn": "/users/*" }],
1111
"scripts": [{ "file": "script.js", "runOn": "/users/*", "module": true }],
1212
"additionalAgreements": "By enabling this feature, you understand that other users will be able to see if you are online or not.",
13-
"translations": ["en", "tr", "de", "es", "fr", "ru"],
1413
"similar": ["display-name", "emoji-status"]
1514
}
1615

features/isonline/locales/de.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

features/isonline/locales/es.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

features/isonline/locales/fr.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

features/isonline/locales/ru.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

features/isonline/locales/tr.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)