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

Fixed intl parsing bug when trying to parse non-string entries #1153

Merged
merged 5 commits into from
Oct 11, 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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ Changes since last non-beta release.

*Please add entries here for your pull requests that are not yet released.*

#### Fixed
- Fixed bug where intl parsing would fail when trying to parse integers or blank entries. by [sepehr500](https://github.com/sepehr500)


### [11.1.6] - 2018-10-05
#### Fixed
Expand Down
4 changes: 3 additions & 1 deletion lib/react_on_rails/locales_to_js.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,10 @@ 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
elsif v.is_a?(String)
h[k] = v.gsub("%{", "{")
elsif !v.is_a?(Array)
h[k] = v
end
end
end
Expand Down
4 changes: 4 additions & 0 deletions spec/react_on_rails/fixtures/i18n/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@ en:
hello: "Hello world"
argument: "I am %{age} years old."
day_names: [Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday]
blank:
number: 2
bool: true
float: 2.0
6 changes: 5 additions & 1 deletion spec/react_on_rails/locales_to_js_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ module ReactOnRails
expect(translations).to include('{"hello":"Hallo welt"')
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).to include('"argument":{"id":"argument","defaultMessage":"I am {age} years old."}')
expect(default).to include('"blank":{"id":"blank","defaultMessage":null}')
expect(default).to include("number")
expect(default).to include("bool")
expect(default).to include("float")
expect(default).not_to include("day_names:")

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