move i18n and locales to its own folder; abstract it a bit; detect at initialization; add cmd line option
This commit is contained in:
parent
51fab56fc5
commit
517a3bf234
|
@ -24,3 +24,4 @@ test_apps/contracts_app/chains.json
|
||||||
.embark/
|
.embark/
|
||||||
NOTES
|
NOTES
|
||||||
npm-debug.log
|
npm-debug.log
|
||||||
|
.tern-port
|
||||||
|
|
14
lib/cmd.js
14
lib/cmd.js
|
@ -2,18 +2,9 @@ const program = require('commander');
|
||||||
const promptly = require('promptly');
|
const promptly = require('promptly');
|
||||||
const utils = require('./utils/utils.js');
|
const utils = require('./utils/utils.js');
|
||||||
const Embark = require('../lib/index');
|
const Embark = require('../lib/index');
|
||||||
const i18n = require('i18n');
|
const i18n = require('./i18n/i18n.js');
|
||||||
let embark = new Embark;
|
let embark = new Embark;
|
||||||
|
|
||||||
i18n.configure({
|
|
||||||
locales: ['en', 'pt'],
|
|
||||||
register: global,
|
|
||||||
//updateFiles: false,
|
|
||||||
directory: utils.joinPath(__dirname, '/../locales')
|
|
||||||
});
|
|
||||||
|
|
||||||
i18n.setLocale('pt');
|
|
||||||
|
|
||||||
class Cmd {
|
class Cmd {
|
||||||
constructor() {
|
constructor() {
|
||||||
program.version(embark.version);
|
program.version(embark.version);
|
||||||
|
@ -118,8 +109,10 @@ class Cmd {
|
||||||
.option('--no-color', __('no colors in case it\'s needed for compatbility purposes'))
|
.option('--no-color', __('no colors in case it\'s needed for compatbility purposes'))
|
||||||
.option('--logfile [logfile]', __('filename to output logs (default: %s)', 'none'))
|
.option('--logfile [logfile]', __('filename to output logs (default: %s)', 'none'))
|
||||||
.option('--loglevel [loglevel]', __('level of logging to display') + ' ["error", "warn", "info", "debug", "trace"]', /^(error|warn|info|debug|trace)$/i, 'debug')
|
.option('--loglevel [loglevel]', __('level of logging to display') + ' ["error", "warn", "info", "debug", "trace"]', /^(error|warn|info|debug|trace)$/i, 'debug')
|
||||||
|
.option('--locale [locale]', __('language to use (default: en)'))
|
||||||
.description(__('run dapp (default: %s)', 'development'))
|
.description(__('run dapp (default: %s)', 'development'))
|
||||||
.action(function (env, options) {
|
.action(function (env, options) {
|
||||||
|
i18n.setOrDetectLocale(options.locale);
|
||||||
embark.run({
|
embark.run({
|
||||||
env: env || 'development',
|
env: env || 'development',
|
||||||
serverPort: options.port,
|
serverPort: options.port,
|
||||||
|
@ -251,7 +244,6 @@ class Cmd {
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
const i18n = require('i18n');
|
||||||
|
const osLocale = require('os-locale');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
const supported_languages = ['en', 'pt'];
|
||||||
|
|
||||||
|
i18n.configure({
|
||||||
|
locales: supported_languages,
|
||||||
|
register: global,
|
||||||
|
//updateFiles: false,
|
||||||
|
directory: path.join(__dirname, 'locales')
|
||||||
|
});
|
||||||
|
|
||||||
|
function isSupported(locale) {
|
||||||
|
return (supported_languages.indexOf(locale.substr(0, 2)) >= 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
function setLocale(locale) {
|
||||||
|
i18n.setLocale(locale.substr(0, 2));
|
||||||
|
}
|
||||||
|
|
||||||
|
function setDefaultLocale() {
|
||||||
|
osLocale().then(setLocale).catch();
|
||||||
|
}
|
||||||
|
|
||||||
|
function setOrDetectLocale(locale) {
|
||||||
|
if (locale && !isSupported(locale)) {
|
||||||
|
console.log("===== locale " + locale + " not supported =====");
|
||||||
|
}
|
||||||
|
if (locale) {
|
||||||
|
return i18n.setLocale(locale.substr(0, 2));
|
||||||
|
}
|
||||||
|
setDefaultLocale();
|
||||||
|
}
|
||||||
|
|
||||||
|
setDefaultLocale();
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
i18n: i18n,
|
||||||
|
setOrDetectLocale: setOrDetectLocale
|
||||||
|
};
|
||||||
|
|
|
@ -69,5 +69,11 @@
|
||||||
"instantiated web3.js object configured to the current environment": "instantiated web3.js object configured to the current environment",
|
"instantiated web3.js object configured to the current environment": "instantiated web3.js object configured to the current environment",
|
||||||
"to immediatly exit (alias: exit)": "to immediatly exit (alias: exit)",
|
"to immediatly exit (alias: exit)": "to immediatly exit (alias: exit)",
|
||||||
"The web3 object and the interfaces for the deployed contracts and their methods are also available": "The web3 object and the interfaces for the deployed contracts and their methods are also available",
|
"The web3 object and the interfaces for the deployed contracts and their methods are also available": "The web3 object and the interfaces for the deployed contracts and their methods are also available",
|
||||||
"versions in use": "versions in use"
|
"versions in use": "versions in use",
|
||||||
|
"language to use (default: en)": "language to use (default: en)",
|
||||||
|
"executing": "executing",
|
||||||
|
"writing file": "writing file",
|
||||||
|
"errors found while generating": "errors found while generating",
|
||||||
|
"Looking for documentation? You can find it at": "Looking for documentation? You can find it at",
|
||||||
|
"Ready": "Ready"
|
||||||
}
|
}
|
File diff suppressed because it is too large
Load Diff
|
@ -51,6 +51,7 @@
|
||||||
"live-plugin-manager": "https://github.com/iurimatias/live-plugin-manager.git",
|
"live-plugin-manager": "https://github.com/iurimatias/live-plugin-manager.git",
|
||||||
"merge": "^1.2.0",
|
"merge": "^1.2.0",
|
||||||
"orbit-db": "^0.17.3",
|
"orbit-db": "^0.17.3",
|
||||||
|
"os-locale": "^2.1.0",
|
||||||
"parse-json": "^4.0.0",
|
"parse-json": "^4.0.0",
|
||||||
"promptly": "^2.1.0",
|
"promptly": "^2.1.0",
|
||||||
"propose": "0.0.5",
|
"propose": "0.0.5",
|
||||||
|
|
Loading…
Reference in New Issue