Use blocks to compute src/dst files

pull/14/head
Sam Bosley 12 years ago
parent d901a681d0
commit aab7ad3501

@ -1,10 +1,15 @@
#!/usr/bin/env ruby
def lang_mod(lang)
def astrid_code_to_getloc_code(lang)
lang.sub("-r", "-")
end
def export(tmp_files, src_files, lang, android)
def getloc_code_to_astrid_code(lang)
lang.sub("-", "-r")
end
def export(tmp_files, lang, android, src_files_block)
src_files = src_files_block.call(lang)
for i in 0...tmp_files.length
%x(cp #{src_files[i]} #{tmp_files[i]}) if src_files[i] != tmp_files[i]
end
@ -21,7 +26,7 @@ def export(tmp_files, src_files, lang, android)
%x(curl --form file=@#{f} --user #{@user}:#{@password} https://api.getlocalization.com/astrid/api/update-master/)
end
else
lang_tmp = lang_mod(lang)
lang_tmp = astrid_code_to_getloc_code(lang)
tmp_files.each do |f|
puts "Updating language file #{f}"
name = File.basename(f)
@ -32,7 +37,7 @@ end
def import(tmp_files, dst_files, lang, android)
def import(tmp_files, lang, android, dst_files_block)
if lang == "master"
tmp_dir = File.dirname(tmp_files[0])
tmp_all = File.join(tmp_dir, "all.zip")
@ -43,10 +48,13 @@ def import(tmp_files, dst_files, lang, android)
%x(tar xzf #{tmp_all} -C #{tmp_all_dir})
# Get all translations
Dir.foreach(tmp_all_dir) do |f|
if (f != "." && f != "..")
Dir.foreach(tmp_all_dir) do |l|
if (l != "." && l != "..")
lang_local = getloc_code_to_astrid_code(l)
dst_files = dst_files_block.call(lang_local)
for i in 0...tmp_files.length
file = File.join(tmp_all_dir, f, File.basename(t))
file = File.join(tmp_all_dir, l, File.basename(tmp_files[i]))
%x(sed -i '' "s/'/\\\\\\'/g" #{file}) if android
puts "Moving #{file} to #{dst_files[i]}"
%x(mv #{file} #{dst_files[i]})
@ -56,7 +64,8 @@ def import(tmp_files, dst_files, lang, android)
%x(rm -rf #{tmp_all_dir})
%x(rm #{tmp_all})
else
lang_tmp = lang_mod(lang)
lang_tmp = astrid_code_to_getloc_code(lang)
dst_files = dst_files_block.call(lang)
for i in 0...tmp_files.length
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]})
@ -81,17 +90,18 @@ def getloc(cmd, platform, lang)
tmp_files = ["translations/strings.xml", "translations/strings-api.xml"]
if lang == "master" && cmd == "export"
%x[./bin/catxml astrid/res/values/strings*.xml > #{tmp_files[0]}]
src_files = ["translations/strings.xml", "api/res/values/strings.xml"]
src_files = Proc.new { |l| ["translations/strings.xml", "api/res/values/strings.xml"] }
else
src_files = ["astrid/res/values-#{lang}/strings.xml", "api/res/values-#{lang}/strings.xml"]
src_files = Proc.new { |l| ["astrid/res/values-#{l}/strings.xml", "api/res/values-#{l}/strings.xml"] }
end
when "ios"
tmp_files = ["Resources/Localizable.strings"]
lang_tmp = lang
lang_tmp = "en" if lang == "master"
src_files = ["Resources/Localizations/#{lang_tmp}.lproj/Localizable.strings"]
if lang == "master" && cmd == "export"
src_files = Proc.new { |l| ["Resources/Localizations/en.lproj/Localizable.strings"] }
else
src_files = Proc.new { |l| ["Resources/Localizations/#{l}.lproj/Localizable.strings"] }
end
when "web"
puts "Web not yet supported."
return
@ -103,10 +113,10 @@ def getloc(cmd, platform, lang)
case cmd
when "export"
puts "Exporting #{lang} files"
export(tmp_files, src_files, lang, android)
export(tmp_files, lang, android, src_files)
when "import"
puts "Importing #{lang} files"
import(tmp_files, src_files, lang, android)
import(tmp_files, lang, android, src_files)
else
puts "Command #{cmd} not recognized. Should be one of 'export' or 'import'."
return

Loading…
Cancel
Save