Use blocks to compute src/dst files

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

@ -1,10 +1,15 @@
#!/usr/bin/env ruby #!/usr/bin/env ruby
def lang_mod(lang) def astrid_code_to_getloc_code(lang)
lang.sub("-r", "-") lang.sub("-r", "-")
end 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 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
@ -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/) %x(curl --form file=@#{f} --user #{@user}:#{@password} https://api.getlocalization.com/astrid/api/update-master/)
end end
else else
lang_tmp = lang_mod(lang) lang_tmp = astrid_code_to_getloc_code(lang)
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)
@ -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" 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")
@ -43,10 +48,13 @@ def import(tmp_files, dst_files, lang, android)
%x(tar xzf #{tmp_all} -C #{tmp_all_dir}) %x(tar xzf #{tmp_all} -C #{tmp_all_dir})
# Get all translations # Get all translations
Dir.foreach(tmp_all_dir) do |f| Dir.foreach(tmp_all_dir) do |l|
if (f != "." && f != "..") 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 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 %x(sed -i '' "s/'/\\\\\\'/g" #{file}) if 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]})
@ -56,7 +64,8 @@ def import(tmp_files, dst_files, lang, android)
%x(rm -rf #{tmp_all_dir}) %x(rm -rf #{tmp_all_dir})
%x(rm #{tmp_all}) %x(rm #{tmp_all})
else 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 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]})
@ -81,17 +90,18 @@ def getloc(cmd, platform, lang)
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]}]
src_files = ["translations/strings.xml", "api/res/values/strings.xml"] src_files = Proc.new { |l| ["translations/strings.xml", "api/res/values/strings.xml"] }
else 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 end
when "ios" when "ios"
tmp_files = ["Resources/Localizable.strings"] tmp_files = ["Resources/Localizable.strings"]
lang_tmp = lang if lang == "master" && cmd == "export"
lang_tmp = "en" if lang == "master" src_files = Proc.new { |l| ["Resources/Localizations/en.lproj/Localizable.strings"] }
src_files = ["Resources/Localizations/#{lang_tmp}.lproj/Localizable.strings"] else
src_files = Proc.new { |l| ["Resources/Localizations/#{l}.lproj/Localizable.strings"] }
end
when "web" when "web"
puts "Web not yet supported." puts "Web not yet supported."
return return
@ -103,10 +113,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, src_files, lang, android) export(tmp_files, lang, android, src_files)
when "import" when "import"
puts "Importing #{lang} files" puts "Importing #{lang} files"
import(tmp_files, src_files, lang, android) import(tmp_files, lang, android, 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