don't allow locale names or codes to be overridden, fixes CNVS-14465

basically two changes:
1. ensure locales.yml is loaded last, to ensure we don't get any wonky
   overrides from translators
2. don't send those strings off for translation any more

test plan:
1. in a rails console w/ RAILS_LOAD_ALL_LOCALES=true, confirm that:
   >  I18n.backend.direct_lookup("nl", "qualified_locale")
  => "nl-NL"`
2. run `rake i18n:generate` and confirm that "qualified_locale" does
   not appear anywhere in ./config/locales/generated/en.yml
3. in canvas (w/ RAILS_LOAD_ALL_LOCALES=true), change your locale to
   "Nederlands (Crowd Sourced)"
4. confirm that you can still view wiki pages

Change-Id: I3923f58d7b9433a9e5e062e16e1556d79f845ae4
Reviewed-on: https://gerrit.instructure.com/38475
Reviewed-by: Cody Cutrer <cody@instructure.com>
Reviewed-by: Brian Palmer <brianp@instructure.com>
Tested-by: Jenkins <jenkins@instructure.com>
QA-Review: Steven Shepherd <sshepherd@instructure.com>
Product-Review: Matt Fairbourn <mfairbourn@instructure.com>
This commit is contained in:
Jon Jensen 2014-07-30 16:31:36 -06:00
parent d666617bbb
commit 4db746a1c0
2 changed files with 3 additions and 3 deletions

View File

@ -1,11 +1,11 @@
# loading all the locales has a significant (>30%) impact on the speed of initializing canvas
# so we skip it in situations where we don't need the locales, such as in development mode and in rails console
skip_locale_loading = (Rails.env.development? || Rails.env.test? || $0 == 'irb') && !ENV['RAILS_LOAD_ALL_LOCALES']
load_path = CANVAS_RAILS2 ? I18n.load_path : Rails.application.config.i18n.railties_load_path
if skip_locale_loading
load_path = CANVAS_RAILS2 ? I18n.load_path : Rails.application.config.i18n.railties_load_path
load_path.replace(load_path.grep(%r{/(locales|en)\.yml\z}))
else
I18n.load_path << (Rails.root + "config/locales/locales.yml").to_s # add it at the end, to trump any weird/invalid stuff in locale-specific files
load_path << (Rails.root + "config/locales/locales.yml").to_s # add it at the end, to trump any weird/invalid stuff in locale-specific files
end
I18n.backend = I18nema::Backend.new

View File

@ -142,7 +142,7 @@ namespace :i18n do
FileUtils.mkdir_p(File.join(yaml_dir))
yaml_file = File.join(yaml_dir, "en.yml")
File.open(Rails.root.join(yaml_file), "w") do |file|
file.write({'en' => @translations}.ya2yaml(:syck_compatible => true))
file.write({'en' => @translations.except('locales', 'qualified_locale')}.ya2yaml(:syck_compatible => true))
end
print "Wrote new #{yaml_file}\n\n"
end