Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Internationalization: Language Support
- * Thanks for testing i18n function: NenkaLab<[email protected]>, and ManDongI<[email protected]>
- * @author Astro36<[email protected]>
- * @function i18n
- * @memberOf global
- * @param {String} text
- * @param {Array.<String>} [args]
- * @returns {String}
- */
- const i18n = (function () {
- const lang = CONTEXT.getResources().getConfiguration().locale.getLanguage(),
- langPath = PATH + "/lang/" + lang + ".json";
- if (new File_(langPath).exists() && useCustomLangTest) {
- const langObj = JSON.parse(getTextFromFile(langPath));
- return function (text, args) {
- if (text in langObj) {
- return langObj[text].replace(/(\{%\d+\})/g, function ($1) {
- return args[$1.match(/\{%(\d+)\}/)[1]];
- });
- }
- return text.replace(/(\{%\d+\})/g, function ($1) {
- return args[$1.match(/\{%(\d+)\}/)[1]];
- });
- };
- }
- return function (text, args) {
- // especially this part needs to be changed
- if(args != null) {
- if(args[0] != null) {
- text = text.replace("%0", args[0]);
- }
- if(args[1] != null) {
- text = text.replace("%1", args[1]);
- }
- if(args[2] != null) {
- text = text.replace("%2", args[2]);
- }
- }
- return text;
- /* return text.replace(/(\{%\d+\})/g, function ($1) {
- return args[$1.match(/\{%(\d+)\}/)[1]];
- }); */
- };
- })();
Advertisement
Add Comment
Please, Sign In to add comment