diff --git a/.gitignore b/.gitignore index 7c9c458c7..059c43b5e 100644 --- a/.gitignore +++ b/.gitignore @@ -45,6 +45,11 @@ js/copayMain.js css/copay.min.css css/vendors.min.css +# translation +po/* +!po/*.po +js/translations.js + webapp browser-extensions/chrome/copay-chrome-extension browser-extensions/chrome/copay-chrome-extension.zip diff --git a/Gruntfile.js b/Gruntfile.js index 0183f688e..4b1216fb4 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -8,6 +8,7 @@ module.exports = function(grunt) { grunt.loadNpmTasks('grunt-contrib-cssmin'); grunt.loadNpmTasks('grunt-contrib-concat'); grunt.loadNpmTasks('grunt-contrib-uglify'); + grunt.loadNpmTasks('grunt-angular-gettext'); // Project Configuration grunt.initConfig({ @@ -105,7 +106,8 @@ module.exports = function(grunt) { 'lib/angular-qrcode/qrcode.js', 'lib/ng-idle/angular-idle.min.js', 'lib/angular-foundation/mm-foundation.min.js', - 'lib/angular-foundation/mm-foundation-tpls.min.js' + 'lib/angular-foundation/mm-foundation-tpls.min.js', + 'lib/angular-gettext/dist/angular-gettext.min.js' ], dest: 'lib/angularjs-all.js' }, @@ -117,6 +119,7 @@ module.exports = function(grunt) { 'js/routes.js', 'js/services/*.js', 'js/controllers/*.js', + 'js/translations.js', 'js/mobile.js', // PLACEHOLDER: CORDOVA SRIPT 'js/init.js' ], @@ -146,10 +149,28 @@ module.exports = function(grunt) { 'lib/vendors.js': ['lib/vendors.js'] } } + }, + nggettext_extract: { + pot: { + files: { + 'po/template.pot': ['index.html', 'views/*.html', 'views/**/*.html'] + } + }, + }, + nggettext_compile: { + all: { + options: { + module: 'copayApp' + }, + files: { + 'js/translations.js': ['po/*.po'] + } + }, } }); - grunt.registerTask('default', ['shell:dev', 'concat', 'cssmin']); - grunt.registerTask('prod', ['shell:prod', 'concat', 'cssmin', 'uglify']); + grunt.registerTask('default', ['shell:dev', 'nggettext_compile', 'concat', 'cssmin']); + grunt.registerTask('prod', ['shell:prod', 'nggettext_compile', 'concat', 'cssmin', 'uglify']); + grunt.registerTask('translate', ['nggettext_extract']); }; diff --git a/bower.json b/bower.json index ffd5637f6..b07213719 100644 --- a/bower.json +++ b/bower.json @@ -11,6 +11,7 @@ "angular-route": "~1.2.14", "angular-qrcode": "~3.1.0", "angular-mocks": "~1.2.14", + "angular-gettext": "~1.1.0", "mocha": "~1.18.2", "chai": "~1.9.1", "crypto-js": "http://crypto-js.googlecode.com/files/CryptoJS%20v3.1.2.zip", diff --git a/config.js b/config.js index af79f4175..984e1b2c8 100644 --- a/config.js +++ b/config.js @@ -1,5 +1,6 @@ 'use strict'; var defaultConfig = { + defaultLanguage: 'en', // DEFAULT network (livenet or testnet) networkName: 'testnet', forceNetwork: false, diff --git a/js/app.js b/js/app.js index fcc03a23a..4f4934cf3 100644 --- a/js/app.js +++ b/js/app.js @@ -24,6 +24,7 @@ var copayApp = window.copayApp = angular.module('copayApp', [ 'mm.foundation', 'monospaced.qrcode', 'ngIdle', + 'gettext', 'copayApp.filters', 'copayApp.services', 'copayApp.controllers', diff --git a/js/controllers/settings.js b/js/controllers/settings.js index 0e72fceb2..4e3020666 100644 --- a/js/controllers/settings.js +++ b/js/controllers/settings.js @@ -9,6 +9,22 @@ angular.module('copayApp.controllers').controller('SettingsController', function $scope.insightPort = config.blockchain.port; $scope.insightSecure = config.blockchain.schema === 'https'; $scope.forceNetwork = config.forceNetwork; + $scope.defaultLanguage = config.defaultLanguage || 'en'; + + $scope.availableLanguages = [{ + name: 'English', + isoCode: 'en', + }, { + name: 'Spanish', + isoCode: 'es', + }]; + + for (var ii in $scope.availableLanguages) { + if ($scope.defaultLanguage === $scope.availableLanguages[ii].isoCode) { + $scope.selectedLanguage = $scope.availableLanguages[ii]; + break; + } + } $scope.unitOpts = [{ name: 'Satoshis (100,000,000 satoshis = 1BTC)', @@ -90,7 +106,8 @@ angular.module('copayApp.controllers').controller('SettingsController', function alternativeName: $scope.selectedAlternative.name, alternativeIsoCode: $scope.selectedAlternative.isoCode, - version: copay.version + version: copay.version, + defaultLanguage: $scope.selectedLanguage.isoCode })); // Go home reloading the application diff --git a/js/routes.js b/js/routes.js index 3ff033a11..02c036251 100644 --- a/js/routes.js +++ b/js/routes.js @@ -79,7 +79,8 @@ angular $idleProvider.warningDuration(20); // in seconds $keepaliveProvider.interval(2); // in seconds }) -.run(function($rootScope, $location, $idle) { +.run(function($rootScope, $location, $idle, gettextCatalog) { + gettextCatalog.currentLanguage = config.defaultLanguage; $idle.watch(); $rootScope.$on('$routeChangeStart', function(event, next, current) { if (!localStorage || localStorage.length < 1) { diff --git a/package.json b/package.json index 10ffd2da7..c04b88bce 100644 --- a/package.json +++ b/package.json @@ -60,6 +60,7 @@ "bitcore": "0.1.35", "grunt-mocha-test": "0.8.2", "grunt-shell": "0.6.4", + "grunt-angular-gettext": "^0.2.15", "istanbul": "0.2.10", "karma": "0.12.9", "karma-chrome-launcher": "0.1.3",