Skip to content

Commit

Permalink
Fixed intl parsing bug when trying to parse non-string entries (#1153)
Browse files Browse the repository at this point in the history
* Check for string
* Number test
* Update for multiple types
  • Loading branch information
sepehr500 authored and justin808 committed Oct 11, 2018
1 parent d484f8f commit 6359a6d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
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

0 comments on commit 6359a6d

Please sign in to comment.