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

Display language name or language key #2949

Merged
merged 7 commits into from
Oct 10, 2018
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
5 changes: 1 addition & 4 deletions app/helpers/locales_helper.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
module LocalesHelper

def name_for_locale(locale)
default = I18n.t("locale", locale: locale)
I18n.backend.translate(locale, "i18n.language.name", default: default)
rescue
nil
I18n.t("i18n.language.name", locale: locale, fallback: false, default: locale.to_s)
end

end
1 change: 1 addition & 0 deletions config/i18n-tasks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ data:
- config/locales/%{locale}/images.yml
- config/locales/%{locale}/guides.yml
- config/locales/%{locale}/user_groups.yml
- config/locales/%{locale}/i18n.yml

# Locale files to write new keys to, based on a list of key pattern => file rules. Matched from top to bottom:
# `i18n-tasks normalize -p` will force move the keys according to these rules
Expand Down
1 change: 0 additions & 1 deletion config/locales/en/general.yml
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,6 @@ en:
text_sign_in: login
text_sign_up: sign up
title: How I can comment this document?
locale: English
notifications:
index:
empty_notifications: You don't have new notifications.
Expand Down
4 changes: 4 additions & 0 deletions config/locales/en/i18n.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
en:
i18n:
language:
name: "English"
1 change: 0 additions & 1 deletion config/locales/es/general.yml
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,6 @@ es:
text_sign_in: iniciar sesión
text_sign_up: registrarte
title: '¿Cómo puedo comentar este documento?'
locale: Español
notifications:
index:
empty_notifications: No tienes notificaciones nuevas.
Expand Down
4 changes: 4 additions & 0 deletions config/locales/es/i18n.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
es:
i18n:
language:
name: "Español"
1 change: 0 additions & 1 deletion config/locales/fr/general.yml
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,6 @@ fr:
open_gov: Gouvernement ouvert
proposals: Propositions
spending_proposals: Propositions de dépense
locale: Français
mailers:
comment:
hi: Bonjour
Expand Down
4 changes: 4 additions & 0 deletions config/locales/fr/i18n.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fr:
i18n:
language:
name: "Français"
1 change: 0 additions & 1 deletion config/locales/he/general.yml
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ he:
poll_questions: הצבעות
budgets: מימון השתתפותי
spending_proposals: הצעות להוצאת כספים
locale: עברית
notifications:
index:
empty_notifications: אין לך תגובות חדשות
Expand Down
4 changes: 4 additions & 0 deletions config/locales/he/i18n.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
he:
i18n:
language:
name: "עברית"
1 change: 0 additions & 1 deletion config/locales/it/general.yml
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,6 @@ it:
text_sign_in: ""
text_sign_up: ""
title: ""
locale: ""
notifications:
index:
comments_on:
Expand Down
1 change: 0 additions & 1 deletion config/locales/nl/general.yml
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@ nl:
text_sign_in: log in
text_sign_up: registreer
title: Hoe kan ik reageren?
locale: Nederlands
notifications:
index:
comments_on:
Expand Down
4 changes: 4 additions & 0 deletions config/locales/nl/i18n.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
nl:
i18n:
language:
name: "Nederlands"
4 changes: 0 additions & 4 deletions config/locales/pt-BR/general.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
---
pt-BR:
i18n:
language:
name: Português
account:
show:
change_credentials_link: Alterar meus dados pessoais
Expand Down Expand Up @@ -879,7 +876,6 @@ pt-BR:
open_gov: Governo aberto
proposals: Propostas
spending_proposals: Propostas de despesas
locale: Português brasileiro
mailers:
comment:
hi: Olá
Expand Down
4 changes: 4 additions & 0 deletions config/locales/pt-BR/i18n.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pt-BR:
i18n:
language:
name: "Português brasileiro"
1 change: 0 additions & 1 deletion config/locales/val/general.yml
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,6 @@ val:
text_sign_in: iniciar sessió
text_sign_up: registrar-te
title: Com puc comentar aquest document?
locale: Valencià
notifications:
index:
empty_notifications: No tens noves notificacions.
Expand Down
4 changes: 4 additions & 0 deletions config/locales/val/i18n.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
val:
i18n:
language:
name: "Valencià"
27 changes: 27 additions & 0 deletions spec/features/localization_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,31 @@
expect(page).not_to have_content('Language')
expect(page).not_to have_css('div.locale')
end

