diff --git a/config/assets.yml b/config/assets.yml index 430fefba9aa..5d82d5292d7 100644 --- a/config/assets.yml +++ b/config/assets.yml @@ -4,6 +4,7 @@ gzip_assets: off css_compressor_options: line_break: 0 +<% saved = _erbout; _erbout = '' %> javascripts: common: - public/javascripts/firebugx.js @@ -33,7 +34,7 @@ javascripts: - public/javascripts/feedback.js - public/javascripts/license_help.js - public/javascripts/wiki_sidebar.js - - public/javascripts/translations/_core.js + - public/javascripts/translations/_core_en.js speed_grader: - public/javascripts/jquery.elastic.js - public/javascripts/ui.selectmenu.js @@ -222,6 +223,27 @@ javascripts: teacher_activity_report: - public/javascripts/jquery.tablesorter.min.js - public/javascripts/compiled/teacher_activity_report.js +<% base_js = _erbout; _erbout = saved %> + +<%= + def conflict(key, oldval, newval) + if oldval.is_a?(Hash) && newval.is_a?(Hash) + oldval.merge(newval) { |key, oldval, newval| conflict(key, oldval, newval) } + elsif oldval.is_a?(Array) && newval.is_a?(Array) + oldval + newval + else + oldval + end + end + + localization_file = 'config/localization_assets.yml' + if File.exists?(localization_file) + localization_js_hash = YAML.load_file(localization_file) + base_js_hash = YAML.load(base_js) + base_js = base_js_hash.merge(localization_js_hash) { |key, oldval, newval| conflict(key, oldval, newval) }.to_yaml.sub(/---/, '') + end + base_js +%> stylesheets: common: diff --git a/lib/tasks/canvas.rake b/lib/tasks/canvas.rake index 9b9fc9828d0..b4eade2b7c8 100644 --- a/lib/tasks/canvas.rake +++ b/lib/tasks/canvas.rake @@ -101,7 +101,7 @@ namespace :canvas do desc "Checks all js files for sytax errors." task :all do - bundles = YAML.load_file('config/assets.yml')['javascripts'] + bundles = YAML.load(ERB.new(File.read('config/assets.yml')).result)['javascripts'] bundles.each do |bundle_name, bundle_files| puts "------------------------------------------------------------" puts "checking bundle: " + bundle_name diff --git a/lib/tasks/i18n.rake b/lib/tasks/i18n.rake index 1385c8aad1d..679234ba944 100755 --- a/lib/tasks/i18n.rake +++ b/lib/tasks/i18n.rake @@ -193,9 +193,16 @@ namespace :i18n do }.empty? and $stderr.puts "WARNING: #{file} has an I18n scope but is not used in any bundles" end - assets_file = 'config/assets.yml' - assets_content = File.read(assets_file) - orig_assets_content = assets_content.dup + assets_file = 'config/localization_assets.yml' + orig_assets_content = File.read(assets_file) if File.exists?(assets_file) + orig_localization_assets = (YAML.load(orig_assets_content)["javascripts"] if orig_assets_content) || {} + orig_localization_assets.symbolize_keys! + assets_content = <<-TRANSLATIONS +# this file was auto-generated by rake i18n:generate_js. +# you probably shouldn't edit it directly + +javascripts: + TRANSLATIONS bundle_it = proc { |bundle, *args| translations = args.shift @@ -209,18 +216,21 @@ $.extend(true, (I18n = I18n || {}), {translations: #{translations.to_json}}); if !File.exist?(bundle_file) || File.read(bundle_file) != content File.open(bundle_file, "w"){ |f| f.write content } end - unless bundles[bundle].include?(bundle_file) - assets_content.sub!(/(^ #{bundle}:\n( - public\/[^\n]+\n)*)/, "\\1 - #{bundle_file}\n") or raise "couldn't add #{bundle_file} to assets.yml" + if !bundles[bundle].include?(bundle_file) || orig_localization_assets[bundle].try(:include?, bundle_file) + assets_content << <<-TRANSLATIONS + #{bundle}: + - #{bundle_file} + TRANSLATIONS end } + all_translations = I18n.backend.send(:translations) bundle_translations.each do |bundle, translations| bundle_it.call(bundle, translations.expand) unless translations.empty? end # in addition to getting the non-en stuff into each bundle, we need to get the core # formats and stuff for all languages (en included) into the common bundle - all_translations = I18n.backend.send(:translations) core_translations = I18n.available_locales.inject({}) { |h1, locale| h1[locale] = [:date, :time, :number, :datetime].inject({}) { |h2, key| h2[key] = all_translations[locale][key] if all_translations[locale][key] @@ -228,6 +238,8 @@ $.extend(true, (I18n = I18n || {}), {translations: #{translations.to_json}}); } h1 } + english_core_translations = {:en => core_translations.delete(:en)} + bundle_it.call(:common, english_core_translations, '_core_en') bundle_it.call(:common, core_translations, '_core') if orig_assets_content != assets_content @@ -413,4 +425,4 @@ $.extend(true, (I18n = I18n || {}), {translations: #{translations.to_json}}); f.write({language => new_translations.expand}.ya2yaml(:syck_compatible => true)) } end -end \ No newline at end of file +end diff --git a/public/javascripts/translations/_core.js b/public/javascripts/translations/_core.js deleted file mode 100644 index 30173f0f522..00000000000 --- a/public/javascripts/translations/_core.js +++ /dev/null @@ -1,3 +0,0 @@ -// this file was auto-generated by rake i18n:generate_js. -// you probably shouldn't edit it directly -$.extend(true, (I18n = I18n || {}), {translations: {"es":{"number":{"percentage":{"format":{"delimiter":""}},"currency":{"format":{"separator":".","format":"%u%n","delimiter":",","unit":"$","precision":2}},"format":{"separator":".","delimiter":",","precision":3},"human":{"format":{"delimiter":"","precision":1},"storage_units":{"units":{"tb":"TB","kb":"KB","byte":{"one":"Byte","other":"Bytes"},"mb":"MB","gb":"GB"},"format":"%n %u"}},"precision":{"format":{"delimiter":""}}},"datetime":{"prompts":{"day":"D\u00eda","minute":"Minuto","month":"Mes","second":"Segundos","year":"A\u00f1o","hour":"Hora"},"distance_in_words":{"about_x_months":{"one":"casi 1 mes","other":"casi %{count} meses"},"almost_x_years":{"one":"casi 1 a\u00f1o","other":"casi %{count} a\u00f1os"},"x_minutes":{"one":"1 minuto","other":"%{count} minutos"},"x_seconds":{"one":"1 segundo","other":"%{count} segundos"},"x_months":{"one":"1 mes","other":"%{count} meses"},"less_than_x_seconds":{"one":"menos de 1 segundo","other":"menos de %{count} segundos"},"half_a_minute":"medio minuto","about_x_hours":{"one":"casi 1 hora","other":"casi %{count} horas"},"about_x_years":{"one":"casi 1 a\u00f1o","other":"casi %{count} a\u00f1os"},"x_days":{"one":"1 d\u00eda","other":"%{count} d\u00edas"},"less_than_x_minutes":{"one":"menos de un minuto","other":"menos de %{count} minutos"},"over_x_years":{"one":"m\u00e1s de 1 a\u00f1o","other":"m\u00e1s de %{count} a\u00f1os"}}},"date":{"abbr_day_names":["Dom","Lun","Mar","Mie","Jue","Vie","Sab"],"day_names":["Domingo","Lunes","Martes","Miercoles","Jueves","Viernes","Sabado"],"formats":{"weekday":"%A","default":"%Y-%m-%d","short":"%b %e","long":"%B %d, %Y","medium":"%b %e, %Y"},"abbr_month_names":[null,"Ene","Feb","Mar","Abr","May","Jun","Jul","Ago","Sep","Oct","Nov","Dic"],"month_names":[null,"Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre"],"days":{"today":"Hoy","yesterday":"Ayer","today_lower":"hoy","tomorrow":"Ma\u00f1ana"},"order":["a\u00f1o","mes","d\u00eda"]},"time":{"with_ago":"hace %{time}","event":"%{date} en %{time}","formats":{"default":"%a, %d %b %Y %H:%M:%S %z","tiny_on_the_hour":"%l%P","short":"%d %b %H:%M","tiny":"%l:%M%P","long":"%B %d, %Y %H:%M"},"ranges":{"times":"%{start_time} hasta %{end_time}","same_day":"%{date} desde %{start_time} hasta %{end_time}","different_days":"%{start_date_and_time} hasta %{end_date_and_time}"},"pm":"pm","am":"am","unknown_date":"Fecha desconocida","due_date":"%{date} hasta %{time}"}},"en":{"number":{"percentage":{"format":{"delimiter":""}},"currency":{"format":{"separator":".","format":"%u%n","delimiter":",","unit":"$","precision":2}},"format":{"separator":".","delimiter":",","precision":3},"human":{"format":{"delimiter":"","precision":1},"storage_units":{"units":{"tb":"TB","byte":{"one":"Byte","other":"Bytes"},"kb":"KB","mb":"MB","gb":"GB"},"format":"%n %u"}},"precision":{"format":{"delimiter":""}}},"datetime":{"prompts":{"day":"Day","month":"Month","minute":"Minute","second":"Seconds","year":"Year","hour":"Hour"},"distance_in_words":{"about_x_months":{"one":"about 1 month","other":"about %{count} months"},"x_minutes":{"one":"1 minute","other":"%{count} minutes"},"almost_x_years":{"one":"almost 1 year","other":"almost %{count} years"},"x_months":{"one":"1 month","other":"%{count} months"},"x_seconds":{"one":"1 second","other":"%{count} seconds"},"less_than_x_seconds":{"one":"less than 1 second","other":"less than %{count} seconds"},"half_a_minute":"half a minute","about_x_hours":{"one":"about 1 hour","other":"about %{count} hours"},"about_x_years":{"one":"about 1 year","other":"about %{count} years"},"x_days":{"one":"1 day","other":"%{count} days"},"over_x_years":{"one":"over 1 year","other":"over %{count} years"},"less_than_x_minutes":{"one":"less than a minute","other":"less than %{count} minutes"}}},"date":{"abbr_day_names":["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],"day_names":["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],"formats":{"weekday":"%A","default":"%Y-%m-%d","short":"%b %e","long":"%B %d, %Y","medium":"%b %e, %Y"},"abbr_month_names":[null,"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],"order":["year","month","day"],"month_names":[null,"January","February","March","April","May","June","July","August","September","October","November","December"],"days":{"today_lower":"today"}},"time":{"formats":{"default":"%a, %d %b %Y %H:%M:%S %z","short":"%d %b %H:%M","tiny_on_the_hour":"%l%P","long":"%B %d, %Y %H:%M","tiny":"%l:%M%P"},"pm":"pm","am":"am"}}}}); diff --git a/public/javascripts/translations/_core_en.js b/public/javascripts/translations/_core_en.js new file mode 100644 index 00000000000..a0253b834d4 --- /dev/null +++ b/public/javascripts/translations/_core_en.js @@ -0,0 +1,3 @@ +// this file was auto-generated by rake i18n:generate_js. +// you probably shouldn't edit it directly +$.extend(true, (I18n = I18n || {}), {translations: {"en":{"datetime":{"distance_in_words":{"over_x_years":{"one":"over 1 year","other":"over %{count} years"},"less_than_x_minutes":{"one":"less than a minute","other":"less than %{count} minutes"},"about_x_months":{"one":"about 1 month","other":"about %{count} months"},"x_seconds":{"one":"1 second","other":"%{count} seconds"},"x_minutes":{"one":"1 minute","other":"%{count} minutes"},"almost_x_years":{"one":"almost 1 year","other":"almost %{count} years"},"x_months":{"one":"1 month","other":"%{count} months"},"less_than_x_seconds":{"one":"less than 1 second","other":"less than %{count} seconds"},"half_a_minute":"half a minute","about_x_hours":{"one":"about 1 hour","other":"about %{count} hours"},"about_x_years":{"one":"about 1 year","other":"about %{count} years"},"x_days":{"one":"1 day","other":"%{count} days"}},"prompts":{"day":"Day","second":"Seconds","minute":"Minute","month":"Month","year":"Year","hour":"Hour"}},"date":{"month_names":[null,"January","February","March","April","May","June","July","August","September","October","November","December"],"abbr_day_names":["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],"days":{"today_lower":"today"},"day_names":["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],"abbr_month_names":[null,"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],"formats":{"medium":"%b %e, %Y","default":"%Y-%m-%d","weekday":"%A","short":"%b %e","long":"%B %d, %Y"},"order":["year","month","day"]},"time":{"am":"am","pm":"pm","formats":{"default":"%a, %d %b %Y %H:%M:%S %z","tiny":"%l:%M%P","short":"%d %b %H:%M","tiny_on_the_hour":"%l%P","long":"%B %d, %Y %H:%M"}},"number":{"percentage":{"format":{"delimiter":""}},"currency":{"format":{"delimiter":",","precision":2,"unit":"$","format":"%u%n","separator":"."}},"precision":{"format":{"delimiter":""}},"format":{"delimiter":",","precision":3,"separator":"."},"human":{"format":{"delimiter":"","precision":1},"storage_units":{"format":"%n %u","units":{"kb":"KB","mb":"MB","byte":{"one":"Byte","other":"Bytes"},"gb":"GB","tb":"TB"}}}}}}});