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:
parent
43aa27e436
commit
81e50dbc71
1
Gemfile
1
Gemfile
|
@ -39,6 +39,7 @@ gem 'sass', '3.2.3'
|
|||
gem 'hashery', '1.3.0', :require => 'hashery/dictionary'
|
||||
gem 'highline', '1.6.1'
|
||||
gem 'i18n', CANVAS_RAILS3 ? '0.5.0' : '0.6.0'
|
||||
gem 'i18nema', '0.0.7'
|
||||
gem 'icalendar', '1.1.5'
|
||||
gem 'jammit', '0.6.6'
|
||||
gem 'json', '1.8.0'
|
||||
|
|
|
@ -6,7 +6,9 @@ if skip_locale_loading
|
|||
else
|
||||
I18n.load_path += Dir[Rails.root.join('vendor', 'plugins', '*', 'config', 'locales', '**', '*.{rb,yml}')]
|
||||
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
|
||||
def before_label(text_or_key, default_value = nil, *args)
|
||||
|
|
|
@ -58,7 +58,7 @@ class I18nImport
|
|||
|
||||
def complete_translations
|
||||
I18n.available_locales
|
||||
base = (I18n.backend.send(:translations)[language.to_sym] || {})
|
||||
base = (I18n.backend.direct_lookup(language) || {})
|
||||
translations = base.flatten_keys.merge(new_translations)
|
||||
fix_plural_keys(translations)
|
||||
translations.expand_keys
|
||||
|
|
|
@ -70,7 +70,7 @@ module LocaleSelection
|
|||
best_locales.first && best_locales.first.first
|
||||
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
|
||||
# there are other translations for that locale)
|
||||
def available_locales
|
||||
|
|
|
@ -74,7 +74,7 @@ namespace :i18n do
|
|||
value
|
||||
hash
|
||||
}
|
||||
@translations = I18n.backend.send(:translations)[:en].inject({}, &stringifier)
|
||||
@translations = I18n.backend.direct_lookup('en').inject({}, &stringifier)
|
||||
|
||||
|
||||
# Ruby
|
||||
|
@ -148,15 +148,9 @@ namespace :i18n do
|
|||
|
||||
desc "Generates JS bundle i18n files (non-en) and adds them to assets.yml"
|
||||
task :generate_js do
|
||||
require 'bundler'
|
||||
Bundler.setup
|
||||
require 'action_controller'
|
||||
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}')]
|
||||
ENV['RAILS_LOAD_ALL_LOCALES'] = '1'
|
||||
I18n.load_path += Dir[Rails.root.join('config', 'locales', '*', '*.{rb,yml}')]
|
||||
Rake::Task['environment'].invoke
|
||||
|
||||
Hash.send :include, I18n::HashExtensions
|
||||
|
||||
|
@ -168,7 +162,7 @@ namespace :i18n do
|
|||
#
|
||||
# LOCALES=hi,ja,pt,zh-hans rake i18n:generate_js
|
||||
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
|
||||
|
||||
if locales.empty?
|
||||
|
|
Loading…
Reference in New Issue