Skip to content

Commit 6359a6d

Browse files
sepehr500justin808
authored andcommitted
Fixed intl parsing bug when trying to parse non-string entries (#1153)
* Check for string * Number test * Update for multiple types
1 parent d484f8f commit 6359a6d

File tree

4 files changed

+15
-2
lines changed

4 files changed

+15
-2
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ Changes since last non-beta release.
1616

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

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

2023
### [11.1.6] - 2018-10-05
2124
#### Fixed

lib/react_on_rails/locales_to_js.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,10 @@ def flatten(translations)
107107
translations.each_with_object({}) do |(k, v), h|
108108
if v.is_a? Hash
109109
flatten(v).map { |hk, hv| h["#{k}.#{hk}".to_sym] = hv }
110-
elsif !v.is_a? Array # Arrays are not supported by react-intl
110+
elsif v.is_a?(String)
111111
h[k] = v.gsub("%{", "{")
112+
elsif !v.is_a?(Array)
113+
h[k] = v
112114
end
113115
end
114116
end

spec/react_on_rails/fixtures/i18n/locales/en.yml

+4
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,7 @@ en:
22
hello: "Hello world"
33
argument: "I am %{age} years old."
44
day_names: [Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday]
5+
blank:
6+
number: 2
7+
bool: true
8+
float: 2.0

spec/react_on_rails/locales_to_js_spec.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ module ReactOnRails
2929
expect(translations).to include('{"hello":"Hallo welt"')
3030
expect(default).to include("const defaultLocale = 'en';")
3131
expect(default).to include('{"hello":{"id":"hello","defaultMessage":"Hello world"}')
32-
expect(default).to include('"argument":{"id":"argument","defaultMessage":"I am {age} years old."}}')
32+
expect(default).to include('"argument":{"id":"argument","defaultMessage":"I am {age} years old."}')
33+
expect(default).to include('"blank":{"id":"blank","defaultMessage":null}')
34+
expect(default).to include("number")
35+
expect(default).to include("bool")
36+
expect(default).to include("float")
3337
expect(default).not_to include("day_names:")
3438

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

0 commit comments

Comments
 (0)