How to use the @node-red/util.i18n.defaultLang function in @node-red/util

To help you get started, we’ve selected a few @node-red/util examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github node-red / node-red / packages / node_modules / @node-red / registry / lib / loader.js View on Github external
types.push(match[1]);
                }
                node.types = types;

                var langRegExp = /^]* data-lang\s*=\s*['"](.+?)['"]/i;
                regExp = /(]* data-help-name=[\s\S]*?<\/script>)/gi;
                match = null;
                var mainContent = "";
                var helpContent = {};
                var index = 0;
                while ((match = regExp.exec(content)) !== null) {
                    mainContent += content.substring(index,regExp.lastIndex-match[1].length);
                    index = regExp.lastIndex;
                    var help = content.substring(regExp.lastIndex-match[1].length,regExp.lastIndex);

                    var lang = i18n.defaultLang;
                    if ((match = langRegExp.exec(help)) !== null) {
                        lang = match[1];
                    }
                    if (!helpContent.hasOwnProperty(lang)) {
                        helpContent[lang] = "";
                    }

                    helpContent[lang] += help;
                }
                mainContent += content.substring(index);

                node.config = mainContent;
                node.help = helpContent;
                // TODO: parse out the javascript portion of the template
                //node.script = "";
                for (var i=0;i
github node-red / node-red / packages / node_modules / @node-red / editor-api / lib / editor / locales.js View on Github external
get: function(req,res) {
        var namespace = req.params[0];
        var lngs = req.query.lng;
        namespace = namespace.replace(/\.json$/,"");
        var lang = req.query.lng || i18n.defaultLang; //apiUtil.determineLangFromHeaders(req.acceptsLanguages() || []);
        var prevLang = i18n.i.language;
        // Trigger a load from disk of the language if it is not the default
        i18n.i.changeLanguage(lang, function(){
            var catalog = loadResource(lang, namespace);
            res.json(catalog||{});
        });
        i18n.i.changeLanguage(prevLang);
    }
}
github node-red / node-red / packages / node_modules / @node-red / registry / lib / loader.js View on Github external
function getNodeHelp(node,lang) {
    if (!node.help[lang]) {
        var help = loadNodeHelp(node,lang);
        if (help == null) {
            var langParts = lang.split("-");
            if (langParts.length == 2) {
                help = loadNodeHelp(node,langParts[0]);
            }
        }
        if (help) {
            node.help[lang] = help;
        } else if (lang === i18n.defaultLang) {
            return null;
        } else {
            node.help[lang] = getNodeHelp(node, i18n.defaultLang);
        }
    }
    return node.help[lang];
}
github node-red / node-red / packages / node_modules / @node-red / registry / lib / loader.js View on Github external
function getNodeHelp(node,lang) {
    if (!node.help[lang]) {
        var help = loadNodeHelp(node,lang);
        if (help == null) {
            var langParts = lang.split("-");
            if (langParts.length == 2) {
                help = loadNodeHelp(node,langParts[0]);
            }
        }
        if (help) {
            node.help[lang] = help;
        } else if (lang === i18n.defaultLang) {
            return null;
        } else {
            node.help[lang] = getNodeHelp(node, i18n.defaultLang);
        }
    }
    return node.help[lang];
}
github node-red / node-red / packages / node_modules / @node-red / editor-api / lib / util.js View on Github external
determineLangFromHeaders: function(acceptedLanguages){
        var lang = i18n.defaultLang;
        acceptedLanguages = acceptedLanguages || [];
        if (acceptedLanguages.length >= 1) {
            lang = acceptedLanguages[0];
        }
        return lang;
    },
    rejectHandler: function(req,res,err) {