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

Remove harcoded "Login.gov" and switch to interpolation #10580

Merged
merged 1 commit into from
May 9, 2024
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
2 changes: 1 addition & 1 deletion app/views/idv/mail_only_warning/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</p>
<span><%= t('vendor_outage.alerts.pinpoint.idv.options_prompt') %></span>
<ul class="margin-bottom-5">
<% t('vendor_outage.alerts.pinpoint.idv.options_html', status_page_url: StatusPage.base_url).each do | option | %>
<% t('vendor_outage.alerts.pinpoint.idv.options_html', app_name: APP_NAME).each do |option| %>
<li>
<%= option %>
</li>
Expand Down
2 changes: 1 addition & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1905,7 +1905,7 @@ vendor_outage.alerts.pinpoint.idv.header: We are working to resolve an error
vendor_outage.alerts.pinpoint.idv.message_html: '%{sp_name_html} needs to make sure you are you — not someone pretending to be you.'
vendor_outage.alerts.pinpoint.idv.options_html:
- Continue now and verify by mail, which takes <strong>5 to 10 days</strong>.
- Exit Login.gov and try again later.
- Exit %{app_name} and try again later.
vendor_outage.alerts.pinpoint.idv.options_prompt: 'You can:'
vendor_outage.alerts.pinpoint.idv.status_page_html: Unfortunately, we’re having technical difficulties right now. %{link_html} to learn when the error is resolved.
vendor_outage.alerts.pinpoint.idv.status_page_link: Get updates on our status page
Expand Down
2 changes: 1 addition & 1 deletion config/locales/es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1902,7 +1902,7 @@ vendor_outage.alerts.pinpoint.idv.header: Estamos trabajando para corregir un er
vendor_outage.alerts.pinpoint.idv.message_html: '%{sp_name_html} necesita asegurarse de que se trata de usted y no de alguien que se hace pasar por usted.'
vendor_outage.alerts.pinpoint.idv.options_html:
- Continuar ahora y verificar por correo, lo cual tarda entre <strong>5 y 10 días</strong>.
- Salir de Login.gov e inténtelo de nuevo más tarde.
- Salir de %{app_name} e inténtelo de nuevo más tarde.
vendor_outage.alerts.pinpoint.idv.options_prompt: 'Usted puede:'
vendor_outage.alerts.pinpoint.idv.status_page_html: Lamentablemente, estamos teniendo problemas técnicos. %{link_html} para saber cuando se haya resuelto el error.
vendor_outage.alerts.pinpoint.idv.status_page_link: Obtenga las actualizaciones en nuestra página de estado
Expand Down
2 changes: 1 addition & 1 deletion config/locales/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1906,7 +1906,7 @@ vendor_outage.alerts.pinpoint.idv.header: Nous travaillons à la résolution d
vendor_outage.alerts.pinpoint.idv.message_html: '%{sp_name_html} doit s’assurer qu’il s’agit bien de vous, et non de quelqu’un qui se fait passer pour vous.'
vendor_outage.alerts.pinpoint.idv.options_html:
- Continuer maintenant et effectuer la vérification par courrier, qui nécessite <strong>5 à 10 jours</strong>.
- Quitter Login.gov.
- Quitter %{app_name}.
vendor_outage.alerts.pinpoint.idv.options_prompt: 'Vous pouvez :'
vendor_outage.alerts.pinpoint.idv.status_page_html: Malheureusement, nous rencontrons actuellement des difficultés techniques. %{link_html} pour savoir quand l’erreur est résolue.
vendor_outage.alerts.pinpoint.idv.status_page_link: Obtenir les dernières informations sur notre page d’état des systèmes.
Expand Down
2 changes: 1 addition & 1 deletion config/locales/zh.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1909,7 +1909,7 @@ vendor_outage.alerts.pinpoint.idv.header: 我们正在争取解决错误。
vendor_outage.alerts.pinpoint.idv.message_html: '%{sp_name_html}需要确保你是你,而不是别人冒充你。'
vendor_outage.alerts.pinpoint.idv.options_html:
- 现在继续并通过普通邮件验证,这需要<strong>5 到 10 天</strong>。
- 退出 Login.gov,稍后再试。
- 退出 %{app_name},稍后再试。
vendor_outage.alerts.pinpoint.idv.options_prompt: 你可以:
vendor_outage.alerts.pinpoint.idv.status_page_html: 遗憾的是,我们目前遇到技术困难。到 %{link_html} 了解错误何时能解决。
vendor_outage.alerts.pinpoint.idv.status_page_link: 在我们的状态页面获得最新信息。
Expand Down
101 changes: 54 additions & 47 deletions spec/i18n_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -340,16 +340,18 @@ def allowed_untranslated_key?(locale, key)

root_dir = File.expand_path(File.join(File.dirname(__FILE__), '../'))

Dir[File.join(root_dir, '/config/locales/**')].sort.each do |group_path|
([File.join(root_dir, '/config/locales')] + Dir[File.join(root_dir, '/config/locales/**')]).
sort.each do |group_path|
i18n_group = group_path.sub("#{root_dir}/", '')

describe i18n_group do
it 'has HTML inside at least one locale string for all keys with .html or _html ' do
combined = Hash.new { |h, k| h[k] = {} }

Dir["#{group_path}/**.yml"].each do |file|
locale, data = YAML.load_file(file).first
flatten_hash(data).each do |key, str|
locale = I18nFlatYmlBackend.locale(file)
data = YAML.load_file(file)
flatten_hash(data, flatten_arrays: false).each do |key, str|
combined[key][locale] = str
end
end
Expand All @@ -363,65 +365,65 @@ def allowed_untranslated_key?(locale, key)
expect(bad_keys).to be_empty
end
end
end

