switch out i18n backend, closes CNVS-5938

test plan:
1. specs should pass
2. run canvas with RAILS_LOAD_ALL_LOCALES=1
3. you should be able to switch locales and see translations
4. run i18n:generate on the parent commit and on this commit, the
   resulting config/locales/generated/en.yml should be identical

Change-Id: I5164943dc6e682c663145e91d7a9791331e9b4cc
Reviewed-on: https://gerrit.instructure.com/21014
Tested-by: Jenkins <jenkins@instructure.com>
Reviewed-by: Cody Cutrer <cody@instructure.com>
QA-Review: Marc LeGendre <marc@instructure.com>
Product-Review: Marc LeGendre <marc@instructure.com>
This commit is contained in:
Jon Jensen 2013-05-29 12:54:10 -06:00
parent 43aa27e436
commit 81e50dbc71
5 changed files with 11 additions and 14 deletions

View File

@ -39,6 +39,7 @@ gem 'sass', '3.2.3'
gem 'hashery', '1.3.0', :require => 'hashery/dictionary' gem 'hashery', '1.3.0', :require => 'hashery/dictionary'
gem 'highline', '1.6.1' gem 'highline', '1.6.1'
gem 'i18n', CANVAS_RAILS3 ? '0.5.0' : '0.6.0' gem 'i18n', CANVAS_RAILS3 ? '0.5.0' : '0.6.0'
gem 'i18nema', '0.0.7'
gem 'icalendar', '1.1.5' gem 'icalendar', '1.1.5'
gem 'jammit', '0.6.6' gem 'jammit', '0.6.6'
gem 'json', '1.8.0' gem 'json', '1.8.0'

View File

@ -6,7 +6,9 @@ if skip_locale_loading
else else
I18n.load_path += Dir[Rails.root.join('vendor', 'plugins', '*', 'config', 'locales', '**', '*.{rb,yml}')] I18n.load_path += Dir[Rails.root.join('vendor', 'plugins', '*', 'config', 'locales', '**', '*.{rb,yml}')]
end end
I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks) I18n.backend = I18nema::Backend.new
I18nema::Backend.send(:include, I18n::Backend::Fallbacks)
I18n.backend.init_translations
module I18nUtilities module I18nUtilities
def before_label(text_or_key, default_value = nil, *args) def before_label(text_or_key, default_value = nil, *args)

View File

@ -58,7 +58,7 @@ class I18nImport
def complete_translations def complete_translations
I18n.available_locales I18n.available_locales
base = (I18n.backend.send(:translations)[language.to_sym] || {}) base = (I18n.backend.direct_lookup(language) || {})
translations = base.flatten_keys.merge(new_translations) translations = base.flatten_keys.merge(new_translations)
fix_plural_keys(translations) fix_plural_keys(translations)
translations.expand_keys translations.expand_keys

View File

@ -70,7 +70,7 @@ module LocaleSelection
best_locales.first && best_locales.first.first best_locales.first && best_locales.first.first
end end
# gives you a hash of localized locales, e.g. {:en => "English", :es => "Español" } # gives you a hash of localized locales, e.g. {"en" => "English", "es" => "Español" }
# if the locale name is not yet translated, it won't be included (even if # if the locale name is not yet translated, it won't be included (even if
# there are other translations for that locale) # there are other translations for that locale)
def available_locales def available_locales

View File

@ -74,7 +74,7 @@ namespace :i18n do
value value
hash hash
} }
@translations = I18n.backend.send(:translations)[:en].inject({}, &stringifier) @translations = I18n.backend.direct_lookup('en').inject({}, &stringifier)
# Ruby # Ruby
@ -148,15 +148,9 @@ namespace :i18n do
desc "Generates JS bundle i18n files (non-en) and adds them to assets.yml" desc "Generates JS bundle i18n files (non-en) and adds them to assets.yml"
task :generate_js do task :generate_js do
require 'bundler' ENV['RAILS_LOAD_ALL_LOCALES'] = '1'
Bundler.setup I18n.load_path += Dir[Rails.root.join('config', 'locales', '*', '*.{rb,yml}')]
require 'action_controller' Rake::Task['environment'].invoke
require 'i18n'
require 'sexp_processor'
require 'jammit'
require 'lib/i18n_extraction/js_extractor.rb'
I18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.{rb,yml}')] +
Dir[Rails.root.join('vendor', 'plugins', '*', 'config', 'locales', '**', '*.{rb,yml}')]
Hash.send :include, I18n::HashExtensions Hash.send :include, I18n::HashExtensions
@ -168,7 +162,7 @@ namespace :i18n do
# #
# LOCALES=hi,ja,pt,zh-hans rake i18n:generate_js # LOCALES=hi,ja,pt,zh-hans rake i18n:generate_js
locales = locales + ENV['LOCALES'].split(',') if ENV['LOCALES'] locales = locales + ENV['LOCALES'].split(',') if ENV['LOCALES']
all_translations = I18n.backend.send(:translations) all_translations = I18n.backend.direct_lookup
flat_translations = all_translations.flatten_keys flat_translations = all_translations.flatten_keys
if locales.empty? if locales.empty?