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 4 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
2 changes: 1 addition & 1 deletion lib/react_on_rails/locales_to_js.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ 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 # Arrays are not supported by react-intl
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment does not seem appropriate anymore

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vcarel Do you think we should support int and bools as well as strings?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like int and bools are not supported -> https://formatjs.io/guides/message-syntax/

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...I mean by react-intl.
I don't know, see my comment to @justin808 below. I don't feel this is going in the right direction, although my last PR is part of the problem.
The decision is up to both of you.

h[k] = v.gsub("%{", "{")
end
end
Expand Down
2 changes: 2 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,5 @@ en:
hello: "Hello world"
argument: "I am %{age} years old."
day_names: [Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday]
blank:
number: 2
2 changes: 2 additions & 0 deletions spec/react_on_rails/locales_to_js_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ module ReactOnRails
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(default).not_to include("blank:")
expect(default).not_to include("number:")

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