Last active
October 5, 2018 04:21
-
-
Save lirenyeo/6a885b35b254c0ba584aca30f3798e4d to your computer and use it in GitHub Desktop.
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 characters
| # 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