How to use the @node-red/util.i18n 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 / editor-api / lib / editor / locales.js View on Github external
* you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 **/
var fs = require('fs');
var path = require('path');
// var apiUtil = require('../util');

var i18n = require("@node-red/util").i18n; // TODO: separate module

var runtimeAPI;

function loadResource(lang, namespace) {
    var catalog = i18n.i.getResourceBundle(lang, namespace);
    if (!catalog) {
        var parts = lang.split("-");
        if (parts.length == 2) {
            var new_lang = parts[0];
            return i18n.i.getResourceBundle(new_lang, namespace);
        }
    }
    return catalog;
}

module.exports = {
github node-red / node-red / packages / node_modules / @node-red / registry / lib / loader.js View on Github external
* Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 **/

var when = require("when");
var fs = require("fs");
var path = require("path");
var semver = require("semver");

var localfilesystem = require("./localfilesystem");
var registry = require("./registry");
var registryUtil = require("./util")
var i18n = require("@node-red/util").i18n;

var settings;
var runtime;

function init(_runtime) {
    runtime = _runtime;
    settings = runtime.settings;
    localfilesystem.init(runtime);
    registryUtil.init(runtime);
}

function load(disableNodePathScan) {
    // To skip node scan, the following line will use the stored node list.
    // We should expose that as an option at some point, although the
    // performance gains are minimal.
    //return loadNodeFiles(registry.getModuleList());
github node-red / node-red / packages / node_modules / @node-red / editor-api / lib / util.js View on Github external
* Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 **/


var log = require("@node-red/util").log; // TODO: separate module
var i18n = require("@node-red/util").i18n; // TODO: separate module


module.exports = {
    errorHandler: function(err,req,res,next) {
        //TODO: why this when rejectHandler also?!

        if (err.message === "request entity too large") {
            log.error(err);
        } else {
            log.error(err.stack);
        }
        log.audit({event: "api.error",error:err.code||"unexpected_error",message:err.toString()},req);
        res.status(400).json({error:"unexpected_error", message:err.toString()});
    },

    determineLangFromHeaders: function(acceptedLanguages){
github node-red / node-red / packages / node_modules / @node-red / editor-api / lib / editor / settings.js View on Github external
*
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 **/
var apiUtils = require("../util");
var runtimeAPI;
var sshkeys = require("./sshkeys");
var theme = require("./theme");
var clone = require("clone");

var i18n = require("@node-red/util").i18n

function extend(target, source) {
    var keys = Object.keys(source);
    var i = keys.length;
    while(i--) {
        var value = source[keys[i]]
        var type = typeof value;
        if (type === 'string' || type === 'number' || type === 'boolean' || Array.isArray(value)) {
            target[keys[i]] = value;
        } else if (value === null) {
            if (target.hasOwnProperty(keys[i])) {
                delete target[keys[i]];
            }
        } else {
            // Object
            if (target.hasOwnProperty(keys[i])) {
github node-red / node-red / packages / node_modules / @node-red / editor-api / lib / editor / index.js View on Github external
* limitations under the License.
 **/

var express = require("express");
var path = require('path');

var comms = require("./comms");
var library = require("./library");
var info = require("./settings");

var auth = require("../auth");
var nodes = require("../admin/nodes"); // TODO: move /icons into here
var needsPermission;
var runtimeAPI;
var log = require("@node-red/util").log; // TODO: separate module
var i18n = require("@node-red/util").i18n; // TODO: separate module

var apiUtil = require("../util");

var ensureRuntimeStarted = function(req,res,next) {
    runtimeAPI.isStarted().then( started => {
        if (!started) {
            log.error("Node-RED runtime not started");
            res.status(503).send("Not started");
        } else {
            next()
        }
    })
}

module.exports = {
    init: function(server, settings, _runtimeAPI) {
github node-red / node-red / packages / node_modules / @node-red / registry / lib / localfilesystem.js View on Github external
*
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 **/

var fs = require("fs");
var path = require("path");

var events;
var log;

var log = require("@node-red/util").log;
var i18n = require("@node-red/util").i18n;

var settings;
var disableNodePathScan = false;
var iconFileExtensions = [".png", ".gif", ".svg"];

function init(runtime) {
    settings = runtime.settings;
    events = runtime.events;
}

function isIncluded(name) {
    if (settings.nodesIncludes) {
        for (var i=0;i
github node-red / node-red / packages / node_modules / @node-red / runtime / lib / index.js View on Github external
nodeApp = express();
    adminApp = express();

    if (_adminApi) {
        adminApi = _adminApi;
    }
    redNodes.init(runtime);
    library.init(runtime);
    externalAPI.init(runtime);
    exec.init(runtime);
    if (__util) {
        log = __util.log;
        i18n = __util.i18n;
    } else {
        log = redUtil.log;
        i18n = redUtil.i18n;
    }
}
github node-red / node-red / packages / node_modules / @node-red / runtime / lib / storage / localfilesystem / projects / defaultFileSet.js View on Github external
* Copyright JS Foundation and other contributors, http://js.foundation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 **/

var i18n = require("@node-red/util").i18n;

module.exports = {
    "package.json": function(project) {
        var package = {
            "name": project.name,
            "description": project.summary||i18n._("storage.localfilesystem.projects.summary"),
            "version": "0.0.1",
            "dependencies": {},
            "node-red": {
                "settings": {
                }
            }
        };
        if (project.files) {
            if (project.files.flow) {
                package['node-red'].settings.flowFile = project.files.flow;
github node-red / node-red / packages / node_modules / @node-red / registry / lib / util.js View on Github external
*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 **/

var path = require("path");
var i18n = require("@node-red/util").i18n;
var registry;
var runtime;

function copyObjectProperties(src,dst,copyList,blockList) {
    if (!src) {
        return;
    }
    if (copyList && !blockList) {
        copyList.forEach(function(i) {
            if (src.hasOwnProperty(i)) {
                var propDescriptor = Object.getOwnPropertyDescriptor(src,i);
                Object.defineProperty(dst,i,propDescriptor);
            }
        });
    } else if (!copyList && blockList) {
        for (var i in src) {
github node-red / node-red / packages / node_modules / @node-red / runtime / lib / index.js View on Github external
var redNodes = require("./nodes");
var storage = require("./storage");
var library = require("./library");
var events = require("./events");
var settings = require("./settings");
var exec = require("./exec");

var express = require("express");
var path = require('path');
var fs = require("fs");
var os = require("os");

var redUtil = require("@node-red/util");
var log = redUtil.log;
var i18n = redUtil.i18n;

var runtimeMetricInterval = null;

var started = false;

var stubbedExpressApp = {
    get: function() {},
    post: function() {},
    put: function() {},
    delete: function() {}
}
var adminApi = {
    auth: {
        needsPermission: function() {return function(req,res,next) {next()}}
    },
    adminApp: stubbedExpressApp,