Better handling of the different language codes that exist between projects

pull/14/head
Sam Bosley 12 years ago
parent 8ee5cd4586
commit 0354701077

@ -7,27 +7,43 @@
# lang: Language code or 'master' # lang: Language code or 'master'
# Converts astrid language codes to GetLocalization language codes (which don't use -r) # Converts astrid language codes to GetLocalization language codes (which don't use -r)
def astrid_code_to_getloc_code(lang) def astrid_code_to_getloc_code(lang, platform)
lang.sub("-r", "-") result = lang.sub("-r", "-")
if platform == "ios"
if lang == "zh-Hans"
result = "zh-TW"
elsif lang == "zh"
result = "zh-CN"
end
end
result
end end
# Inverse of the above function # Inverse of the above function
def getloc_code_to_astrid_code(lang) def getloc_code_to_astrid_code(lang, platform)
lang.sub("-", "-r") result = lang.sub("-", "-r")
if platform == "ios"
if lang == "zh-CN"
result = "zh"
elsif lang == "zh-TW"
result = "zh-Hans"
end
end
result
end end
# Uploads files for the specified language to GetLocalization # Uploads files for the specified language to GetLocalization
# tmp_files (Array): temporary strings files to use # tmp_files (Array): temporary strings files to use
# lang (String): language code # lang (String): language code
# android (Boolean): whether or not this export is for android # platform (String): platform; one of 'android', 'ios', 'web'
# src_files_block (Proc): Block for computing the source file list from the language code # src_files_block (Proc): Block for computing the source file list from the language code
def export(tmp_files, lang, android, src_files_block) def export(tmp_files, lang, platform, src_files_block)
src_files = src_files_block.call(lang) src_files = src_files_block.call(lang)
for i in 0...tmp_files.length for i in 0...tmp_files.length
%x(cp #{src_files[i]} #{tmp_files[i]}) if src_files[i] != tmp_files[i] %x(cp #{src_files[i]} #{tmp_files[i]}) if src_files[i] != tmp_files[i]
end end
if android if platform == "android"
tmp_files.each do |f| tmp_files.each do |f|
%x(sed -i '' "s/\\\\\\'/'/g" #{f}) %x(sed -i '' "s/\\\\\\'/'/g" #{f})
end end
@ -39,7 +55,7 @@ def export(tmp_files, lang, android, src_files_block)
%x(curl --form file=@#{f} --user #{@user}:#{@password} https://api.getlocalization.com/astrid/api/update-master/) %x(curl --form file=@#{f} --user #{@user}:#{@password} https://api.getlocalization.com/astrid/api/update-master/)
end end
else else
lang_tmp = astrid_code_to_getloc_code(lang) lang_tmp = astrid_code_to_getloc_code(lang, platform)
tmp_files.each do |f| tmp_files.each do |f|
puts "Updating language file #{f}" puts "Updating language file #{f}"
name = File.basename(f) name = File.basename(f)
@ -51,9 +67,9 @@ end
# Downloads and imports files for the specified language # Downloads and imports files for the specified language
# tmp_files (Array): temporary strings files to use # tmp_files (Array): temporary strings files to use
# lang (String): language code # lang (String): language code
# android (Boolean): whether or not this import is for android # platform (String): platform; one of 'android', 'ios', or 'web'
# dst_files_block (Proc): Block for computing the destination files list from the language code # dst_files_block (Proc): Block for computing the destination files list from the language code
def import(tmp_files, lang, android, dst_files_block) def import(tmp_files, lang, platform, dst_files_block)
if lang == "master" if lang == "master"
tmp_dir = File.dirname(tmp_files[0]) tmp_dir = File.dirname(tmp_files[0])
tmp_all = File.join(tmp_dir, "all.zip") tmp_all = File.join(tmp_dir, "all.zip")
@ -66,12 +82,12 @@ def import(tmp_files, lang, android, dst_files_block)
# Get all translations # Get all translations
Dir.foreach(tmp_all_dir) do |l| Dir.foreach(tmp_all_dir) do |l|
if (l != "." && l != "..") if (l != "." && l != "..")
lang_local = getloc_code_to_astrid_code(l) lang_local = getloc_code_to_astrid_code(l, platform)
dst_files = dst_files_block.call(lang_local) dst_files = dst_files_block.call(lang_local)
for i in 0...tmp_files.length for i in 0...tmp_files.length
file = File.join(tmp_all_dir, l, File.basename(tmp_files[i])) file = File.join(tmp_all_dir, l, File.basename(tmp_files[i]))
%x(sed -i '' "s/'/\\\\\\'/g" #{file}) if android %x(sed -i '' "s/'/\\\\\\'/g" #{file}) if platform == "android"
puts "Moving #{file} to #{dst_files[i]}" puts "Moving #{file} to #{dst_files[i]}"
%x(mv #{file} #{dst_files[i]}) %x(mv #{file} #{dst_files[i]})
end end
@ -80,12 +96,12 @@ def import(tmp_files, lang, android, dst_files_block)
%x(rm -rf #{tmp_all_dir}) %x(rm -rf #{tmp_all_dir})
%x(rm #{tmp_all}) %x(rm #{tmp_all})
else else
lang_tmp = astrid_code_to_getloc_code(lang) lang_tmp = astrid_code_to_getloc_code(lang, platform)
dst_files = dst_files_block.call(lang) dst_files = dst_files_block.call(lang)
for i in 0...tmp_files.length for i in 0...tmp_files.length
name = File.basename(tmp_files[i]) name = File.basename(tmp_files[i])
%x(curl --user #{@user}:#{@password} https://api.getlocalization.com/astrid/api/translations/file/#{name}/#{lang_tmp}/ -o #{tmp_files[i]}) %x(curl --user #{@user}:#{@password} https://api.getlocalization.com/astrid/api/translations/file/#{name}/#{lang_tmp}/ -o #{tmp_files[i]})
%x(sed -i '' "s/'/\\\\\\'/g" #{tmp_files[i]}) if android %x(sed -i '' "s/'/\\\\\\'/g" #{tmp_files[i]}) if platform == "android"
puts "Moving #{tmp_files[i]} to #{dst_files[i]}" puts "Moving #{tmp_files[i]} to #{dst_files[i]}"
%x(mv #{tmp_files[i]} #{dst_files[i]}) %x(mv #{tmp_files[i]} #{dst_files[i]})
end end
@ -98,13 +114,11 @@ end
# platform (String): Project platform. Must be 'android', 'ios', or 'web' # platform (String): Project platform. Must be 'android', 'ios', or 'web'
# lang (String): Language code. Can also be 'master' to specify master files for export or all languages for import. # lang (String): Language code. Can also be 'master' to specify master files for export or all languages for import.
def getloc(cmd, platform, lang) def getloc(cmd, platform, lang)
android = false
@user = "sbosley" @user = "sbosley"
@password = "ohSed4pe" @password = "ohSed4pe"
case platform case platform
when "android" when "android"
android = true
tmp_files = ["translations/strings.xml", "translations/strings-api.xml"] tmp_files = ["translations/strings.xml", "translations/strings-api.xml"]
if lang == "master" && cmd == "export" if lang == "master" && cmd == "export"
%x[./bin/catxml astrid/res/values/strings*.xml > #{tmp_files[0]}] %x[./bin/catxml astrid/res/values/strings*.xml > #{tmp_files[0]}]
@ -131,10 +145,10 @@ def getloc(cmd, platform, lang)
case cmd case cmd
when "export" when "export"
puts "Exporting #{lang} files" puts "Exporting #{lang} files"
export(tmp_files, lang, android, src_files) export(tmp_files, lang, platform, src_files)
when "import" when "import"
puts "Importing #{lang} files" puts "Importing #{lang} files"
import(tmp_files, lang, android, src_files) import(tmp_files, lang, platform, src_files)
else else
puts "Command #{cmd} not recognized. Should be one of 'export' or 'import'." puts "Command #{cmd} not recognized. Should be one of 'export' or 'import'."
return return

Loading…
Cancel
Save