Marcel Wolf Marcel Wolf - 4 months ago 11
Node.js Question

Add additional file to global path in nodeJS

I am new to NodeJS/ JavaScript and I want to add an additional File to my Global variable Declaration. My Idear:

I want do add a Language File to my Global Path

var getLanguage = require('./language.js');
module.exports = {
retryAssertionTimeout: 2000,
url:'https://10.99.8.81',
language: getLanguage.de_de,


In Language File I have Two Definitions, one for german and one for english.

So if I change

language: getLanguage.de_de,


to

language: getLanguage.en_en,


i want to change the used langugage.

the declaration in my language file looks like:

module.exports = {
de_de: {
verzeichnisse: "Verzeichnisse",
benachrichtigungen: "Benachrichtigungen",
berichte: "Berichte",
ftp_server: "FTP Server",
}
};


in my functions i call it with

var data = client.globals;
var language = data.language;
.goto(language.benutzer) //Benutzer is declared in my full file.


but this just not work.

Any idears?

Answer
[laguage.js]
var chinese = {
    game : "游戏"
}

var english = {
    game : "game"
}

function getLanguage(type) {
    if (type == 1) {
        return chinese;
    } else if (type == 2) {
        return english;
    }
}

exports.getLanguage = getLanguage;

[main.js]
var getLanguage = require('./language.js');
var language = getLanguage.getLanguage(1);
console.log(language);

[result]
{ game: '游戏'}
Comments