Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use full regional locale in Dashboard #13363

Merged
merged 5 commits into from
Feb 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 0 additions & 34 deletions bin/i18n/sync-codeorg-out
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ def push_out_translated_files
rename_from_crowdin_name_to_locale
run_bash_script "bin/i18n-codeorg/out.sh"
copy_untranslated_apps
cleanup_chinese_and_portuguese_codes
rebuild_blockly_js_files
check_for_mismatching_links_or_images
puts "updating TTS I18n (should usually take 2-3 minutes, may take up to 15 if there are a whole lot of translation updates)"
Expand Down Expand Up @@ -46,39 +45,6 @@ def copy_untranslated_apps
end
end

# Dashboard currently has a bug; it uses 2 letter language codes instead of 4 letter locales.
# When two languages share the same language code, Dashboard doesn't know which language
# to use so we've overrided the user's selected language to always show Simplified Chinese
# (zh-CN) even if they've selected Traditional Chinese (zh-TW). Likewise for Brazilian
# Portuguese (pt-BR) and Portugal Portuguese (pt-PT).
# TODO (Tanya): Fix Dashboard to use 4 letter locales instead of 2 letter language codes
# and remove this hacky override.
def cleanup_chinese_and_portuguese_codes
dashboard_categories = %w(authored_hints callouts data devise dsls failure_message_overrides instructions markdown_instructions scripts slides unplugged)

locales_with_same_language = {
'zh' => ['zh-CN', 'zh-TW'],
'pt' => ['pt-BR', 'pt-PT']
}

locales_with_same_language.each do |language, locales|
# Fix codes in base file
file = "dashboard/config/locales/#{locales[0]}.yml"
File.write(file, File.read(file).gsub(/"#{locales[0]}":/, "\"#{language}\":"))
file = "dashboard/config/locales/#{locales[1]}.yml"
File.write(file, File.read(file).gsub(/"#{language}":/, "\"#{locales[1]}\":"))

# Fix codes in each dashboard locale file
dashboard_categories.each do |dashboard|
file = "dashboard/config/locales/#{dashboard}.#{locales[0]}.yml"
File.write(file, File.read(file).gsub(/"#{locales[0]}":/, "\"#{language}\":"))

file = "dashboard/config/locales/#{dashboard}.#{locales[1]}.yml"
File.write(file, File.read(file).gsub(/"#{language}":/, "\"#{locales[1]}\":"))
end
end
end

def rebuild_blockly_js_files
run_bash_script "apps/node_modules/@code-dot-org/blockly/i18n/codeorg-messages.sh"
Dir.chdir('apps') do
Expand Down
2 changes: 1 addition & 1 deletion dashboard/app/helpers/locale_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def locale
# if(current_user && current_user.locale != current)
# TODO: Set language cookie and reload the page.
# end
current.downcase.to_sym
current.to_sym
end

def locale_dir
Expand Down
12 changes: 6 additions & 6 deletions dashboard/app/models/concerns/text_to_speech.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,27 @@
TTS_BUCKET = 'cdo-tts'

