From 4a0c574a526e3c4802ef37b6407b78436f727217 Mon Sep 17 00:00:00 2001 From: Maurice Williams Date: Wed, 15 Apr 2015 00:28:24 -0400 Subject: [PATCH] Translating the admin panel for PoC * first time playing with ember-intl (part of format.js). using the 2.0 (beta) version to try side-loading of messages * installing grunt-plugin for downloading translated strings * removing old translation files * `grunt dev` will also download the translation files --- Gruntfile.js | 16 +++++++ core/client/app/app.js | 9 +++- core/client/app/formats.js | 25 ++++++++++ core/client/app/locales/en.js | 15 ++++++ core/client/app/locales/es.js | 12 +++++ core/client/app/templates/-navbar.hbs | 14 +++--- core/client/app/templates/settings/about.hbs | 48 ++++++++++++------- .../client/app/templates/settings/general.hbs | 3 +- core/client/package.json | 1 + core/client/translations/en.json | 30 ++++++++++++ package.json | 1 + 11 files changed, 148 insertions(+), 26 deletions(-) create mode 100644 core/client/app/formats.js create mode 100644 core/client/app/locales/en.js create mode 100644 core/client/app/locales/es.js create mode 100644 core/client/translations/en.json diff --git a/Gruntfile.js b/Gruntfile.js index 80bc507d645e..81bc2ae5889b 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -446,6 +446,19 @@ var _ = require('lodash'), params: '--init' } } + }, + + // ### transifex_keyvaluejson + // download translation strings from Transifex + transifex_keyvaluejson: { + admin: { + options: { + project: 'ghost-test-project', + resource: 'ghost-admin-poc', + dest: '/core/client/translations' + } + } + } }; @@ -878,6 +891,9 @@ var _ = require('lodash'), grunt.registerTask('init', 'Prepare the project for development', ['shell:ember:init', 'shell:bower', 'update_submodules', 'assets', 'default']); + grunt.registerTask('i18n', 'Get translation strings for all avialble locales', + ['transifex_keyvaluejson:admin']); + // ### Basic Asset Building // Builds and moves necessary client assets. Prod additionally builds the ember app. grunt.registerTask('assets', 'Basic asset building & moving', diff --git a/core/client/app/app.js b/core/client/app/app.js index 37a05b889807..94a78e24956e 100755 --- a/core/client/app/app.js +++ b/core/client/app/app.js @@ -10,7 +10,14 @@ Ember.MODEL_FACTORY_INJECTIONS = true; var App = Ember.Application.extend({ modulePrefix: config.modulePrefix, podModulePrefix: config.podModulePrefix, - Resolver: Resolver + Resolver: Resolver, + ready: function () { + + var language = navigator.language || navigator.browserLanguage; + //TODO: need to figure out how to set this dynamically based on blog setting + this.intl.set('locales', [language, 'hu-HU', 'es', 'en']); + + } }); loadInitializers(App, config.modulePrefix); diff --git a/core/client/app/formats.js b/core/client/app/formats.js new file mode 100644 index 000000000000..84315b142943 --- /dev/null +++ b/core/client/app/formats.js @@ -0,0 +1,25 @@ +export default { + date: { + 'numeric': { + month: 'numeric', + day: 'numeric', + year: 'numeric' + }, + long: { + month: 'long', + day : 'numeric', + year : 'numeric' + } + }, + number: { + usd: { style: 'currency', currency: 'EUR' }, + eur: { style: 'currency', currency: 'USD' } + }, + time: { + hhmmss: { + hour: 'numeric', + minute: 'numeric', + second: 'numeric' + } + } +}; diff --git a/core/client/app/locales/en.js b/core/client/app/locales/en.js new file mode 100644 index 000000000000..3ee8145c0435 --- /dev/null +++ b/core/client/app/locales/en.js @@ -0,0 +1,15 @@ +import Locale from 'ember-intl/models/locale'; + +export default Locale.extend({ + locale: 'en', + messages: { + greeting: 'hello!', + num: 99, + product: { + info: '{product} will cost {price, number, EUR} if ordered by {deadline, date, time}', + html: { + info: '{product} will cost {price, number, EUR} if ordered by {deadline, date, time}' + } + } + } +}); diff --git a/core/client/app/locales/es.js b/core/client/app/locales/es.js new file mode 100644 index 000000000000..603d0801369c --- /dev/null +++ b/core/client/app/locales/es.js @@ -0,0 +1,12 @@ +import Locale from 'ember-intl/models/locale'; + +export default Locale.extend({ + locale: 'es', + messages: { + greeting: 'hola!', + num: 99, + product: { + info: '{product} va a costar {price, number USD} si es ordenado antes del {deadline, date, time}' + } + } +}); diff --git a/core/client/app/templates/-navbar.hbs b/core/client/app/templates/-navbar.hbs index de5e12f20a3f..483f09face7d 100644 --- a/core/client/app/templates/-navbar.hbs +++ b/core/client/app/templates/-navbar.hbs @@ -1,20 +1,20 @@