diff --git a/Gruntfile.js b/Gruntfile.js index bceb3edb8..a3c44bd88 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -174,8 +174,8 @@ module.exports = function(grunt) { messages: { src: [ 'nodes/core/locales/en-US/messages.json', - 'locales/en-US/editor.json', - 'locales/en-US/runtime.json' + 'red/api/locales/en-US/editor.json', + 'red/runtime/locales/en-US/runtime.json' ] } }, @@ -223,8 +223,8 @@ module.exports = function(grunt) { json: { files: [ 'nodes/core/locales/en-US/messages.json', - 'locales/en-US/editor.json', - 'locales/en-US/runtime.json' + 'red/api/locales/en-US/editor.json', + 'red/runtime/locales/en-US/runtime.json' ], tasks: ['jsonlint:messages'] } @@ -238,7 +238,7 @@ module.exports = function(grunt) { args: nodemonArgs, ext: 'js,html,json', watch: [ - 'red','nodes','locales' + 'red','nodes' ] } } @@ -302,8 +302,7 @@ module.exports = function(grunt) { 'red/**', 'public/**', 'editor/templates/**', - 'bin/**', - 'locales/**' + 'bin/**' ], dest: path.resolve('<%= paths.dist %>/node-red-<%= pkg.version %>') }] diff --git a/red/api/index.js b/red/api/index.js index dde167dc3..18f783dbe 100644 --- a/red/api/index.js +++ b/red/api/index.js @@ -34,6 +34,7 @@ var comms = require("./comms"); var auth = require("./auth"); var needsPermission = auth.needsPermission; +var i18n; var log; var adminApp; var nodeApp; @@ -50,6 +51,7 @@ var errorHandler = function(err,req,res,next) { function init(server,runtime) { var settings = runtime.settings; + i18n = runtime.i18n; log = runtime.log; if (settings.httpNodeRoot !== false) { nodeApp = express(); @@ -127,8 +129,9 @@ function init(server,runtime) { } } function start() { - comms.start(); - return when.resolve(); + return i18n.registerMessageCatalog("editor",path.resolve(path.join(__dirname,"locales")),"editor.json").then(function(){ + comms.start(); + }); } function stop() { comms.stop(); diff --git a/red/api/locales.js b/red/api/locales.js index 53520f221..05a5f0cc1 100644 --- a/red/api/locales.js +++ b/red/api/locales.js @@ -13,20 +13,52 @@ * See the License for the specific language governing permissions and * limitations under the License. **/ +var fs = require('fs'); +var path = require('path'); var i18n; +var supportedLangs = []; + +var apiLocalDir = path.resolve(path.join(__dirname,"locales")); + +var initSupportedLangs = function() { + fs.readdir(apiLocalDir, function(err,files) { + if(!err) { + supportedLangs = files; + } + }); +} + +function determineLangFromHeaders(acceptedLanguages){ + var lang = i18n.defaultLang; + acceptedLanguages = acceptedLanguages || []; + for (var i=0;i