Last active
September 4, 2018 11:25
-
-
Save aryondev/3bcc4df552da8d0686c7bc3fe24ede5d to your computer and use it in GitHub Desktop.
Revisions
-
aryondev revised this gist
Sep 4, 2018 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,9 +7,9 @@ parse_hash = lambda do |key, value| if value.is_a?(Hash) { key => value.map { |k,v| parse_hash.call(k,v) } }.reduce({}, &:merge) else { key => translator.translate(value, from: 'en', to: 'ru') } end end -
aryondev created this gist
Sep 4, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,18 @@ require 'json' require 'bing_translator' translator = BingTranslator.new('COGNITIVE_SUBSCRIPTION_KEY') content = File.read('content.json') json = JSON.parse(content) parse_hash = lambda do |key, value| if value.is_a?(Hash) { key => value.map { |k,v| parse_hash(k,v) } }.reduce({}, &:merge) else { key => translator.translate(value) } end end new_json = json.map do |key, value| new_json[key] = parse_hash.call(value) end.reduce({}, &:merge)