diff --git a/CHANGELOG.md b/CHANGELOG.md index 31919949c..c3b670943 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/react_on_rails/locales_to_js.rb b/lib/react_on_rails/locales_to_js.rb index 6ce37405d..64062a2bd 100644 --- a/lib/react_on_rails/locales_to_js.rb +++ b/lib/react_on_rails/locales_to_js.rb @@ -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 diff --git a/spec/react_on_rails/fixtures/i18n/locales/en.yml b/spec/react_on_rails/fixtures/i18n/locales/en.yml index a9f72ecc7..00b783ede 100644 --- a/spec/react_on_rails/fixtures/i18n/locales/en.yml +++ b/spec/react_on_rails/fixtures/i18n/locales/en.yml @@ -1,2 +1,3 @@ en: hello: "Hello world" + argument: "I am %{age} years old." diff --git a/spec/react_on_rails/locales_to_js_spec.rb b/spec/react_on_rails/locales_to_js_spec.rb index 159caad57..87b63a2cb 100644 --- a/spec/react_on_rails/locales_to_js_spec.rb +++ b/spec/react_on_rails/locales_to_js_spec.rb @@ -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