lib/LocalizationSmartcat.rb in pixab-1.7.2 vs lib/LocalizationSmartcat.rb in pixab-1.7.3

- old
+ new

@@ -12,10 +12,11 @@ USERNAME = '4c8b26ac-ff12-427f-a460-afaacbb3fa3c' PASSWORD = '6_nDd3whcOZQHv5dPAusbq5Wmfl' Localization_FILE_NAME = 'Localization.zip' Project_AirBrush = '6cd2db15-6325-43ae-9087-f78aca9bec9a' + Project_AirBrushVideo = '16cbeffd-bb6e-46e8-a32e-9c79d23a796f' attr_accessor :projects, :tags, :platform, :collections def initialize() @projects = Project_AirBrush @@ -32,10 +33,18 @@ @collections = 'AirBrush' when '--ab-iOS' @platform = 'iOS' @tags = 'iOS' @collections = 'AirBrush' + when '--abv-iOS' + @projects = Project_AirBrushVideo + @platform = 'iOS' + @tags = 'iOS' + when '--abv-android' + @projects = Project_AirBrushVideo + @platform = 'android' + @tags = 'android' end end commands.each_index do |index| command = commands[index] @@ -81,21 +90,11 @@ return response.body end # 第二步:循环尝试下载ZIP文件 - def download_zip_file_with_retry(download_url, export_id, max_retries=30) - # 加载动画字符 - spinner = Enumerator.new do |e| - loop do - e.yield '|' - e.yield '/' - e.yield '-' - e.yield '\\' - end - end - + def download_zip_file_with_retry(download_url, export_id, max_retries=60) retries = 0 while retries < max_retries uri = URI("#{download_url}/#{export_id}") request = Net::HTTP::Get.new(uri) request.basic_auth(USERNAME,PASSWORD) @@ -106,17 +105,15 @@ if response.code == "200" File.open(Localization_FILE_NAME, "wb") { |file| file.write(response.body) } return true else - # 等待1秒后重试 - # 打印动画字符 - print "\r#{spinner.next}" - sleep 0.5 - print "\r#{spinner.next}" - sleep 0.5 retries += 1 + dots = '.' * retries + print "\r#{dots}" + # 等待1秒后重试 + sleep 1 end end puts "Failed to download after #{max_retries} retries. Export ID: #{export_id}" return false @@ -142,14 +139,16 @@ next end f_path = extract_localization_file_path(f.name) FileUtils.mkdir_p(File.dirname(f_path)) content = f.get_input_stream.read - localization_content = content.gsub(/=\s*".*";/) do |match| - match.gsub('%s', '%@') + if projects == Project_AirBrush + content = content.gsub(/=\s*".*";/) do |match| + match.gsub('%s', '%@') + end end - File.write(f_path, localization_content) + File.write(f_path, content) end end def unzip_file_android(zip_file) zip_file.each do |f| @@ -181,11 +180,15 @@ if !platform.nil? format = nil template = nil if platform == 'android' format = 'android-xml' - template = '{LOCALE:ANDROID}/strings_ph.xml' + if projects == Project_AirBrush + template = '{LOCALE:ANDROID}/strings_ph.xml' + else + template = '{LOCALE:ANDROID}/strings.xml' + end else format = 'ios-strings' template = '{LOCALE:IOS}.lproj/Localizable.strings' end export_params['format'] = format @@ -198,42 +201,78 @@ return export_params end def extract_localization_file_path(zip_file_path) - if platform.nil? || platform != 'android' - return zip_file_path - end + case projects + when Project_AirBrush + if platform.nil? || platform != 'android' + return zip_file_path + end - - path = File.dirname(zip_file_path) - localization = '' - case path - when 'en' + path = File.dirname(zip_file_path) localization = '' - when 'fr' - localization = '-fr-rFR' - when 'ru' - localization = '-ru-rRU' - when 'zh-rHans' - localization = '-zh-rCN' - when 'tr' - localization = '-tr-rTR' - when 'pt-rBR' - localization = '-pt' - else - localization = "-#{path}" + case path + when 'en' + localization = '' + when 'fr' + localization = '-fr-rFR' + when 'ru' + localization = '-ru-rRU' + when 'zh-rHans' + localization = '-zh-rCN' + when 'tr' + localization = '-tr-rTR' + when 'pt-rBR' + localization = '-pt' + else + localization = "-#{path}" + end + return "values#{localization}/#{File.basename(zip_file_path)}" + + when Project_AirBrushVideo + if platform.nil? + return zip_file_path + end + + case platform + when 'android' + path = File.dirname(zip_file_path) + localization = '' + case path + when 'en' + localization = '' + when 'zh-rHans' + localization = '-zh-rCN' + when 'zh-rHant' + localization = '-zh-rHK' + else + localization = "-#{path}" + end + return "values#{localization}/#{File.basename(zip_file_path)}" + when 'iOS' + path = File.dirname(zip_file_path) + localization = zip_file_path + case path + when 'pt-PT.lproj' + localization = File.join('pt.lproj', File.basename(zip_file_path)) + end + return localization + end end - return "values#{localization}/#{File.basename(zip_file_path)}" + end def is_ignored_file_path(file_path) - if platform != 'android' - return false + case projects + when Project_AirBrush + return false unless platform == 'android' + + path = File.dirname(file_path) + return path == 'zh-rHant' ? true : false end - path = File.dirname(file_path) - return path == 'zh-rHant' ? true : false + return false end end end \ No newline at end of file