Skip to content

Instantly share code, notes, and snippets.

@lirenyeo
Last active October 5, 2018 04:21
Show Gist options
  • Save lirenyeo/6a885b35b254c0ba584aca30f3798e4d to your computer and use it in GitHub Desktop.
Save lirenyeo/6a885b35b254c0ba584aca30f3798e4d to your computer and use it in GitHub Desktop.
# All translation key-value pair must be have String datatype as key
require 'fileutils'
dir = '/Users/liren/Desktop'
SOURCE_LANG = 'EN'
LANGS = ['ID', 'MS', 'TH', 'ZH']
def translate(file_path, lang)
lines = IO.readlines(file_path).map do |line|
p line
line.gsub(/(.+:\s?['"])(.+)(['"],?)/, '\1[' + lang + '] \2\3')
end
File.open(file_path, 'w') do |file|
file.puts lines
end
end
LANGS.each do |lang|
lang_folder = "#{dir}/#{lang}"
FileUtils.copy_entry "#{dir}/#{SOURCE_LANG}", lang_folder
Dir["#{lang_folder}/*.js"].each do |file|
translate(file, lang)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment