Skip to content

Commit

Permalink
Symbolize names and freeze values when loading from JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
paarthmadan committed Dec 9, 2021
1 parent 3ae91d3 commit b73ef81
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/i18n/backend/base.rb
Expand Up @@ -253,7 +253,7 @@ def load_yml(filename)
# toplevel keys.
def load_json(filename)
begin
::JSON.parse(File.read(filename))
::JSON.parse(File.read(filename), symbolize_names: true, freeze: true)
rescue TypeError, StandardError => e
raise InvalidLocaleData.new(filename, e.inspect)
end
Expand Down
2 changes: 1 addition & 1 deletion test/backend/simple_test.rb
Expand Up @@ -77,7 +77,7 @@ def setup

test "simple load_json: loads data from a JSON file" do
data = I18n.backend.send(:load_json, "#{locales_dir}/en.json")
assert_equal({ 'en' => { 'foo' => { 'bar' => 'baz' } } }, data)
assert_equal({ :en => { :foo => { :bar => 'baz' } } }, data)
end

test "simple load_translations: loads data from known file formats" do
Expand Down

0 comments on commit b73ef81

Please sign in to comment.