Dir["#{group_path}/*.yml"].each do |full_path|
i18n_file = full_path.sub("#{root_dir}/", '')
locale = File.basename(full_path, '.yml').to_sym
Dir[File.join(root_dir, '/config/locales/**/*.yml')].sort.each do |full_path|
i18n_file = full_path.sub("#{root_dir}/", '')
locale = File.basename(full_path, '.yml').to_sym

describe i18n_file do
let(:flattened_yaml_data) { flatten_hash(YAML.load_file(full_path)) }
describe i18n_file do
let(:flattened_yaml_data) { flatten_hash(YAML.load_file(full_path)) }

# Transliteration includes special characters by definition, so it could fail checks below
if !full_path.match?(%(/config/locales/transliterate/))
it 'has only lower_snake_case keys' do
keys = flattened_yaml_data.keys
# Transliteration includes special characters by definition, so it could fail checks below
if !full_path.match?(%(/config/locales/transliterate/))
it 'has only lower_snake_case keys' do
keys = flattened_yaml_data.keys

bad_keys = keys.reject { |key| key =~ /^[a-z0-9_.]+$/ }
expect(bad_keys).to be_empty
end
bad_keys = keys.reject { |key| key =~ /^[a-z0-9_.]+$/ }
expect(bad_keys).to be_empty
end
end

it 'has correctly-formatted interpolation values' do
bad_keys = flattened_yaml_data.select do |_key, value|
next unless value.is_a?(String)

interpolation_names = value.scan(/%\{([^}]+)\}/).flatten
it 'has correctly-formatted interpolation values' do
bad_keys = flattened_yaml_data.select do |_key, value|
next unless value.is_a?(String)

interpolation_names.any? { |name| name.downcase != name }
end
interpolation_names = value.scan(/%\{([^}]+)\}/).flatten

expect(bad_keys).to be_empty
interpolation_names.any? { |name| name.downcase != name }
end

it 'does not contain any translations expecting legacy fallback behavior' do
bad_keys = flattened_yaml_data.select do |_key, value|
value.include?('NOT TRANSLATED YET')
end
expect(bad_keys).to be_empty
end

expect(bad_keys).to be_empty
it 'does not contain any translations expecting legacy fallback behavior' do
bad_keys = flattened_yaml_data.select do |_key, value|
value.include?('NOT TRANSLATED YET')
end

it 'does not contain any translations that hardcode APP_NAME' do
bad_keys = flattened_yaml_data.select do |_key, value|
value.include?(APP_NAME)
end
expect(bad_keys).to be_empty
end

expect(bad_keys).to be_empty
it 'does not contain any translations that hardcode APP_NAME' do
bad_keys = flattened_yaml_data.select do |_key, value|
value.include?(APP_NAME)
end

it 'does not contain content from another language' do
flattened_yaml_data.each do |key, value|
other_locales = LOCALE_SPECIFIC_CONTENT.keys - [locale]
expect(value).not_to match(
Regexp.union(*LOCALE_SPECIFIC_CONTENT.slice(*other_locales).values),
)
end
expect(bad_keys).to be_empty
end

it 'does not contain content from another language' do
flattened_yaml_data.each do |key, value|
other_locales = LOCALE_SPECIFIC_CONTENT.keys - [locale]
expect(value).not_to match(
Regexp.union(*LOCALE_SPECIFIC_CONTENT.slice(*other_locales).values),
)
end
end

it 'does not contain common misspellings', if: COMMONLY_MISSPELLED_WORDS.key?(locale) do
flattened_yaml_data.each do |key, value|
expect(value).not_to match(COMMONLY_MISSPELLED_WORDS[locale])
end
it 'does not contain common misspellings', if: COMMONLY_MISSPELLED_WORDS.key?(locale) do
flattened_yaml_data.each do |key, value|
expect(value).not_to match(COMMONLY_MISSPELLED_WORDS[locale])
end
end
end
Expand Down Expand Up @@ -452,13 +454,18 @@ def extract_interpolation_arguments(translation)
map(&:compact).map(&:first).to_set
end

def flatten_hash(hash, parent_keys: [], out_hash: {}, &block)
def flatten_hash(hash, flatten_arrays: true, parent_keys: [], out_hash: {})
hash.each do |key, value|
if value.is_a?(Hash)
flatten_hash(value, parent_keys: parent_keys + [key], out_hash: out_hash, &block)
flatten_hash(value, flatten_arrays:, parent_keys: parent_keys + [key], out_hash:)
elsif value.is_a?(Array) && flatten_arrays
value.each_with_index do |item, idx|
flat_key = [*parent_keys, key, idx.to_s].join('.')
out_hash[flat_key] = item if item
end
else
flat_key = [*parent_keys, key].join('.')
out_hash[flat_key] = value
out_hash[flat_key] = value if value
end
end

Expand Down
16 changes: 16 additions & 0 deletions spec/views/idv/mail_only_warning/show.html.erb_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
require 'rails_helper'

RSpec.describe 'idv/mail_only_warning/show.html.erb' do
before do
allow(view).to receive(:step_indicator_steps).and_return([])
allow(view).to receive(:current_sp).and_return(nil)

allow(view).to receive(:exit_url).and_return('/exit_url')
end

it 'lists options with correct interpolation' do
render

expect(rendered).to include(APP_NAME)
end
end