From 728d9e2096cfc0e98b9cdaec11a3d4c6e393b567 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Fri, 29 May 2015 10:44:10 +0200 Subject: [PATCH] Add i18n review16321002 --- Gruntfile.js | 67 +++++++++++++++++++------ bower.json | 3 +- index.html | 45 +---------------- package.json | 4 +- src/action.js | 9 ++-- src/common.js | 104 +++++++++++++++++++++------------------ src/rpc.js | 3 +- src/sao.js | 28 +++++++++-- src/screen.js | 45 ++++++++++------- src/session.js | 130 +++++++++++++++++++++++++++++++++++++------------ src/tab.js | 125 ++++++++++++++++++++++++++++------------------- src/view.js | 33 +++++++------ src/window.js | 45 ++++++++--------- src/wizard.js | 2 +- 14 files changed, 385 insertions(+), 258 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index dcad7d3dfc..71896d84a4 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1,24 +1,59 @@ module.exports = function(grunt) { + var _ = grunt.util._; + var locales = ["bg_BG", "ca_ES", "cs_CZ", "de_DE", "es_AR", "es_CO", "es_EC", + "es_ES", "fr_FR", "ja_JP", "lt_LT", "nl_NL", "ru_RU", "sl_SI"]; + var jsfiles = [ + 'src/sao.js', + 'src/rpc.js', + 'src/pyson.js', + 'src/session.js', + 'src/model.js', + 'src/tab.js', + 'src/screen.js', + 'src/view.js', + 'src/action.js', + 'src/common.js', + 'src/window.js', + 'src/wizard.js' + ]; + // Project configuration. grunt.initConfig({ pkg: grunt.file.readJSON('package.json'), + xgettext: { + locale: { + files: { + javascript: jsfiles + }, + options: { + functionName: "Sao.i18n.gettext", + potFile: "locale/messages.pot" + }, + } + }, + shell: { + options: { + failOnError: true + }, + msgmerge: { + command: _.map(locales, function(locale) { + var po = "locale/" + locale + ".po"; + return "msgmerge -U " + po + " locale/messages.pot;"; + }).join("") + }, + po2json: { + command: _.map(locales, function(locale) { + var po = "locale/" + locale + ".po"; + var json = "locale/" + locale + ".json"; + return "./node_modules/.bin/po2json-gettextjs " + + po + " " + json + ";"; + }).join("") + } + }, concat: { dist: { - src: [ - 'src/sao.js', - 'src/rpc.js', - 'src/pyson.js', - 'src/session.js', - 'src/model.js', - 'src/tab.js', - 'src/screen.js', - 'src/view.js', - 'src/action.js', - 'src/common.js', - 'src/window.js', - 'src/wizard.js' - ], + src: jsfiles, dest: 'dist/<%= pkg.name %>.js' } }, @@ -85,6 +120,8 @@ module.exports = function(grunt) { // Load the plugin that provides the "uglify" task. grunt.loadNpmTasks('grunt-contrib-concat'); + grunt.loadNpmTasks('grunt-xgettext'); + grunt.loadNpmTasks('grunt-shell'); grunt.loadNpmTasks('grunt-contrib-jshint'); grunt.loadNpmTasks('grunt-contrib-uglify'); grunt.loadNpmTasks('grunt-contrib-less'); @@ -93,5 +130,7 @@ module.exports = function(grunt) { // Default task(s). grunt.registerTask('default', ['concat', 'jshint', 'uglify', 'less:default']); grunt.registerTask('dev', ['concat', 'jshint', 'less:dev']); + grunt.registerTask('msgmerge', ['shell:msgmerge']); + grunt.registerTask('po2json', ['shell:po2json']); }; diff --git a/bower.json b/bower.json index aa29e0d112..419b124bd2 100644 --- a/bower.json +++ b/bower.json @@ -20,7 +20,8 @@ "moment": "~2.10.2", "eonasdan-bootstrap-datetimepicker": "~4.7.14", "typeahead.js": "~0.10.5", - "typeahead.js-bootstrap3.less": "~0" + "typeahead.js-bootstrap3.less": "~0", + "gettext.js": "~0.5.0" }, "devDependencies": { "qunit": "~1.18.0" diff --git a/index.html b/index.html index 03c8da8f9b..3158747424 100644 --- a/index.html +++ b/index.html @@ -11,6 +11,7 @@ this repository contains the full copyright notices and license terms. --> + @@ -76,49 +77,5 @@ this repository contains the full copyright notices and license terms. --> Sao.login(); }); - - diff --git a/package.json b/package.json index e32e34ca6e..28978228af 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,9 @@ "grunt-contrib-less": "^1.0.1", "grunt-contrib-nodeunit": "~0.4.1", "grunt-contrib-uglify": "^0.9.1", - "grunt-contrib-watch": "~0.6.1" + "grunt-contrib-watch": "~0.6.1", + "grunt-shell": "^1.1.2", + "grunt-xgettext": "^0.3.5" }, "keywords": [ "tryton" diff --git a/src/action.js b/src/action.js index b47595e31c..5241e9aabe 100644 --- a/src/action.js +++ b/src/action.js @@ -132,15 +132,14 @@ var action = actions[i]; keyact[action.name.replace(/_/g, '')] = action; } - // TODO translation - var prm = Sao.common.selection('Select your action', keyact, - alwaysask); + var prm = Sao.common.selection( + Sao.i18n.gettext('Select your action'), + keyact, alwaysask); return prm.then(function(action) { Sao.Action.exec_action(action, data, context); }, function() { if (jQuery.isEmptyObject(keyact) && warning) { - // TODO translation - alert('No action defined!'); + alert(Sao.i18n.gettext('No action defined!')); } }); }; diff --git a/src/common.js b/src/common.js index 2ac7289e56..c15033400c 100644 --- a/src/common.js +++ b/src/common.js @@ -98,7 +98,8 @@ return prm; } var dialog = new Sao.Dialog( - title || 'Your selection:', 'selection-dialog'); + title || Sao.i18n.gettext('Your selection:'), + 'selection-dialog'); keys.forEach(function(k, i) { jQuery('
', { @@ -117,14 +118,14 @@ jQuery('