ensure _core_en.js is up-to-date, i18n:generate_js tweaks
* add a spec to keep _core_en.js current * remove a couple unnecessary requires * I18n.load_path parity (we don't need generated/en.yml here) * don't bother trying to load plugin yml files because we don't do those test plan: 1. specs should pass 2. localized canvas should also work, i.e. 1. run rake i18n:generate_js 2. run canvas with RAILS_LOAD_ALL_LOCALES=true and USE_OPTIMIZED_JS=true 3. switch to spanish 4. go to a localized js-heavy page (e.g. conferences) 5. you should see translated stuff Change-Id: Ia368c11f72fdc7395e4cbf82c3385d0c997b0dd4 Reviewed-on: https://gerrit.instructure.com/21788 Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Simon Williams <simon@instructure.com> QA-Review: Marc LeGendre <marc@instructure.com> Product-Review: Marc LeGendre <marc@instructure.com> Reviewed-by: Landon Wilkins <lwilkins@instructure.com>
This commit is contained in:
parent
5240c19933
commit
598452df45
|
@ -3,8 +3,6 @@
|
|||
skip_locale_loading = (Rails.env.development? || Rails.env.test? || $0 == 'irb') && !ENV['RAILS_LOAD_ALL_LOCALES']
|
||||
if skip_locale_loading
|
||||
I18n.load_path = I18n.load_path.grep(%r{/(locales|en)\.yml\z})
|
||||
else
|
||||
I18n.load_path += Dir[Rails.root.join('vendor', 'plugins', '*', 'config', 'locales', '**', '*.{rb,yml}')]
|
||||
end
|
||||
unless CANVAS_RAILS3
|
||||
I18n.backend = I18nema::Backend.new
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
module I18n
|
||||
module Utils
|
||||
CORE_KEYS = [:date, :time, :number, :datetime, :support]
|
||||
|
||||
def self.dump_js(translations)
|
||||
Hash.send :include, I18n::HashExtensions unless Hash.new.kind_of?(I18n::HashExtensions)
|
||||
|
||||
# include all locales (even if untranslated) to avoid js errors
|
||||
I18n.available_locales.each { |locale| translations[locale.to_s] ||= {} }
|
||||
|
||||
<<-TRANSLATIONS.gsub(/^ {8}/, '')
|
||||
// this file was auto-generated by rake i18n:generate_js.
|
||||
// you probably shouldn't edit it directly
|
||||
define(['i18nObj', 'jquery'], function(I18n, $) {
|
||||
$.extend(true, I18n, {translations: #{translations.to_ordered.to_json}});
|
||||
});
|
||||
TRANSLATIONS
|
||||
end
|
||||
end
|
||||
end
|
|
@ -148,20 +148,23 @@ namespace :i18n do
|
|||
|
||||
desc "Generates JS bundle i18n files (non-en) and adds them to assets.yml"
|
||||
task :generate_js do
|
||||
# This is intentially requiring things individually rather than just
|
||||
# This is intentionally requiring things individually rather than just
|
||||
# loading the rails+canvas environment, because that environment isn't
|
||||
# available during the deploy process. Don't change this out for a call to
|
||||
# the `environment` rake task.
|
||||
require 'bundler'
|
||||
Bundler.setup
|
||||
require 'action_controller'
|
||||
|
||||
# set up rails i18n paths ... normally rails env does this for us :-/
|
||||
require 'action_controller'
|
||||
require 'active_record'
|
||||
I18n.load_path += Dir[Rails.root.join('config', 'locales', '*.{rb,yml}')]
|
||||
|
||||
require 'i18n'
|
||||
require 'i18nema'
|
||||
require 'sexp_processor'
|
||||
require 'jammit'
|
||||
require 'lib/i18n_extraction/js_extractor.rb'
|
||||
I18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.{rb,yml}')]
|
||||
I18n.load_path += Dir[Rails.root.join('vendor', 'plugins', '*', 'config', 'locales', '**', '*.{rb,yml}')]
|
||||
require 'lib/i18n/utils'
|
||||
|
||||
I18n.backend = I18nema::Backend.new
|
||||
I18nema::Backend.send(:include, I18n::Backend::Fallbacks)
|
||||
I18n.backend.init_translations
|
||||
|
@ -175,7 +178,7 @@ namespace :i18n do
|
|||
# list of abbreviations in the LOCALES environment variable. e.g.
|
||||
#
|
||||
# LOCALES=hi,ja,pt,zh-hans rake i18n:generate_js
|
||||
locales = locales + ENV['LOCALES'].split(',') if ENV['LOCALES']
|
||||
locales += ENV['LOCALES'].split(',').map(&:to_sym) if ENV['LOCALES']
|
||||
all_translations = I18n.backend.direct_lookup
|
||||
flat_translations = all_translations.flatten_keys
|
||||
|
||||
|
@ -216,14 +219,7 @@ namespace :i18n do
|
|||
|
||||
dump_translations = lambda do |translation_name, translations|
|
||||
file = "public/javascripts/translations/#{translation_name}.js"
|
||||
locales.each { |locale| translations[locale.to_s] ||= {} }
|
||||
content = <<-TRANSLATIONS
|
||||
// this file was auto-generated by rake i18n:generate_js.
|
||||
// you probably shouldn't edit it directly
|
||||
define(['i18nObj', 'jquery'], function(I18n, $) {
|
||||
$.extend(true, I18n, {translations: #{translations.to_ordered.to_json}});
|
||||
});
|
||||
TRANSLATIONS
|
||||
content = I18n::Utils.dump_js(translations)
|
||||
if !File.exist?(file) || File.read(file) != content
|
||||
File.open(file, "w"){ |f| f.write content }
|
||||
end
|
||||
|
@ -236,7 +232,7 @@ define(['i18nObj', 'jquery'], function(I18n, $) {
|
|||
# in addition to getting the non-en stuff into each scope_file, we need to get the core
|
||||
# formats and stuff for all languages (en included) into the common scope_file
|
||||
core_translations = I18n.available_locales.inject({}) { |h1, locale|
|
||||
h1[locale.to_s] = all_translations[locale].slice(:date, :time, :number, :datetime, :support)
|
||||
h1[locale.to_s] = all_translations[locale].slice(*I18n::Utils::CORE_KEYS)
|
||||
h1
|
||||
}
|
||||
dump_translations.call('_core_en', {'en' => core_translations.delete('en')})
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// this file was auto-generated by rake i18n:generate_js.
|
||||
// you probably shouldn't edit it directly
|
||||
define(['i18nObj', 'jquery'], function(I18n, $) {
|
||||
$.extend(true, I18n, {translations: {"ar":{},"en":{"date":{"abbr_day_names":["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],"abbr_month_names":[null,"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],"day_names":["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],"days":{"today":"Today","today_lower":"today","tomorrow":"Tomorrow","yesterday":"Yesterday"},"formats":{"date_at_time":"%b %-d at %l:%M%P","default":"%Y-%m-%d","long":"%B %d, %Y","medium":"%b %-d, %Y","medium_month":"%b %Y","medium_with_weekday":"%a %b %-d, %Y","short":"%b %-d","short_month":"%b","short_weekday":"%a","weekday":"%A"},"month_names":[null,"January","February","March","April","May","June","July","August","September","October","November","December"],"order":["year","month","day"]},"datetime":{"distance_in_words":{"about_x_hours":{"one":"about 1 hour","other":"about %{count} hours"},"about_x_months":{"one":"about 1 month","other":"about %{count} months"},"about_x_years":{"one":"about 1 year","other":"about %{count} years"},"almost_x_years":{"one":"almost 1 year","other":"almost %{count} years"},"half_a_minute":"half a minute","less_than_x_minutes":{"one":"less than a minute","other":"less than %{count} minutes"},"less_than_x_seconds":{"one":"less than 1 second","other":"less than %{count} seconds"},"over_x_years":{"one":"over 1 year","other":"over %{count} years"},"x_days":{"one":"1 day","other":"%{count} days"},"x_minutes":{"one":"1 minute","other":"%{count} minutes"},"x_months":{"one":"1 month","other":"%{count} months"},"x_seconds":{"one":"1 second","other":"%{count} seconds"}},"prompts":{"day":"Day","hour":"Hour","minute":"Minute","month":"Month","second":"Seconds","year":"Year"}},"number":{"currency":{"format":{"delimiter":",","format":"%u%n","precision":2,"separator":".","unit":"$"}},"format":{"delimiter":",","precision":3,"separator":"."},"human":{"format":{"delimiter":"","precision":1},"storage_units":{"format":"%n %u","units":{"byte":{"one":"Byte","other":"Bytes"},"gb":"GB","kb":"KB","mb":"MB","tb":"TB"}}},"percentage":{"format":{"delimiter":""}},"precision":{"format":{"delimiter":""}}},"support":{"array":{"last_word_connector":", and ","or":{"last_word_connector":", or ","two_words_connector":" or "},"two_words_connector":" and ","words_connector":", "},"help_menu":{"community_support_description":"Interact with and get assistance from your peers.","community_support_forums":"Community Support Forums","contact_support":"Contact Support","contact_support_sub_text":"Get assistance with time-sensitive issues.","curriculum_assessment_errata":"Curriculum/Assessment Errata","curriculum_assessment_errata_description":"View already reported assessment and curricula errors. Search for \"errata.\"","networking_academy_description":"View Cisco answers to the most commonly asked questions.","networking_academy_faqs":"Networking Academy FAQs"},"select":{"prompt":"Please select"}},"time":{"am":"am","count_hours_ago":{"one":"1 hour ago","other":"%{count} hours ago"},"count_minutes_ago":{"one":"1 minute ago","other":"%{count} minutes ago"},"due_date":"%{date} by %{time}","event":"%{date} at %{time}","formats":{"default":"%a, %d %b %Y %H:%M:%S %z","long":"%B %d, %Y %H:%M","short":"%d %b %H:%M","tiny":"%l:%M%P","tiny_on_the_hour":"%l%P"},"less_than_a_minute_ago":"less than a minute ago","pm":"pm","ranges":{"different_days":"%{start_date_and_time} to %{end_date_and_time}","same_day":"%{date} from %{start_time} to %{end_time}","times":"%{start_time} to %{end_time}"},"unknown_date":"Unknown date","with_ago":"%{time} ago"}},"es":{},"fr":{},"ja":{},"ko":{},"nl":{},"pt":{},"ru":{},"zh":{}}});
|
||||
$.extend(true, I18n, {translations: {"ar":{},"en":{"date":{"abbr_day_names":["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],"abbr_month_names":[null,"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],"day_names":["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],"days":{"today_lower":"today"},"formats":{"date_at_time":"%b %-d at %l:%M%P","default":"%Y-%m-%d","long":"%B %d, %Y","medium":"%b %-d, %Y","medium_month":"%b %Y","medium_with_weekday":"%a %b %-d, %Y","short":"%b %-d","short_month":"%b","short_weekday":"%a","weekday":"%A"},"month_names":[null,"January","February","March","April","May","June","July","August","September","October","November","December"],"order":["year","month","day"]},"datetime":{"distance_in_words":{"about_x_hours":{"one":"about 1 hour","other":"about %{count} hours"},"about_x_months":{"one":"about 1 month","other":"about %{count} months"},"about_x_years":{"one":"about 1 year","other":"about %{count} years"},"almost_x_years":{"one":"almost 1 year","other":"almost %{count} years"},"half_a_minute":"half a minute","less_than_x_minutes":{"one":"less than a minute","other":"less than %{count} minutes"},"less_than_x_seconds":{"one":"less than 1 second","other":"less than %{count} seconds"},"over_x_years":{"one":"over 1 year","other":"over %{count} years"},"x_days":{"one":"1 day","other":"%{count} days"},"x_minutes":{"one":"1 minute","other":"%{count} minutes"},"x_months":{"one":"1 month","other":"%{count} months"},"x_seconds":{"one":"1 second","other":"%{count} seconds"}},"prompts":{"day":"Day","hour":"Hour","minute":"Minute","month":"Month","second":"Seconds","year":"Year"}},"number":{"currency":{"format":{"delimiter":",","format":"%u%n","precision":2,"separator":".","unit":"$"}},"format":{"delimiter":",","precision":3,"separator":"."},"human":{"format":{"delimiter":"","precision":1},"storage_units":{"format":"%n %u","units":{"byte":{"one":"Byte","other":"Bytes"},"gb":"GB","kb":"KB","mb":"MB","tb":"TB"}}},"percentage":{"format":{"delimiter":""}},"precision":{"format":{"delimiter":""}}},"support":{"array":{"last_word_connector":", and ","or":{"last_word_connector":", or ","two_words_connector":" or "},"two_words_connector":" and ","words_connector":", "},"help_menu":{"community_support_description":"Interact with and get assistance from your peers.","community_support_forums":"Community Support Forums","contact_support":"Contact Support","contact_support_sub_text":"Get assistance with time-sensitive issues.","curriculum_assessment_errata":"Curriculum/Assessment Errata","curriculum_assessment_errata_description":"View already reported assessment and curricula errors. Search for \"errata.\"","networking_academy_description":"View Cisco answers to the most commonly asked questions.","networking_academy_faqs":"Networking Academy FAQs"},"select":{"prompt":"Please select"}},"time":{"am":"am","formats":{"default":"%a, %d %b %Y %H:%M:%S %z","long":"%B %d, %Y %H:%M","short":"%d %b %H:%M","tiny":"%l:%M%P","tiny_on_the_hour":"%l%P"},"pm":"pm"}},"es":{},"fr":{},"ja":{},"ko":{},"nl":{},"pt":{},"ru":{},"zh":{}}});
|
||||
});
|
||||
|
|
|
@ -96,4 +96,16 @@ describe I18n do
|
|||
should == "thing count: 2"
|
||||
end
|
||||
end
|
||||
|
||||
context "_core_en.js" do
|
||||
it "should be up-to-date" do
|
||||
pending('RAILS_LOAD_ALL_LOCALES=true') unless ENV['RAILS_LOAD_ALL_LOCALES']
|
||||
translations = {'en' => I18n.backend.direct_lookup('en').slice(*I18n::Utils::CORE_KEYS)}
|
||||
|
||||
# HINT: if this spec fails, run `rake i18n:generate_js`...
|
||||
# it probably means you added a format or a new language
|
||||
File.read('public/javascripts/translations/_core_en.js').should ==
|
||||
I18n::Utils.dump_js(translations)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue