Skip to content

Commit

Permalink
FormatJS i18n argument parsing (#1046)
Browse files Browse the repository at this point in the history
* Fixed i18n parsing
  • Loading branch information
sepehr500 authored and justin808 committed Mar 23, 2018
1 parent 9121184 commit a7ca9b3
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ Contributors: please follow the recommendations outlined at [keepachangelog.com]
## [Unreleased]
Changes since last non-beta release.

#### Fixed
- Changed i18n parsing to convert ruby i18n argument syntax into FormatJS argument syntax. by [sepehr500](https://github.com/sepehr500)

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

### [10.1.3] - 2018-02-28
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 @@ -108,7 +108,7 @@ def flatten(translations)
if v.is_a? Hash
flatten(v).map { |hk, hv| h["#{k}.#{hk}".to_sym] = hv }
else
h[k] = v
h[k] = v.gsub("%{", "{")
end
end
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,2 +1,3 @@
en:
hello: "Hello world"
argument: "I am %{age} years old."
3 changes: 2 additions & 1 deletion spec/react_on_rails/locales_to_js_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ module ReactOnRails
expect(translations).to include('{"hello":"Hello world"')
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('{"hello":{"id":"hello","defaultMessage":"Hello world"}')
expect(default).to include('"argument":{"id":"argument","defaultMessage":"I am {age} years old."}}')

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

0 comments on commit a7ca9b3

Please sign in to comment.