mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-27 09:06:15 +01:00
committed by
GitHub
parent
edf80cfb3b
commit
344575dde1
@@ -2,7 +2,19 @@
|
|||||||
|
|
||||||
(function (factory) {
|
(function (factory) {
|
||||||
function loadClient(language, namespace) {
|
function loadClient(language, namespace) {
|
||||||
return Promise.resolve(jQuery.getJSON([config.assetBaseUrl, 'language', language, namespace].join('/') + '.json?' + config['cache-buster']));
|
return new Promise(function (resolve, reject) {
|
||||||
|
jQuery.getJSON([config.assetBaseUrl, 'language', language, namespace].join('/') + '.json?' + config['cache-buster'], function (data) {
|
||||||
|
const payload = {
|
||||||
|
language: language,
|
||||||
|
namespace: namespace,
|
||||||
|
data: data,
|
||||||
|
};
|
||||||
|
$(window).trigger('action:translator.loadClient', payload);
|
||||||
|
resolve(payload.promise ? Promise.resolve(payload.promise) : data);
|
||||||
|
}).fail(function (jqxhr, textStatus, error) {
|
||||||
|
reject(new Error(textStatus + ', ' + error));
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
var warn = function () { console.warn.apply(console, arguments); };
|
var warn = function () { console.warn.apply(console, arguments); };
|
||||||
if (typeof define === 'function' && define.amd) {
|
if (typeof define === 'function' && define.amd) {
|
||||||
@@ -549,6 +561,18 @@
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
flushNamespace: function (namespace) {
|
||||||
|
Object.keys(Translator.cache).forEach(function (code) {
|
||||||
|
if (Translator.cache[code] &&
|
||||||
|
Translator.cache[code].translations &&
|
||||||
|
Translator.cache[code].translations[namespace]
|
||||||
|
) {
|
||||||
|
Translator.cache[code].translations[namespace] = null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Legacy translator function for backwards compatibility
|
* Legacy translator function for backwards compatibility
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ const fs = require('fs');
|
|||||||
const path = require('path');
|
const path = require('path');
|
||||||
const utils = require('./utils');
|
const utils = require('./utils');
|
||||||
const { paths } = require('./constants');
|
const { paths } = require('./constants');
|
||||||
|
const plugins = require('./plugins');
|
||||||
|
|
||||||
const Languages = module.exports;
|
const Languages = module.exports;
|
||||||
const languagesPath = path.join(__dirname, '../build/public/language');
|
const languagesPath = path.join(__dirname, '../build/public/language');
|
||||||
@@ -13,7 +14,13 @@ Languages.timeagoCodes = files.filter(f => f.startsWith('jquery.timeago')).map(f
|
|||||||
|
|
||||||
Languages.get = async function (language, namespace) {
|
Languages.get = async function (language, namespace) {
|
||||||
const data = await fs.promises.readFile(path.join(languagesPath, language, `${namespace}.json`), 'utf8');
|
const data = await fs.promises.readFile(path.join(languagesPath, language, `${namespace}.json`), 'utf8');
|
||||||
return JSON.parse(data) || {};
|
const parsed = JSON.parse(data) || {};
|
||||||
|
const result = await plugins.hooks.fire('filter:languages.get', {
|
||||||
|
language,
|
||||||
|
namespace,
|
||||||
|
data: parsed,
|
||||||
|
});
|
||||||
|
return result.data;
|
||||||
};
|
};
|
||||||
|
|
||||||
let codeCache = null;
|
let codeCache = null;
|
||||||
|
|||||||
Reference in New Issue
Block a user