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
*/
const path = require('path');
const I18n = require('i18n-2');
module.exports = {
sync: true,
@@ -14,9 +17,21 @@ module.exports = {
},
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);
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;
},
};