fix: Create isolated i18n instances to prevent locale collision

This commit is contained in:
Maksim Eltyshev
2025-11-27 18:28:25 +01:00
parent 54e230d4c1
commit bf2ab4649e
3 changed files with 19 additions and 2 deletions

View File

@@ -3,6 +3,9 @@
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md * Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
*/ */
const path = require('path');
const I18n = require('i18n-2');
module.exports = { module.exports = {
sync: true, sync: true,
@@ -14,9 +17,21 @@ module.exports = {
}, },
fn(inputs) { fn(inputs) {
const i18n = _.cloneDeep(sails.hooks.i18n); const i18n = new I18n({
locales: sails.config.i18n.locales,
defaultLocale: sails.config.i18n.defaultLocale,
directory: path.join(sails.config.appPath, sails.config.i18n.localesDirectory),
extension: '.json',
devMode: false,
});
i18n.setLocale(inputs.language || sails.config.i18n.defaultLocale); i18n.setLocale(inputs.language || sails.config.i18n.defaultLocale);
return i18n.__.bind(i18n); // eslint-disable-line no-underscore-dangle /* eslint-disable no-underscore-dangle */
const translator = i18n.__.bind(i18n);
translator.n = i18n.__n.bind(i18n);
/* eslint-enable no-underscore-dangle */
return translator;
}, },
}; };

View File

@@ -16,6 +16,7 @@
"escape-html": "^1.0.3", "escape-html": "^1.0.3",
"escape-markdown": "^1.0.4", "escape-markdown": "^1.0.4",
"fs-extra": "^11.3.2", "fs-extra": "^11.3.2",
"i18n-2": "^0.7.3",
"ico-to-png": "^0.2.2", "ico-to-png": "^0.2.2",
"istextorbinary": "^9.5.0", "istextorbinary": "^9.5.0",
"jsonwebtoken": "^9.0.2", "jsonwebtoken": "^9.0.2",

View File

@@ -52,6 +52,7 @@
"escape-html": "^1.0.3", "escape-html": "^1.0.3",
"escape-markdown": "^1.0.4", "escape-markdown": "^1.0.4",
"fs-extra": "^11.3.2", "fs-extra": "^11.3.2",
"i18n-2": "^0.7.3",
"ico-to-png": "^0.2.2", "ico-to-png": "^0.2.2",
"istextorbinary": "^9.5.0", "istextorbinary": "^9.5.0",
"jsonwebtoken": "^9.0.2", "jsonwebtoken": "^9.0.2",