Class: Applocale::ConvertToStrFile
- Inherits:
-
Object
- Object
- Applocale::ConvertToStrFile
- Defined in:
- lib/applocale/Core/convert_to_localefile.rb
Class Method Summary collapse
- .add_escape(platform, lang, key, content, injectObj) ⇒ Object
- .convert(platform, lang_path_list, sheetcontent_list, rubycode) ⇒ Object
- .convert_to_stringfile(platform, langpath_obj, sheetcontent_list, injectObj) ⇒ Object
- .convert_to_xml(platform, langpath_obj, sheetcontent_list, injectObj) ⇒ Object
Class Method Details
.add_escape(platform, lang, key, content, injectObj) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/applocale/Core/convert_to_localefile.rb', line 65 def self.add_escape(platform, lang, key, content, injectObj) value = content if injectObj.has_before_convent_to_locale value = injectObj.load_before_convent_to_locale(lang.to_s, key, value) end if injectObj.has_convent_to_locale value = injectObj.load_convent_to_locale(lang.to_s, key, value) else value = ContentUtil.add_escape(platform, value) end if injectObj.has_after_convent_to_locale value = injectObj.load_after_convent_to_locale(lang.to_s, key, value) end return value end |
.convert(platform, lang_path_list, sheetcontent_list, rubycode) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/applocale/Core/convert_to_localefile.rb', line 12 def self.convert(platform, lang_path_list, sheetcontent_list, rubycode) injectObj = Applocale::Injection.load(rubycode) lang_path_list.each do |langpath_obj| puts "Start to convert to string file for [\"#{langpath_obj.lang}\"] #{langpath_obj.filepath}...".green if platform == Platform::IOS self.convert_to_stringfile(platform, langpath_obj, sheetcontent_list, injectObj) elsif platform == Platform::ANDROID self.convert_to_xml(platform, langpath_obj, sheetcontent_list, injectObj) end end puts 'Convert Finished !!!'.green end |
.convert_to_stringfile(platform, langpath_obj, sheetcontent_list, injectObj) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/applocale/Core/convert_to_localefile.rb', line 27 def self.convert_to_stringfile(platform, langpath_obj, sheetcontent_list, injectObj) FileUtils.mkdir_p(File.dirname(langpath_obj.filepath)) target = open(langpath_obj.filepath, 'w') sheetcontent_list.each do |sheetcontent| contentlist = sheetcontent.get_rowInfo_sortby_key next if contentlist.length <= 0 target.puts('/*******************************') target.puts(" * #{sheetcontent.comment}") target.puts(' *******************************/') target.puts('') contentlist.each do |rowinfo| content = rowinfo.content_dict[langpath_obj.lang] value = self.add_escape(platform, langpath_obj.lang, rowinfo.key_str, content, injectObj) target.puts("\"#{rowinfo.key_str}\" = \"#{value}\";") end target.puts('') end target.close end |
.convert_to_xml(platform, langpath_obj, sheetcontent_list, injectObj) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/applocale/Core/convert_to_localefile.rb', line 47 def self.convert_to_xml(platform, langpath_obj, sheetcontent_list, injectObj) FileUtils.mkdir_p(File.dirname(langpath_obj.filepath)) target = open(langpath_obj.filepath, 'w') target.puts('<resources>') sheetcontent_list.each do |sheetcontent| target.puts(" <!-- #{sheetcontent.comment} -->") contentlist = sheetcontent.get_rowInfo_sortby_key contentlist.each do |rowinfo| content = rowinfo.content_dict[langpath_obj.lang] value = self.add_escape(platform, langpath_obj.lang, rowinfo.key_str, content, injectObj) target.puts(" <string name=\"#{rowinfo.key_str}\">#{value}</string>") end target.puts('') end target.puts('</resources>') target.close end |