Skip to content

Commit

Permalink
add widespread locales locally
Browse files Browse the repository at this point in the history
  • Loading branch information
phosphore committed Dec 7, 2022
1 parent 2bc5b5f commit 44c0b74
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
"author": "[email protected]",
"license": "Apache-2.0",
"i18nSource": "https://electronegativity-i18n.s3.us-west-2.amazonaws.com/",
"i18nSource": "https://electronegativity-i18n.s3.us-west-2.amazonaws.com",
"bugs": {
"url": "https://github.com/doyensec/electronegativity/issues"
},
Expand Down
2 changes: 1 addition & 1 deletion src/locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,5 @@
"LIMIT_NAVIGATION_GLOBAL_CHECK_NONE_FOUND":"Missing navigation limits using .on new-window and will-navigate events",
"LIMIT_NAVIGATION_GLOBAL_CHECK_NEW_WINDOW_MISSING":"Missing .on new-window navigation limit",
"LIMIT_NAVIGATION_GLOBAL_CHECK_WILL_NAVIGATE_MISSING":"Missing .on will-navigate navigation limit",
"PERMISSION_REQUEST_HANDLER_GLOBAL_CHECK":"Missing PermissionRequestHandler to limit specific permissions (e.g. openExternal) in response to events from particular origins.",
"PERMISSION_REQUEST_HANDLER_GLOBAL_CHECK":"Missing PermissionRequestHandler to limit specific permissions (e.g. openExternal) in response to events from particular origins."
}
11 changes: 6 additions & 5 deletions src/locales/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default function _i18n () {
return new Promise((resolve, reject) => {
var defaultLocale = "en-US";
i18n.configure({
locales: ['en-US'], // widespread locales available locally
locales: ['en-US', 'es-ES', 'fr-FR'], // some widespread locales available locally
defaultLocale: defaultLocale,
directory: __dirname,
updateFiles: false,
Expand All @@ -16,17 +16,18 @@ export default function _i18n () {

defaultLocale = process.env.LANG ? process.env.LANG : defaultLocale;
const i18nSource = require('../../package.json').i18nSource;
return got(`${i18nSource}/${defaultLocale}.json`)
got(`${i18nSource}/${defaultLocale}.json`, {timeout: {request: 1000}})
.then(r => {
if (r.statusCode === 200) {// Add JSON translations to i18n
i18n.addLocale(defaultLocale, JSON.parse(r.body));
i18n.setLocale(defaultLocale);
resolve(); // resolve the promise when the setLocale is set
}
resolve(); // resolve the promise
})
.catch(e => {
// Could not retrieve updated translations for the current locale
reject(e);
console.log("Could not retrieve updated translations for the current locale");
i18n.setLocale(defaultLocale);
resolve();
});
});
};

0 comments on commit 44c0b74

Please sign in to comment.