Class: Applocale::ParseLocalizedResource
- Inherits:
-
Object
- Object
- Applocale::ParseLocalizedResource
- Defined in:
- lib/applocale/Core/ParserStringFile/parse_localized_resource.rb
Instance Method Summary collapse
-
#initialize(skip_error = false, platform, xlsxpath, langpathobj_list, sheetobj_list, rubycode) ⇒ ParseLocalizedResource
constructor
A new instance of ParseLocalizedResource.
- #parse_android ⇒ Object
- #parse_ios ⇒ Object
- #startParse ⇒ Object
- #write_to_xlsx(path, sheetobj, errorlist, content, keylist) ⇒ Object
Constructor Details
#initialize(skip_error = false, platform, xlsxpath, langpathobj_list, sheetobj_list, rubycode) ⇒ ParseLocalizedResource
Returns a new instance of ParseLocalizedResource.
20 21 22 23 24 25 26 27 28 |
# File 'lib/applocale/Core/ParserStringFile/parse_localized_resource.rb', line 20 def initialize(skip_error = false, platform, xlsxpath, langpathobj_list, sheetobj_list, rubycode) @skip_error = skip_error @platform = platform @xlsxpath = xlsxpath @langpathobj_list = langpathobj_list @sheetobj_list = sheetobj_list @injectobj = Applocale::Injection.load(rubycode) startParse() end |
Instance Method Details
#parse_android ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/applocale/Core/ParserStringFile/parse_localized_resource.rb', line 57 def parse_android result = ParseXMLFile.new(@platform, @langpathobj_list, @injectobj) errorlist = result.errorlist content = result.strings_keys keylist = result.keys_list return {:errorlist => errorlist, :content => content, :keylist => keylist} end |
#parse_ios ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/applocale/Core/ParserStringFile/parse_localized_resource.rb', line 49 def parse_ios result = ParseStringsFile.new(@platform, @langpathobj_list, @injectobj) errorlist = result.errorlist content = result.strings_keys keylist = result.keys_list return {:errorlist => errorlist, :content => content, :keylist => keylist} end |
#startParse ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/applocale/Core/ParserStringFile/parse_localized_resource.rb', line 30 def startParse puts "Start to Parse StringFile .... ".green FileUtils.mkdir_p(File.dirname(@xlsxpath)) FileUtils.rm(@xlsxpath) if File.exist? @xlsxpath sheetobj = @sheetobj_list[0] if @platform == Platform::IOS result = self.parse_ios write_to_xlsx(@xlsxpath, sheetobj, result[:errorlist], result[:content], result[:keylist]) elsif @platform == Platform::ANDROID result = self.parse_android write_to_xlsx(@xlsxpath, sheetobj, result[:errorlist], result[:content], result[:keylist]) else ErrorUtil::CommandError.new('Platform not supported').raise end end |
#write_to_xlsx(path, sheetobj, errorlist, content, keylist) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/applocale/Core/ParserStringFile/parse_localized_resource.rb', line 65 def write_to_xlsx(path, sheetobj, errorlist, content, keylist) ErrorUtil::ParseLocalizedError::ParseLocalizedError.raiseArr(errorlist, !@skip_error) puts "Start write to file: \"#{path}\" ...".green workbook = RubyXL::Workbook.new worksheet = workbook.worksheets[0] worksheet.sheet_name = sheetobj.sheetname rowno = 0 keycolno = 0 langcolno_dict = {} sheet_info_obj = sheetobj.obj if sheet_info_obj.is_a? Applocale::Config::SheetInfoByHeader worksheet.add_cell(rowno, keycolno, sheet_info_obj.key_header) langcolno = keycolno + 1 sheet_info_obj.lang_headers.each do |key, header| worksheet.add_cell(rowno, langcolno, header) langcolno_dict[key] = langcolno langcolno += 1 end rowno+=1 elsif sheet_info_obj.is_a? Applocale::Config::SheetInfoByRow rowno = sheet_info_obj.row - 1 keycolno = Applocale::ParseXLSXModule::Helper.collabel_to_colno(sheet_info_obj.key_col) - 1 sheet_info_obj.lang_cols.each do |lang, collabel| langcolno_dict[lang] = Applocale::ParseXLSXModule::Helper.collabel_to_colno(collabel) - 1 end end keylist.each do |key| worksheet.add_cell(rowno, keycolno, key) unless content[key].nil? langcolno_dict.each do |lang, colno| worksheet.add_cell(rowno, colno, content[key][lang][:value]) if !content[key][lang].nil? && !content[key][lang][:value].nil? end end rowno+=1 end workbook.write(path) end |