From 5a6533201e58e99f86a3b12d2abb9372460ee9b6 Mon Sep 17 00:00:00 2001 From: Zog Date: Wed, 7 Feb 2018 09:23:20 +0100 Subject: Refs #4126 @6h; Add i18n to JS --- .gitignore | 2 ++ Gemfile | 1 + Gemfile.lock | 3 +++ app/assets/javascripts/application.js | 3 +++ app/assets/javascripts/i18n/extended.coffee | 24 ++++++++++++++++++++++ app/assets/stylesheets/components/_tables.sass | 3 ++- .../vehicle_journeys/components/ConfirmModal.js | 6 +++--- .../vehicle_journeys/components/Filters.js | 18 ++++++++-------- .../vehicle_journeys/components/VehicleJourney.js | 10 ++++----- .../vehicle_journeys/components/VehicleJourneys.js | 18 ++++++++-------- .../components/tools/EditVehicleJourney.js | 2 +- app/views/calendars/_form_advanced.html.slim | 2 +- app/views/layouts/application.html.slim | 2 ++ app/views/routes/_form.html.slim | 2 +- app/views/time_tables/edit.html.slim | 2 +- app/views/time_tables/index.html.slim | 2 +- app/views/vehicle_journeys/index.html.slim | 2 +- app/views/workbenches/show.html.slim | 2 +- config/environments/development.rb | 1 + config/locales/en.yml | 5 +++++ config/locales/fr.yml | 4 ++++ config/locales/vehicle_journeys.en.yml | 15 ++++++++++++++ config/locales/vehicle_journeys.fr.yml | 16 +++++++++++++++ lib/tasks/ci.rake | 4 ++-- package.json | 4 ++++ spec/javascript/preprocessor.js | 15 ++++++++++++++ .../components/VehicleJourneys_spec.js | 7 +++++++ .../__snapshots__/VehicleJourneys_spec.js.snap | 20 +++++++++--------- 28 files changed, 149 insertions(+), 46 deletions(-) create mode 100644 app/assets/javascripts/i18n/extended.coffee create mode 100644 spec/javascript/preprocessor.js diff --git a/.gitignore b/.gitignore index acdb5e230..dd4d057ef 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,8 @@ /tmp *~ public/assets/ +public/javascripts/i18n.js +public/javascripts/translations.js # for vim users *.swp diff --git a/Gemfile b/Gemfile index bb1a42df0..db5202bdf 100644 --- a/Gemfile +++ b/Gemfile @@ -103,6 +103,7 @@ gem 'will_paginate-bootstrap' gem 'gretel' gem 'country_select' gem 'flag-icons-rails' +gem 'i18n-js' # Format Output gem 'json' diff --git a/Gemfile.lock b/Gemfile.lock index ffa63b535..41469d9c2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -270,6 +270,8 @@ GEM multi_xml (>= 0.5.2) i18n (0.9.3) concurrent-ruby (~> 1.0) + i18n-js (3.0.4) + i18n (~> 0.6, >= 0.6.6) i18n-tasks (0.9.15) activesupport (>= 4.0.2) ast (>= 2.1.0) @@ -636,6 +638,7 @@ DEPENDENCIES gretel has_array_of! htmlbeautifier + i18n-js i18n-tasks inherited_resources jbuilder (~> 2.0) diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 4c5aff22f..6a79f7e8e 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -22,3 +22,6 @@ //= require_directory . // require('whatwg-fetch') // require('babel-polyfill') +//= require "i18n" +//= require "i18n/extended" +//= require "i18n/translations" diff --git a/app/assets/javascripts/i18n/extended.coffee b/app/assets/javascripts/i18n/extended.coffee new file mode 100644 index 000000000..aeb67bd09 --- /dev/null +++ b/app/assets/javascripts/i18n/extended.coffee @@ -0,0 +1,24 @@ +#= require i18n + +decorateI18n = (_i18n)-> + _i18n.tc = (key, opts={}) -> + out = _i18n.t(key, opts) + out += " " if _i18n.locale == "fr" + out + ":" + + _i18n.model_name = (model, opts={}) -> + last_key = if opts.plural then "other" else "one" + _i18n.t("activerecord.models.#{model}.#{last_key}") + + _i18n.attribute_name = (model, attribute, opts={}) -> + _i18n.t("activerecord.attributes.#{model}.#{attribute}") + + _i18n.enumerize = (enumerize, key, opts={}) -> + I18n.t("enumerize.#{enumerize}.#{key}") + + _i18n + +module?.exports = decorateI18n + +if I18n? + decorateI18n(I18n) diff --git a/app/assets/stylesheets/components/_tables.sass b/app/assets/stylesheets/components/_tables.sass index 35e1122f3..5f8b06f09 100644 --- a/app/assets/stylesheets/components/_tables.sass +++ b/app/assets/stylesheets/components/_tables.sass @@ -9,7 +9,6 @@ font-weight: 700 border-bottom: 2px solid $darkgrey vertical-align: middle - > a position: relative display: block @@ -326,6 +325,8 @@ padding: 6px 8px border-bottom: 2px solid rgba($grey, 0.5) border-top: 1px solid rgba($grey, 0.5) + text-transform: capitalize + .td position: relative padding: 6px 8px diff --git a/app/javascript/vehicle_journeys/components/ConfirmModal.js b/app/javascript/vehicle_journeys/components/ConfirmModal.js index 3bfc852fb..75e8a3932 100644 --- a/app/javascript/vehicle_journeys/components/ConfirmModal.js +++ b/app/javascript/vehicle_journeys/components/ConfirmModal.js @@ -7,7 +7,7 @@ export default function ConfirmModal({dispatch, modal, onModalAccept, onModalCan
Voulez-vous valider vos modifications avant de changer de page?
+{I18n.t('vehicle_journeys.vehicle_journeys_matrix.modal_confirm')}