Skip to content

Commit

Permalink
Ignore Arrays in Rails i18n yml files
Browse files Browse the repository at this point in the history
  • Loading branch information
vcarel committed Aug 10, 2018
1 parent 7de8ce3 commit 397cf44
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ See [Upgrading React on Rails](./docs/basics/upgrading-react-on-rails.md) for mo
## [Unreleased]
Changes since last non-beta release.

- Ignore Arrays in Rails i18n yml files

*Please add entries here for your pull requests that are not yet released.*
### [11.1.1] - 2018-08-09
#### Fixed
Expand Down
2 changes: 2 additions & 0 deletions lib/react_on_rails/locales_to_js.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ def flatten(translations)
translations.each_with_object({}) do |(k, v), h|
if v.is_a? Hash
flatten(v).map { |hk, hv| h["#{k}.#{hk}".to_sym] = hv }
elsif v.is_a? Array
# Arrays are not supported by react-intl
else
h[k] = v.gsub("%{", "{")
end
Expand Down
1 change: 1 addition & 0 deletions spec/react_on_rails/fixtures/i18n/locales/en.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
en:
hello: "Hello world"
argument: "I am %{age} years old."
day_names: [Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday]
1 change: 1 addition & 0 deletions spec/react_on_rails/locales_to_js_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ module ReactOnRails
expect(default).to include("const defaultLocale = 'en';")
expect(default).to include('{"hello":{"id":"hello","defaultMessage":"Hello world"}')
expect(default).to include('"argument":{"id":"argument","defaultMessage":"I am {age} years old."}}')
expect(default).not_to include('day_names:')

expect(File.mtime(translations_path)).to be >= File.mtime(en_path)
end
Expand Down

0 comments on commit 397cf44

Please sign in to comment.