Skip to content

Commit 31d3996

Browse files
author
Drew Proebstel
committed
state name look up is now language specfic
1 parent 2fa88de commit 31d3996

File tree

3 files changed

+52
-17
lines changed

3 files changed

+52
-17
lines changed

app/services/state_file/state_information_service.rb

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ class << self
4242
end
4343
end
4444

45-
def state_name(state_code)
45+
def state_name(state_code, locale = I18n.locale)
4646
raise InvalidStateCodeError, state_code unless STATES_INFO.key?(state_code)
47-
I18n.t("state_file.state_information_service.#{state_code}.state_name")
47+
I18n.t("state_file.state_information_service.#{state_code}.state_name", locale: locale)
4848
end
4949

5050
def department_of_taxation(state_code)
@@ -96,8 +96,11 @@ def active_state_codes
9696
@_active_state_codes ||= STATES_INFO.keys.map(&:to_s).freeze
9797
end
9898

99-
def state_code_to_name_map
100-
@_state_code_to_name_map ||= active_state_codes.to_h { |state_code, _| [state_code, state_name(state_code)] }.freeze
99+
def state_code_to_name_map(locale = I18n.locale)
100+
@_state_code_to_name_map ||= {}
101+
@_state_code_to_name_map[locale] ||= active_state_codes.to_h do |state_code|
102+
[state_code, state_name(state_code, locale)]
103+
end.freeze
101104
end
102105

103106
def state_intake_classes

app/views/state_file/state_file_pages/about_page.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<%= t(".closed_forever_subheader_html", faq_link: state_faq_path(us_state: 'us')) %>
1010
</div>
1111

12-
<%= link_to "https://pya.fileyourstatetaxes.org/#{I18n.locale}/year_select", class: "button button--primary button--home", id: "firstCta", role: "button", style: "display: flex; justify-content: center; align-items: center; text-align: center;" do %>
12+
<%= link_to "https://pya.fileyourstatetaxes.org/#{I18n.locale}/year_select", class: "button button--primary button--home no-external", id: "firstCta", role: "button", style: "display: flex; justify-content: center; align-items: center; text-align: center;" do %>
1313
<%= t(".download_your_return") %>
1414
<% end %>
1515

spec/services/state_file/state_information_service_spec.rb

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,60 @@
88
end
99

1010
describe ".state_code_to_name_map" do
11-
it "returns a map of all the state codes to state names" do
12-
result = {
13-
"az" => "Arizona",
14-
"md" => "Maryland",
15-
"nc" => "North Carolina",
16-
"nj" => "New Jersey",
17-
"ny" => "New York",
18-
"id" => "Idaho",
19-
}
20-
expect(described_class.state_code_to_name_map).to eq result
11+
it "returns a map of all the state codes to state names in English by default" do
12+
I18n.with_locale(:en) do
13+
result = {
14+
"az" => "Arizona",
15+
"md" => "Maryland",
16+
"nc" => "North Carolina",
17+
"nj" => "New Jersey",
18+
"ny" => "New York",
19+
"id" => "Idaho",
20+
}
21+
22+
expect(described_class.state_code_to_name_map).to eq(result)
23+
end
24+
end
25+
26+
it "is locale aware and returns localized state names for the current locale" do
27+
I18n.with_locale(:es) do
28+
result = {
29+
"az" => I18n.t("state_file.state_information_service.az.state_name"),
30+
"md" => I18n.t("state_file.state_information_service.md.state_name"),
31+
"nc" => I18n.t("state_file.state_information_service.nc.state_name"),
32+
"nj" => I18n.t("state_file.state_information_service.nj.state_name"),
33+
"ny" => I18n.t("state_file.state_information_service.ny.state_name"),
34+
"id" => I18n.t("state_file.state_information_service.id.state_name"),
35+
}
36+
37+
expect(described_class.state_code_to_name_map).to eq(result)
38+
end
2139
end
2240
end
2341

2442
describe ".state_intake_classes" do
2543
it "returns an array of the intake classes" do
26-
expect(described_class.state_intake_classes).to match_array [StateFileAzIntake, StateFileIdIntake, StateFileMdIntake, StateFileNcIntake, StateFileNjIntake, StateFileNyIntake]
44+
expect(described_class.state_intake_classes).to match_array [
45+
StateFileAzIntake,
46+
StateFileIdIntake,
47+
StateFileMdIntake,
48+
StateFileNcIntake,
49+
StateFileNjIntake,
50+
StateFileNyIntake,
51+
]
2752
end
2853
end
2954

3055
describe ".state_intake_class_names" do
3156
it "returns an array of the intake classes as strings" do
32-
expect(described_class.state_intake_class_names).to match_array ["StateFileAzIntake", "StateFileIdIntake", "StateFileMdIntake", "StateFileNcIntake", "StateFileNjIntake", "StateFileNyIntake"]
57+
expect(described_class.state_intake_class_names).to match_array [
58+
"StateFileAzIntake",
59+
"StateFileIdIntake",
60+
"StateFileMdIntake",
61+
"StateFileNcIntake",
62+
"StateFileNjIntake",
63+
"StateFileNyIntake",
64+
]
3365
end
3466
end
3567

0 commit comments

Comments
 (0)