Globalize strings to end user
This commit is contained in:
parent
96d5c4f64e
commit
6d142c9596
|
@ -16,3 +16,5 @@ generated-instructions*.json
|
||||||
checkstyle.xml
|
checkstyle.xml
|
||||||
loopback-boot-*.tgz
|
loopback-boot-*.tgz
|
||||||
/test/sandbox/
|
/test/sandbox/
|
||||||
|
intl/*
|
||||||
|
!intl/en/*
|
2
index.js
2
index.js
|
@ -6,6 +6,8 @@
|
||||||
var PluginBase = require('./lib/plugin-base');
|
var PluginBase = require('./lib/plugin-base');
|
||||||
var Bootstrapper = require('./lib/bootstrapper').Bootstrapper;
|
var Bootstrapper = require('./lib/bootstrapper').Bootstrapper;
|
||||||
var addInstructionsToBrowserify = require('./lib/bundler');
|
var addInstructionsToBrowserify = require('./lib/bundler');
|
||||||
|
var SG = require('strong-globalize');
|
||||||
|
SG.SetRootDir(__dirname);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize an application from an options object or
|
* Initialize an application from an options object or
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
{
|
||||||
|
"ae47060728bbbccb3b6279bfce9895e8": "Discarding middleware instructions, loopback client does not support middleware.",
|
||||||
|
"69746d336c89bf4bb371a6c2fe56304d": "{0} does not resolve to a valid value, returned as {1}. \"{2}\" must be resolvable in Environment variable or by app.get().",
|
||||||
|
"cdbbcf09fd7f613f3a3e4eacba0e614f": "WARNING: Main config file \"{0}.json\" is missing",
|
||||||
|
"3a7049e42006e8bc19e0f4fc8df63b6b": "The `app` is powered by an incompatible loopback version {0}. Supported versions: {1}",
|
||||||
|
"70654dc6eb565613a33344efed3de998": "Failed loading boot script: {0}\n{1}",
|
||||||
|
"0c8892b57ac28e5bdeb28f6d4eeace0f": "Middleware must be an array",
|
||||||
|
"33e14d1e42c43970490614c1fa38dbd3": "Middleware phases must be an array",
|
||||||
|
"35c9468dd1fc15ae5ee90a4801467772": "The phase \"{0}\" is not defined in the main config.",
|
||||||
|
"75f38e979d1caf27338aba1122e42884": "Middleware factory must be a function",
|
||||||
|
"e422b92bace89e40433df300053440c1": "The middleware \"{0}\" in phase \"{1}\"is not defined in the main config.",
|
||||||
|
"fdc23df1bd0fe55fe3faabcc89ff60f3": "Middleware \"{0}\" not found: {1}",
|
||||||
|
"34319676975b1abf107da7a056abb434": "Invalid normalization format - \"{0}\"",
|
||||||
|
"4d052d84c8620730afd4a30832f11724": "Cannot configure unknown model {0}",
|
||||||
|
"5b0d7d21c4b507336a96242c7f29b788": "The data in model-config.json is in the unsupported 1.x format.",
|
||||||
|
"6037512314fac9d12af6c654a3804823": "Built-in model {0} should have been defined",
|
||||||
|
"1e5fea50eef843cbffd1d438494912c8": "Cannot resolve path \"{0}\"",
|
||||||
|
"6447e6b342a2c51ab0bc53b3cbdf3742": "Ordering conflict: cannot add \"{0}\" after \"{1}\", because the opposite order was already specified",
|
||||||
|
"978a25819e71602cad691dbe7ba17592": "{0} config must be a valid JSON object",
|
||||||
|
"be2dcdab7aa493ed8d77287eb45cfec8": "cannot require directory contents without directory name"
|
||||||
|
}
|
|
@ -7,6 +7,7 @@ var fs = require('fs');
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
var commondir = require('commondir');
|
var commondir = require('commondir');
|
||||||
var cloneDeep = require('lodash').cloneDeep;
|
var cloneDeep = require('lodash').cloneDeep;
|
||||||
|
var g = require('strong-globalize')();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add boot instructions to a browserify bundler.
|
* Add boot instructions to a browserify bundler.
|
||||||
|
@ -99,7 +100,7 @@ function bundleInstructions(context, bundler) {
|
||||||
var hasMiddleware = instructions.middleware.phases.length ||
|
var hasMiddleware = instructions.middleware.phases.length ||
|
||||||
instructions.middleware.middleware.length;
|
instructions.middleware.middleware.length;
|
||||||
if (hasMiddleware) {
|
if (hasMiddleware) {
|
||||||
console.warn(
|
g.warn(
|
||||||
'Discarding middleware instructions,' +
|
'Discarding middleware instructions,' +
|
||||||
' loopback client does not support middleware.');
|
' loopback client does not support middleware.');
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ var path = require('path');
|
||||||
var debug = require('debug')('loopback:boot:plugin');
|
var debug = require('debug')('loopback:boot:plugin');
|
||||||
var assert = require('assert');
|
var assert = require('assert');
|
||||||
var _ = require('lodash');
|
var _ = require('lodash');
|
||||||
|
var g = require('strong-globalize')();
|
||||||
|
|
||||||
module.exports = PluginBase;
|
module.exports = PluginBase;
|
||||||
|
|
||||||
|
@ -89,7 +90,7 @@ PluginBase.prototype.findConfigFiles = function(rootDir, env, name, exts) {
|
||||||
var master = ifExists(name + '.json');
|
var master = ifExists(name + '.json');
|
||||||
if (!master && (ifExistsWithAnyExt(name + '.local') ||
|
if (!master && (ifExistsWithAnyExt(name + '.local') ||
|
||||||
ifExistsWithAnyExt(name + '.' + env))) {
|
ifExistsWithAnyExt(name + '.' + env))) {
|
||||||
console.warn('WARNING: Main config file "' + name + '.json" is missing');
|
g.warn('WARNING: Main config file "%s.json" is missing', name);
|
||||||
}
|
}
|
||||||
if (!master) return [];
|
if (!master) return [];
|
||||||
|
|
||||||
|
@ -280,7 +281,7 @@ function getConfigVariable(app, param, useEnvVars) {
|
||||||
// it will now return `undefined`, for the use case of
|
// it will now return `undefined`, for the use case of
|
||||||
// dynamic datasources url:`undefined` to fallback to other parameters
|
// dynamic datasources url:`undefined` to fallback to other parameters
|
||||||
configVariable = undefined;
|
configVariable = undefined;
|
||||||
console.warn('%s does not resolve to a valid value, returned as %s. ' +
|
g.warn('%s does not resolve to a valid value, returned as %s. ' +
|
||||||
'"%s" must be resolvable in Environment variable or by app.get().',
|
'"%s" must be resolvable in Environment variable or by app.get().',
|
||||||
param, configVariable, varName);
|
param, configVariable, varName);
|
||||||
debug('Dynamic Configuration: Cannot resolve variable for `%s`, ' +
|
debug('Dynamic Configuration: Cannot resolve variable for `%s`, ' +
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
var util = require('util');
|
var util = require('util');
|
||||||
var assert = require('assert');
|
var assert = require('assert');
|
||||||
var semver = require('semver');
|
var semver = require('semver');
|
||||||
|
var g = require('strong-globalize')();
|
||||||
var format = require('util').format;
|
var format = require('util').format;
|
||||||
var PluginBase = require('../plugin-base');
|
var PluginBase = require('../plugin-base');
|
||||||
|
|
||||||
|
@ -28,7 +29,7 @@ function assertLoopBackVersion(app) {
|
||||||
// while loopback-boot treats pre-releases the same way as regular versions
|
// while loopback-boot treats pre-releases the same way as regular versions
|
||||||
var version = (loopback.version || '1.0.0').replace(/-.*$/, '');
|
var version = (loopback.version || '1.0.0').replace(/-.*$/, '');
|
||||||
if (!semver.satisfies(version, RANGE)) {
|
if (!semver.satisfies(version, RANGE)) {
|
||||||
var msg = format(
|
var msg = g.f(
|
||||||
'The `app` is powered by an incompatible loopback version %s. ' +
|
'The `app` is powered by an incompatible loopback version %s. ' +
|
||||||
'Supported versions: %s',
|
'Supported versions: %s',
|
||||||
loopback.version || '(unknown)',
|
loopback.version || '(unknown)',
|
||||||
|
|
|
@ -10,6 +10,7 @@ var async = require('async');
|
||||||
var debug = require('debug')('loopback:boot:script');
|
var debug = require('debug')('loopback:boot:script');
|
||||||
var PluginBase = require('../plugin-base');
|
var PluginBase = require('../plugin-base');
|
||||||
var _ = require('lodash');
|
var _ = require('lodash');
|
||||||
|
var g = require('strong-globalize')();
|
||||||
|
|
||||||
module.exports = function(options) {
|
module.exports = function(options) {
|
||||||
return new Script(options);
|
return new Script(options);
|
||||||
|
@ -67,7 +68,7 @@ function runScripts(app, list, callback) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Failed loading boot script: %s\n%s', filepath, err.stack);
|
g.error('Failed loading boot script: %s\n%s', filepath, err.stack);
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -10,6 +10,7 @@ var _ = require('lodash');
|
||||||
var cloneDeepWith = _.cloneDeepWith;
|
var cloneDeepWith = _.cloneDeepWith;
|
||||||
var cloneDeep = _.cloneDeep;
|
var cloneDeep = _.cloneDeep;
|
||||||
var debug = require('debug')('loopback:boot:middleware');
|
var debug = require('debug')('loopback:boot:middleware');
|
||||||
|
var g = require('strong-globalize')();
|
||||||
var PluginBase = require('../plugin-base');
|
var PluginBase = require('../plugin-base');
|
||||||
var utils = require('../utils');
|
var utils = require('../utils');
|
||||||
|
|
||||||
|
@ -31,10 +32,10 @@ Middleware.prototype.merge = function(target, config, fileName) {
|
||||||
if (phase in target) {
|
if (phase in target) {
|
||||||
err = this.mergePhaseConfig(target[phase], config[phase], phase);
|
err = this.mergePhaseConfig(target[phase], config[phase], phase);
|
||||||
} else {
|
} else {
|
||||||
err = 'The phase "' + phase + '" is not defined in the main config.';
|
err = g.f('The phase "%s" is not defined in the main config.', phase);
|
||||||
}
|
}
|
||||||
if (err)
|
if (err)
|
||||||
throw new Error('Cannot apply ' + fileName + ': ' + err);
|
throw new Error(g.ft('Cannot apply %s: %s', fileName, err));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -68,8 +69,8 @@ Middleware.prototype.mergePhaseConfig = function(target, config, phase) {
|
||||||
err = this.mergeObjects(targetMiddleware, configMiddleware);
|
err = this.mergeObjects(targetMiddleware, configMiddleware);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
err = 'The middleware "' + mw + '" in phase "' + phase + '"' +
|
err = g.f('The middleware "%s" in phase "%s"' +
|
||||||
'is not defined in the main config.';
|
'is not defined in the main config.', mw, phase);
|
||||||
}
|
}
|
||||||
if (err) return err;
|
if (err) return err;
|
||||||
}
|
}
|
||||||
|
@ -93,7 +94,7 @@ Middleware.prototype.buildInstructions = function(context, rootDir, config) {
|
||||||
// if a non-optional middleware is not resolvable, it will throw
|
// if a non-optional middleware is not resolvable, it will throw
|
||||||
// at resolveAppPath() and not reach here
|
// at resolveAppPath() and not reach here
|
||||||
if (!resolved.sourceFile) {
|
if (!resolved.sourceFile) {
|
||||||
return console.log('Middleware "%s" not found: %s',
|
return g.log('Middleware "%s" not found: %s',
|
||||||
middleware,
|
middleware,
|
||||||
resolved.optional
|
resolved.optional
|
||||||
);
|
);
|
||||||
|
@ -234,11 +235,11 @@ Middleware.prototype.start = function(context) {
|
||||||
// Phases can be empty
|
// Phases can be empty
|
||||||
var phases = instructions.phases || [];
|
var phases = instructions.phases || [];
|
||||||
assert(Array.isArray(phases),
|
assert(Array.isArray(phases),
|
||||||
'Middleware phases must be an array');
|
g.f('Middleware phases must be an array'));
|
||||||
|
|
||||||
var middleware = instructions.middleware;
|
var middleware = instructions.middleware;
|
||||||
assert(Array.isArray(middleware),
|
assert(Array.isArray(middleware),
|
||||||
'Middleware must be an array');
|
g.f('Middleware must be an array'));
|
||||||
|
|
||||||
debug('Defining middleware phases %j', phases);
|
debug('Defining middleware phases %j', phases);
|
||||||
app.defineMiddlewarePhases(phases);
|
app.defineMiddlewarePhases(phases);
|
||||||
|
@ -251,7 +252,7 @@ Middleware.prototype.start = function(context) {
|
||||||
factory = factory[data.fragment].bind(factory);
|
factory = factory[data.fragment].bind(factory);
|
||||||
}
|
}
|
||||||
assert(typeof factory === 'function',
|
assert(typeof factory === 'function',
|
||||||
'Middleware factory must be a function');
|
g.f('Middleware factory must be a function'));
|
||||||
data.config = self.getUpdatedConfigObject(context, data.config,
|
data.config = self.getUpdatedConfigObject(context, data.config,
|
||||||
{ useEnvVars: true });
|
{ useEnvVars: true });
|
||||||
app.middlewareFromConfig(factory, data.config);
|
app.middlewareFromConfig(factory, data.config);
|
||||||
|
|
|
@ -9,6 +9,7 @@ var path = require('path');
|
||||||
var PluginBase = require('../plugin-base');
|
var PluginBase = require('../plugin-base');
|
||||||
var _ = require('lodash');
|
var _ = require('lodash');
|
||||||
var debug = require('debug')('loopback:boot:mixin');
|
var debug = require('debug')('loopback:boot:mixin');
|
||||||
|
var g = require('strong-globalize')();
|
||||||
var utils = require('../utils');
|
var utils = require('../utils');
|
||||||
|
|
||||||
var tryResolveAppPath = utils.tryResolveAppPath;
|
var tryResolveAppPath = utils.tryResolveAppPath;
|
||||||
|
@ -162,8 +163,8 @@ function normalizeMixinName(str, options) {
|
||||||
return normalization(str);
|
return normalization(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
var err = new Error('Invalid normalization format - "' +
|
var err = new Error(g.f('Invalid normalization format - "%s"',
|
||||||
normalization + '"');
|
normalization));
|
||||||
err.code = 'INVALID_NORMALIZATION_FORMAT';
|
err.code = 'INVALID_NORMALIZATION_FORMAT';
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ var util = require('util');
|
||||||
var PluginBase = require('../plugin-base');
|
var PluginBase = require('../plugin-base');
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
var debug = require('debug')('loopback:boot:model');
|
var debug = require('debug')('loopback:boot:model');
|
||||||
|
var g = require('strong-globalize')();
|
||||||
var _ = require('lodash');
|
var _ = require('lodash');
|
||||||
var toposort = require('toposort');
|
var toposort = require('toposort');
|
||||||
var utils = require('../utils');
|
var utils = require('../utils');
|
||||||
|
@ -235,7 +236,7 @@ function assertIsValidModelConfig(config) {
|
||||||
|
|
||||||
if (unsupported) {
|
if (unsupported) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
'The data in model-config.json is in the unsupported 1.x format.');
|
g.f('The data in model-config.json is in the unsupported 1.x format.'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -267,12 +268,12 @@ Model.prototype.start = function(context) {
|
||||||
if (!data.definition) {
|
if (!data.definition) {
|
||||||
model = registry.getModel(name);
|
model = registry.getModel(name);
|
||||||
if (!model) {
|
if (!model) {
|
||||||
throw new Error('Cannot configure unknown model ' + name);
|
throw new Error(g.f('Cannot configure unknown model %s', name));
|
||||||
}
|
}
|
||||||
debug('Configuring existing model %s', name);
|
debug('Configuring existing model %s', name);
|
||||||
} else if (isBuiltinLoopBackModel(app, data)) {
|
} else if (isBuiltinLoopBackModel(app, data)) {
|
||||||
model = registry.getModel(name);
|
model = registry.getModel(name);
|
||||||
assert(model, 'Built-in model ' + name + ' should have been defined');
|
assert(model, g.f('Built-in model %s should have been defined', name));
|
||||||
debug('Configuring built-in LoopBack model %s', name);
|
debug('Configuring built-in LoopBack model %s', name);
|
||||||
} else {
|
} else {
|
||||||
debug('Creating new model %s %j', name, data.definition);
|
debug('Creating new model %s %j', name, data.definition);
|
||||||
|
|
13
lib/utils.js
13
lib/utils.js
|
@ -7,6 +7,7 @@ var debug = require('debug')('loopback:boot');
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
var Module = require('module');
|
var Module = require('module');
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
|
var g = require('strong-globalize')();
|
||||||
var assert = require('assert');
|
var assert = require('assert');
|
||||||
var _ = require('lodash');
|
var _ = require('lodash');
|
||||||
|
|
||||||
|
@ -30,7 +31,7 @@ var FILE_EXTENSION_JSON = exports.FILE_EXTENSION_JSON = '.json';
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function findScripts(dir, extensions) {
|
function findScripts(dir, extensions) {
|
||||||
assert(dir, 'cannot require directory contents without directory name');
|
assert(dir, g.t('cannot require directory contents without directory name'));
|
||||||
|
|
||||||
var files = tryReadDir(dir);
|
var files = tryReadDir(dir);
|
||||||
extensions = extensions || _.keys(require.extensions);
|
extensions = extensions || _.keys(require.extensions);
|
||||||
|
@ -141,7 +142,7 @@ function fixFileExtension(filepath, files, onlyScriptsExportingFunction) {
|
||||||
function resolveAppPath(rootDir, relativePath, resolveOptions) {
|
function resolveAppPath(rootDir, relativePath, resolveOptions) {
|
||||||
var resolvedPath = tryResolveAppPath(rootDir, relativePath, resolveOptions);
|
var resolvedPath = tryResolveAppPath(rootDir, relativePath, resolveOptions);
|
||||||
if (resolvedPath === undefined && !resolveOptions.optional) {
|
if (resolvedPath === undefined && !resolveOptions.optional) {
|
||||||
var err = new Error('Cannot resolve path "' + relativePath + '"');
|
var err = new Error(g.f('Cannot resolve path "%s"', relativePath));
|
||||||
err.code = 'PATH_NOT_FOUND';
|
err.code = 'PATH_NOT_FOUND';
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
|
@ -241,7 +242,7 @@ function tryResolveAppPath(rootDir, relativePath, resolveOptions) {
|
||||||
function assertIsValidConfig(name, config) {
|
function assertIsValidConfig(name, config) {
|
||||||
if (config) {
|
if (config) {
|
||||||
assert(typeof config === 'object',
|
assert(typeof config === 'object',
|
||||||
name + ' config must be a valid JSON object');
|
g.f('%s config must be a valid JSON object', name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -313,9 +314,9 @@ function mergePhaseNameLists(currentNames, namesToMerge) {
|
||||||
// A new phase - try to add it after the last one,
|
// A new phase - try to add it after the last one,
|
||||||
// unless it was already registered
|
// unless it was already registered
|
||||||
if (targetArray.indexOf(valueToAdd) !== -1) {
|
if (targetArray.indexOf(valueToAdd) !== -1) {
|
||||||
throw new Error('Ordering conflict: cannot add "' + valueToAdd +
|
throw new Error(g.f('Ordering conflict: cannot add "%s" after "%s",' +
|
||||||
'" after "' + previousValue + '", because the opposite order was ' +
|
' because the opposite order was already specified',
|
||||||
' already specified');
|
valueToAdd, previousValue));
|
||||||
}
|
}
|
||||||
var previousIx = targetArray.indexOf(previousValue);
|
var previousIx = targetArray.indexOf(previousValue);
|
||||||
targetArray.splice(previousIx + 1, 0, valueToAdd);
|
targetArray.splice(previousIx + 1, 0, valueToAdd);
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
"debug": "^2.2.0",
|
"debug": "^2.2.0",
|
||||||
"lodash": "^4.13.1",
|
"lodash": "^4.13.1",
|
||||||
"semver": "^5.1.0",
|
"semver": "^5.1.0",
|
||||||
|
"strong-globalize": "^2.5.5",
|
||||||
"toposort": "^1.0.0"
|
"toposort": "^1.0.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|
Loading…
Reference in New Issue