From 35c93eb59f338f827406d772a9ed034992f52466 Mon Sep 17 00:00:00 2001 From: Simon Ho Date: Wed, 27 Jul 2016 15:45:24 -0700 Subject: [PATCH] Add globalization --- .gitignore | 3 +++ example/hidden.js | 4 +++- example/simple.js | 4 +++- index.js | 8 +++++++- intl/en/messages.json | 5 +++++ package.json | 1 + 6 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 intl/en/messages.json diff --git a/.gitignore b/.gitignore index 5e487e2..0136051 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,6 @@ npm-debug.log node_modules LoopBackExplorer.iml + +intl/* +!intl/en/ diff --git a/example/hidden.js b/example/hidden.js index a0f4104..3ab579a 100644 --- a/example/hidden.js +++ b/example/hidden.js @@ -3,6 +3,8 @@ // This file is licensed under the MIT License. // License text available at https://opensource.org/licenses/MIT +var g = require('strong-globalize')(); + var loopback = require('loopback'); var app = loopback(); var explorer = require('../'); @@ -20,6 +22,6 @@ app.model(User); var apiPath = '/api'; explorer(app, { basePath: apiPath }); app.use(apiPath, loopback.rest()); -console.log('Explorer mounted at localhost:' + port + '/explorer'); +g.log('{{Explorer}} mounted at {{localhost:%s/explorer}}', port); app.listen(port); diff --git a/example/simple.js b/example/simple.js index c67ab44..ef39372 100644 --- a/example/simple.js +++ b/example/simple.js @@ -3,6 +3,8 @@ // This file is licensed under the MIT License. // License text available at https://opensource.org/licenses/MIT +var g = require('strong-globalize')(); + var loopback = require('loopback'); var app = loopback(); var explorer = require('../'); @@ -19,6 +21,6 @@ app.model(Product); var apiPath = '/api'; explorer(app, { basePath: apiPath }); app.use(apiPath, loopback.rest()); -console.log('Explorer mounted at http://localhost:' + port + '/explorer'); +g.log('{{Explorer}} mounted at {{http://localhost:%s/explorer}}', port); app.listen(port); diff --git a/index.js b/index.js index f9b71e1..dec2788 100644 --- a/index.js +++ b/index.js @@ -4,6 +4,11 @@ // License text available at https://opensource.org/licenses/MIT 'use strict'; + +var SG = require('strong-globalize'); +SG.SetRootDir(__dirname); +var g = SG(); + /*! * Adds dynamically-updated docs as /explorer */ @@ -38,7 +43,8 @@ function routes(loopbackApplication, options) { loopback.version.split('.')[0] || 1; if (loopbackMajor < 2) { - throw new Error('loopback-component-explorer requires loopback 2.0 or newer'); + throw new Error(g.f('{{loopback-component-explorer}} requires ' + + '{{loopback}} 2.0 or newer')); } options = _defaults({}, options, { diff --git a/intl/en/messages.json b/intl/en/messages.json new file mode 100644 index 0000000..3387cea --- /dev/null +++ b/intl/en/messages.json @@ -0,0 +1,5 @@ +{ + "b9e94c12da3208f46a969191874c425c": "{{Explorer}} mounted at {{localhost:{0}/explorer}}", + "88bef790f515ec7b7af0c6871e60c077": "{{Explorer}} mounted at {{http://localhost:{0}/explorer}}", + "f3f2b04c273e23780d76306f8c72a60f": "{{loopback-component-explorer}} requires {{loopback}} 2.0 or newer" +} diff --git a/package.json b/package.json index 63f3ea8..6e0464d 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,7 @@ "debug": "^2.2.0", "lodash": "^3.10.0", "loopback-swagger": "^2.1.0", + "strong-globalize": "^2.6.2", "strong-swagger-ui": "^21.0.0" } }