context "Missing language names" do

let!(:default_enforce) { I18n.enforce_available_locales }
let!(:default_locales) { I18n.available_locales.dup }

before do
I18n.enforce_available_locales = false
I18n.available_locales = default_locales + [:wl]
I18n.locale = :wl
end

after do
I18n.enforce_available_locales = default_enforce
I18n.available_locales = default_locales
I18n.locale = I18n.default_locale
end

scenario 'Available locales without language translation display locale key' do
visit '/'

within('.locale-form .js-location-changer') do
expect(page).to have_content 'wl'
end
end

end
end
20 changes: 10 additions & 10 deletions spec/features/site_customization/custom_pages_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@

scenario "Listed in more information page" do
custom_page = create(:site_customization_page, :published,
slug: "another-slug",
slug: "another-slug",
title_en: "Another custom page",
subtitle_en: "Subtitle for custom page",
more_info_flag: true
Expand Down Expand Up @@ -136,10 +136,10 @@
expect(page).to have_content("Subtitle for custom page")
end
end
end
end

context "Translation" do

let(:custom_page) { create(:site_customization_page, :published,
slug: "example-page",
title_en: "Title in English",
Expand All @@ -148,7 +148,7 @@
subtitle_es: "Subtitulo en Español",
content_en: "Content in English",
content_es: "Contenido en Español"
) }
) }

background do
admin = create(:administrator)
Expand All @@ -162,19 +162,19 @@
scenario "Add a translation in Português", :js do
visit @edit_page_url

select "Português", from: "translation_locale"
select "Português brasileiro", from: "translation_locale"
fill_in 'site_customization_page_title_pt_br', with: 'Titulo em Português'

click_button 'Update Custom page'
expect(page).to have_content "Page updated successfully"

visit @edit_page_url
expect(page).to have_field('site_customization_page_title_en', with: 'Title in English')

click_link "Español"
expect(page).to have_field('site_customization_page_title_es', with: 'Titulo en Español')

click_link "Português"
click_link "Português brasileiro"
expect(page).to have_field('site_customization_page_title_pt_br', with: 'Titulo em Português')
end

Expand All @@ -190,11 +190,11 @@
visit custom_page.url

select('English', from: 'locale-switcher')

expect(page).to have_content("Title in English")

select('Español', from: 'locale-switcher')

expect(page).to have_content("Titulo correcta en Español")
end

Expand Down
4 changes: 2 additions & 2 deletions spec/features/translations/poll_question_answers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@
scenario "Add a translation for a locale with non-underscored name", :js do
visit @edit_answer_url

select('Português', from: 'translation_locale')
select('Português brasileiro', from: 'translation_locale')
fill_in_ckeditor 'poll_question_answer_description_pt_br', with: 'resposta em Português'
click_button 'Save'

select('Português', from: 'locale-switcher')
select('Português brasileiro', from: 'locale-switcher')
expect(page).to have_content("resposta em Português")
end

Expand Down
32 changes: 32 additions & 0 deletions spec/helpers/locales_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require 'rails_helper'

describe LocalesHelper do

context "Language names" do

let!(:default_enforce) { I18n.enforce_available_locales }

before do
I18n.enforce_available_locales = false
end

after do
I18n.backend.reload!
I18n.enforce_available_locales = default_enforce
end

it "returns the language name in i18n.language.name translation" do
keys = { language: {
name: "World Language" }}

I18n.backend.store_translations(:wl, { i18n: keys })

expect(name_for_locale(:wl)).to eq("World Language")
end

it "retuns the locale key if i18n.language.name translation is not found" do
expect(name_for_locale(:wl)).to eq("wl")
end

end
end
4 changes: 2 additions & 2 deletions spec/shared/features/translatable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,14 @@
visit path
field = fields.sample

select "Português", from: "translation_locale"
select "Português brasileiro", from: "translation_locale"
fill_in field_for(field, :pt_br), with: text_for(field, :"pt-BR")

click_button update_button_text

visit path

select('Português', from: 'locale-switcher')
select('Português brasileiro', from: 'locale-switcher')

expect(page).to have_field(field_for(field, :pt_br), with: text_for(field, :"pt-BR"))
end
Expand Down