VOICES = {
'en-us': {
'en-US': {
VOICE: 'sharon22k',
SPEED: 180,
SHAPE: 100
},
'es-es': {
'es-ES': {
VOICE: 'ines22k',
SPEED: 180,
SHAPE: 100,
},
'es-mx': {
'es-MX': {
VOICE: 'rosa22k',
SPEED: 180,
SHAPE: 100,
},
'it-it': {
'it-IT': {
VOICE: 'vittorio22k',
SPEED: 180,
SHAPE: 100,
},
'pt-br': {
'pt-BR': {
VOICE: 'marcia22k',
SPEED: 180,
SHAPE: 100,
Expand Down Expand Up @@ -81,7 +81,7 @@ def self.locale_supported?(locale)
def self.localized_voice
# Use localized voice if we have a setting for the current locale;
# default to English otherwise.
loc = TextToSpeech.locale_supported?(I18n.locale) ? I18n.locale : :'en-us'
loc = TextToSpeech.locale_supported?(I18n.locale) ? I18n.locale : :'en-US'
VOICES[loc]
end

Expand Down
7 changes: 3 additions & 4 deletions dashboard/config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,10 @@ class Application < Rails::Application
# By default, config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
config.i18n.enforce_available_locales = false
config.i18n.available_locales = ['en']
config.i18n.available_locales = ['en-US']
config.i18n.fallbacks = {}
config.i18n.default_locale = 'en-us'
locales = YAML.load_file("#{Rails.root}/config/locales.yml")
LOCALES = Hash[locales.map {|k, v| [k.downcase, v.class == String ? v.downcase : v]}]
config.i18n.default_locale = 'en-US'
LOCALES = YAML.load_file("#{Rails.root}/config/locales.yml")
LOCALES.each do |locale, data|
next unless data.is_a? Hash
data.symbolize_keys!
Expand Down
2 changes: 1 addition & 1 deletion dashboard/config/locales/authored_hints.pt-BR.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"pt":
"pt-BR":
data:
authored_hints:
2-3 Artist 1 new_authored_hint:
Expand Down
2 changes: 1 addition & 1 deletion dashboard/config/locales/authored_hints.pt-PT.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"pt-PT":
"pt":
data:
authored_hints:
2-3 Artist 1 new_authored_hint:
Expand Down
2 changes: 1 addition & 1 deletion dashboard/config/locales/authored_hints.zh-CN.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"zh":
"zh-CN":
data:
authored_hints:
2-3 Artist 1 new_authored_hint:
Expand Down
2 changes: 1 addition & 1 deletion dashboard/config/locales/callouts.pt-BR.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"pt":
"pt-BR":
data:
callouts:
2-3 Artist 1 new_callout: []
Expand Down
2 changes: 1 addition & 1 deletion dashboard/config/locales/callouts.pt-PT.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"pt-PT":
"pt":
data:
callouts:
2-3 Artist 1 new_callout: []
Expand Down
2 changes: 1 addition & 1 deletion dashboard/config/locales/callouts.zh-CN.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"zh":
"zh-CN":
data:
callouts:
2-3 Artist 1 new_callout: []
Expand Down
2 changes: 1 addition & 1 deletion dashboard/config/locales/data.pt-BR.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"pt":
"pt-BR":
data:
game:
name:
Expand Down
2 changes: 1 addition & 1 deletion dashboard/config/locales/data.pt-PT.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"pt-PT":
"pt":
data:
game:
name:
Expand Down
2 changes: 1 addition & 1 deletion dashboard/config/locales/data.zh-CN.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"zh":
"zh-CN":
data:
game:
name:
Expand Down
2 changes: 1 addition & 1 deletion dashboard/config/locales/devise.pt-BR.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"pt":
"pt-BR":
devise:
confirmations:
confirmed: Seu endereço de email foi confirmado com sucesso.
Expand Down
2 changes: 1 addition & 1 deletion dashboard/config/locales/devise.pt-PT.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"pt-PT":
"pt":
devise:
confirmations:
confirmed: O teu endereço de e-mail foi confirmado com sucesso.
Expand Down
2 changes: 1 addition & 1 deletion dashboard/config/locales/devise.zh-CN.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"zh":
"zh-CN":
devise:
confirmations:
confirmed: "你的电子邮件地址已验证成功。"
Expand Down
2 changes: 1 addition & 1 deletion dashboard/config/locales/dsls.pt-BR.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"pt":
"pt-BR":
data:
match:
2-3 Big Event Match 1:
Expand Down
2 changes: 1 addition & 1 deletion dashboard/config/locales/dsls.pt-PT.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"pt-PT":
"pt":
data:
match:
2-3 Big Event Match 1:
Expand Down
2 changes: 1 addition & 1 deletion dashboard/config/locales/dsls.zh-TW.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"zh-TW":
"zh":
data:
match:
2-3 Big Event Match 1:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"pt":
"pt-BR":
data:
failure_message_overrides:
Code Studio Puzzle Challenge 1 - Artist_instruction: |-
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"pt-PT":
"pt":
data:
failure_message_overrides:
Code Studio Puzzle Challenge 1 - Artist_instruction: |-
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"zh":
"zh-CN":
data:
failure_message_overrides:
Code Studio Puzzle Challenge 1 - Artist_instruction: |-
Expand Down
2 changes: 1 addition & 1 deletion dashboard/config/locales/instructions.pt-BR.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"pt":
"pt-BR":
data:
instructions:
2-3 Artist 1 new_instruction: Oi, eu sou um artista. Você pode escrever códigos
Expand Down
2 changes: 1 addition & 1 deletion dashboard/config/locales/instructions.pt-PT.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"pt-PT":
"pt":
data:
instructions:
2-3 Artist 1 new_instruction: Oi, eu sou um artista. Você pode escrever códigos
Expand Down
2 changes: 1 addition & 1 deletion dashboard/config/locales/instructions.zh-CN.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"zh":
"zh-CN":
data:
instructions:
2-3 Artist 1 new_instruction: "您好,我是一个艺术家。你写的代码可以让我画任何的东西。 用几个程序模块来让我画一些灰色线条吧。
Expand Down
2 changes: 1 addition & 1 deletion dashboard/config/locales/markdown_instructions.pt-BR.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"pt":
"pt-BR":
data:
markdown_instructions:
pre-assessment survey q25A'_markdown_instruction: |
Expand Down
2 changes: 1 addition & 1 deletion dashboard/config/locales/markdown_instructions.pt-PT.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"pt-PT":
"pt":
data:
markdown_instructions:
pre-assessment survey q25A'_markdown_instruction: |
Expand Down
2 changes: 1 addition & 1 deletion dashboard/config/locales/markdown_instructions.zh-CN.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"zh":
"zh-CN":
data:
markdown_instructions:
pre-assessment survey q25A'_markdown_instruction: |
Expand Down
2 changes: 1 addition & 1 deletion dashboard/config/locales/pt-BR.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"pt":
"pt-BR":
errors:
messages:
not_saved: 'Corrija os seguintes erros:'
Expand Down
2 changes: 1 addition & 1 deletion dashboard/config/locales/pt-PT.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"pt-PT":
"pt":
errors:
messages:
not_saved: 'Por favor, corrige os seguintes erros:'
Expand Down
2 changes: 1 addition & 1 deletion dashboard/config/locales/scripts.pt-BR.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"pt":
"pt-BR":
data:
script:
name:
Expand Down
2 changes: 1 addition & 1 deletion dashboard/config/locales/scripts.pt-PT.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"pt-PT":
"pt":
data:
script:
name:
Expand Down
2 changes: 1 addition & 1 deletion dashboard/config/locales/scripts.zh-CN.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"zh":
"zh-CN":
data:
script:
name:
Expand Down
2 changes: 1 addition & 1 deletion dashboard/config/locales/slides.pt-BR.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"pt":
"pt-BR":
slides:
maze_intro:
1:
Expand Down
2 changes: 1 addition & 1 deletion dashboard/config/locales/slides.pt-PT.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"pt-PT":
"pt":
slides:
maze_intro:
1:
Expand Down
2 changes: 1 addition & 1 deletion dashboard/config/locales/slides.zh-CN.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"zh":
"zh-CN":
slides:
maze_intro:
1:
Expand Down
2 changes: 1 addition & 1 deletion dashboard/config/locales/unplugged.pt-BR.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"pt":
"pt-BR":
data:
unplugged:
Unplug1:
Expand Down
2 changes: 1 addition & 1 deletion dashboard/config/locales/unplugged.pt-PT.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"pt-PT":
"pt":
data:
unplugged:
Unplug1:
Expand Down
2 changes: 1 addition & 1 deletion dashboard/config/locales/unplugged.zh-CN.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"zh":
"zh-CN":
data:
unplugged:
Unplug1:
Expand Down
2 changes: 1 addition & 1 deletion dashboard/config/locales/zh-CN.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"zh":
"zh-CN":
errors:
messages:
not_saved: "请更正以下错误:"
Expand Down
2 changes: 1 addition & 1 deletion dashboard/scripts/update_tts_i18n.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
require_relative('../config/environment')
require 'cdo/properties'

ENABLED_LANGUAGES = [:'es-es', :'it-it', :'pt-br']
ENABLED_LANGUAGES = [:'es-ES', :'it-IT', :'pt-BR']

k1_script_names = [
Script::COURSEA_DRAFT_NAME,
Expand Down
2 changes: 1 addition & 1 deletion dashboard/test/controllers/activities_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def _test_logged_in_milestone(async_activity_writes:)
script_level_id: @script_level.id,
level_id: @script_level.level.id,
user_agent: 'Rails Testing',
locale: :'en-us'
locale: :'en-US'
}],
slogger.records
)
Expand Down
10 changes: 5 additions & 5 deletions dashboard/test/controllers/api_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def make_progress_in_section(script)
expected_response = [
{
"student" => {"id" => @student_1.id, "name" => @student_1.name},
"stage" => "translation missing: en-us.data.script.name.#{script.name}.title",
"stage" => "translation missing: en-US.data.script.name.#{script.name}.title",
"puzzle" => 1,
"question" => "Long assessment 1",
"url" => "http://test.host/s/#{script.name}/stage/1/puzzle/1?section_id=#{@section.id}&user_id=#{@student_1.id}",
Expand Down Expand Up @@ -322,7 +322,7 @@ def make_progress_in_section(script)
# all these are translation missing because we don't actually generate i18n files in tests
expected_response = [
{
"stage" => "translation missing: en-us.data.script.name.#{script.name}.title",
"stage" => "translation missing: en-US.data.script.name.#{script.name}.title",
"levelgroup_results" => [
{
"type" => "text_match",
Expand Down Expand Up @@ -449,7 +449,7 @@ def make_progress_in_section(script)
# all these are translation missing because we don't actually generate i18n files in tests
expected_response = [
{
"stage" => "translation missing: en-us.data.script.name.#{script.name}.title",
"stage" => "translation missing: en-US.data.script.name.#{script.name}.title",
"levelgroup_results" => [
{
"type" => "text_match",
Expand Down Expand Up @@ -1054,7 +1054,7 @@ def make_progress_in_section(script)
script_level_id: script_level.id,
level_id: level.id,
user_agent: 'Rails Testing',
locale: :'en-us'
locale: :'en-US'
}
],
slogger.records
Expand Down Expand Up @@ -1087,7 +1087,7 @@ def make_progress_in_section(script)
script_level_id: script_level.id,
level_id: level.id,
user_agent: 'Rails Testing',
locale: :'en-us'
locale: :'en-US'
}
],
slogger.records
Expand Down
Loading