applocale 0.3.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,7 +3,6 @@ require File.expand_path('../../../Util/platform.rb', __FILE__)
3
3
  require File.expand_path('../../ParseXLSX/parse_xlsx_module', __FILE__)
4
4
  require File.expand_path('../parse_strings_file', __FILE__)
5
5
  require File.expand_path('../parse_xml_file', __FILE__)
6
- require File.expand_path('../../../Util/injection.rb', __FILE__)
7
6
 
8
7
  require 'rubyXL'
9
8
  require 'colorize'
@@ -15,15 +14,15 @@ module Applocale
15
14
  @xlsxpath
16
15
  @langpathobj_list
17
16
  @sheetobj_list
18
- @injectobj
17
+ @convert_file
19
18
 
20
- def initialize(skip_error = false, platform, xlsxpath, langpathobj_list, sheetobj_list, rubycode)
19
+ def initialize(skip_error = false, platform, xlsxpath, langpathobj_list, sheetobj_list, convert_file)
21
20
  @skip_error = skip_error
22
21
  @platform = platform
23
22
  @xlsxpath = xlsxpath
24
23
  @langpathobj_list = langpathobj_list
25
24
  @sheetobj_list = sheetobj_list
26
- @injectobj = Applocale::Injection.load(rubycode)
25
+ @convert_file = convert_file
27
26
  startParse()
28
27
  end
29
28
 
@@ -47,7 +46,7 @@ module Applocale
47
46
  end
48
47
 
49
48
  def parse_ios
50
- result = ParseStringsFile.new(@platform, @langpathobj_list, @injectobj)
49
+ result = ParseStringsFile.new(@platform, @langpathobj_list, @convert_file)
51
50
  errorlist = result.errorlist
52
51
  content = result.strings_keys
53
52
  keylist = result.keys_list
@@ -55,7 +54,7 @@ module Applocale
55
54
  end
56
55
 
57
56
  def parse_android
58
- result = ParseXMLFile.new(@platform, @langpathobj_list, @injectobj)
57
+ result = ParseXMLFile.new(@platform, @langpathobj_list,@convert_file)
59
58
  errorlist = result.errorlist
60
59
  content = result.strings_keys
61
60
  keylist = result.keys_list
@@ -1,19 +1,18 @@
1
1
  require File.expand_path('../../setting.rb', __FILE__)
2
2
  require File.expand_path('../../../Util/error_util.rb', __FILE__)
3
3
  require File.expand_path('../../../Util/regex_util.rb', __FILE__)
4
- require File.expand_path('../../../Util/injection.rb', __FILE__)
5
4
 
6
5
  module Applocale
7
6
  class ParseStringsFile
8
7
 
9
- attr_reader :strings_keys, :errorlist, :in_multiline_comments, :keys_list, :platform, :injectobj
8
+ attr_reader :strings_keys, :errorlist, :in_multiline_comments, :keys_list, :platform, :convert_file
10
9
 
11
- def initialize(platform, langpathobj_list, injectobj)
10
+ def initialize(platform, langpathobj_list, convert_file)
12
11
  @strings_keys = {}
13
12
  @keys_list = Array.new
14
13
  @errorlist = Array.new()
15
14
  @platform = platform
16
- @injectobj = injectobj
15
+ @convert_file = convert_file
17
16
  self.to_parse_files(langpathobj_list)
18
17
  end
19
18
 
@@ -163,20 +162,11 @@ module Applocale
163
162
  end
164
163
 
165
164
  def remove_escape(lang, key, content)
166
- value = content
167
- if @injectobj.has_before_parse_from_locale
168
- value = @injectobj.load_before_parse_from_locale(lang.to_s, key, value)
169
- end
170
- if @injectobj.has_parse_from_locale
171
- value = @injectobj.load_parse_from_locale(lang.to_s, key, value)
172
- else
173
- value = ContentUtil.remove_escape(@platform, value)
174
- end
175
- if @injectobj.has_after_parse_from_locale
176
- value = @injectobj.load_after_parse_from_locale(lang.to_s, key, value)
165
+ value = ContentUtil.remove_escape(@platform, content)
166
+ if @convert_file.has_parse_from_locale
167
+ return @convert_file.load_parse_from_locale(lang.to_s, key, content, value)
177
168
  end
178
169
  return value
179
170
  end
180
-
181
171
  end
182
172
  end
@@ -1,18 +1,19 @@
1
1
  require File.expand_path('../../setting.rb', __FILE__)
2
2
  require File.expand_path('../../../Util/error_util.rb', __FILE__)
3
3
  require File.expand_path('../../../Util/regex_util.rb', __FILE__)
4
+ require File.expand_path('../../../Util/convert_util.rb', __FILE__)
4
5
 
5
6
  module Applocale
6
7
 
7
8
  class ParseXMLFile
8
- attr_reader :strings_keys, :errorlist, :in_multiline_comments, :keys_list, :platform, :injectobj
9
+ attr_reader :strings_keys, :errorlist, :in_multiline_comments, :keys_list, :platform, :convert_file
9
10
 
10
- def initialize(platform, langpathobj_list, injectobj)
11
+ def initialize(platform, langpathobj_list, convert_file)
11
12
  @strings_keys = {}
12
13
  @keys_list = Array.new
13
14
  @errorlist = Array.new()
14
15
  @platform = platform
15
- @injectobj = injectobj
16
+ @convert_file = convert_file
16
17
  self.to_parse_files(langpathobj_list)
17
18
  end
18
19
 
@@ -48,20 +49,11 @@ module Applocale
48
49
  end
49
50
 
50
51
  def remove_escape(lang, key, content)
51
- value = content
52
- if @injectobj.has_before_parse_from_locale
53
- value = @injectobj.load_before_parse_from_locale(lang.to_s, key, value)
54
- end
55
- if @injectobj.has_parse_from_locale
56
- value = @injectobj.load_parse_from_locale(lang.to_s, key, value)
57
- else
58
- value = ContentUtil.remove_escape(@platform, value)
59
- end
60
- if @injectobj.has_after_parse_from_locale
61
- value = @injectobj.load_after_parse_from_locale(lang.to_s, key, value)
52
+ value = ContentUtil.remove_escape(@platform, content)
53
+ if @convert_file.has_parse_from_locale
54
+ return @convert_file.load_parse_from_locale(lang.to_s, key, content, value)
62
55
  end
63
56
  return value
64
57
  end
65
-
66
58
  end
67
59
  end
@@ -1,7 +1,7 @@
1
1
  require File.expand_path('../setting.rb', __FILE__)
2
2
  require File.expand_path('../../Util/platform.rb', __FILE__)
3
3
  require File.expand_path('../../Util/regex_util.rb', __FILE__)
4
- require File.expand_path('../../Util/injection.rb', __FILE__)
4
+ require File.expand_path('../../Util/convert_util.rb', __FILE__)
5
5
 
6
6
  require 'colorize'
7
7
  require 'json'
@@ -14,22 +14,21 @@ module Applocale
14
14
 
15
15
  platform = setting.platform
16
16
  lang_path_list = setting.lang_path_list
17
- injectObj = setting.injection
18
17
 
19
18
  lang_path_list.each do |langpath_obj|
20
19
  puts "Start to convert to string file for [\"#{langpath_obj.lang}\"] #{langpath_obj.filepath}...".green
21
20
  if platform == Platform::IOS
22
- self.convert_to_stringfile(platform, langpath_obj, sheetcontent_list, injectObj)
21
+ self.convert_to_stringfile(platform, langpath_obj, sheetcontent_list, setting.convert_file)
23
22
  elsif platform == Platform::ANDROID
24
- self.convert_to_xml(platform, langpath_obj, sheetcontent_list, injectObj)
23
+ self.convert_to_xml(platform, langpath_obj, sheetcontent_list, setting.convert_file)
25
24
  elsif platform == Platform::JSON
26
- self.convert_to_json(platform, langpath_obj, sheetcontent_list, injectObj)
25
+ self.convert_to_json(platform, langpath_obj, sheetcontent_list, setting.convert_file)
27
26
  end
28
27
  end
29
28
  puts 'Convert Finished !!!'.green
30
29
  end
31
30
 
32
- def self.convert_to_stringfile(platform, langpath_obj, sheetcontent_list, injectObj)
31
+ def self.convert_to_stringfile(platform, langpath_obj, sheetcontent_list, convert_file)
33
32
  FileUtils.mkdir_p(File.dirname(langpath_obj.filepath))
34
33
  file_header_comment = []
35
34
  is_double_dash_comment = false
@@ -76,14 +75,14 @@ module Applocale
76
75
  target.puts('')
77
76
  contentlist.each do |rowinfo|
78
77
  content = rowinfo.content_dict[langpath_obj.lang]
79
- value = self.add_escape(platform, langpath_obj.lang, rowinfo.key_str, content, injectObj)
78
+ value = self.add_escape(platform, langpath_obj.lang, rowinfo.key_str, content, convert_file)
80
79
  target.puts("\"#{rowinfo.key_str}\" = \"#{value}\";")
81
80
  end
82
81
  end
83
82
  target.close
84
83
  end
85
84
 
86
- def self.convert_to_xml(platform, langpath_obj, sheetcontent_list, injectObj)
85
+ def self.convert_to_xml(platform, langpath_obj, sheetcontent_list, convert_file)
87
86
  FileUtils.mkdir_p(File.dirname(langpath_obj.filepath))
88
87
  target = open(langpath_obj.filepath, 'w')
89
88
  target.puts('<resources>')
@@ -92,7 +91,7 @@ module Applocale
92
91
  contentlist = sheetcontent.get_rowInfo_sortby_key
93
92
  contentlist.each do |rowinfo|
94
93
  content = rowinfo.content_dict[langpath_obj.lang]
95
- value = self.add_escape(platform, langpath_obj.lang, rowinfo.key_str, content, injectObj)
94
+ value = self.add_escape(platform, langpath_obj.lang, rowinfo.key_str, content, convert_file)
96
95
  target.puts(" <string name=\"#{rowinfo.key_str}\">#{value}</string>")
97
96
  end
98
97
  target.puts('')
@@ -101,12 +100,12 @@ module Applocale
101
100
  target.close
102
101
  end
103
102
 
104
- def self.convert_to_json(platform, lang_path_obj, sheet_content_list, inject_obj)
103
+ def self.convert_to_json(platform, lang_path_obj, sheet_content_list, convert_file)
105
104
  FileUtils.mkdir_p(File.dirname(lang_path_obj.filepath))
106
105
  hash = sheet_content_list.map do |sheet_content|
107
106
  newResult = sheet_content.get_rowInfo_sortby_key.map do |row|
108
107
  content = ContentUtil.remove_escaped_new_line(row.content_dict[lang_path_obj.lang])
109
- value = add_escape(platform, lang_path_obj.lang, row.key_str, content, inject_obj)
108
+ value = add_escape(platform, lang_path_obj.lang, row.key_str, content, convert_file)
110
109
  [row.key_str, value]
111
110
  end.to_h
112
111
  newResult
@@ -124,21 +123,12 @@ module Applocale
124
123
  target.close
125
124
  end
126
125
 
127
- def self.add_escape(platform, lang, key, content, injectObj)
128
- value = content
129
- if injectObj.has_before_convent_to_locale
130
- value = injectObj.load_before_convent_to_locale(lang.to_s, key, value)
131
- end
132
- if injectObj.has_convent_to_locale
133
- value = injectObj.load_convent_to_locale(lang.to_s, key, value)
134
- else
135
- value = ContentUtil.add_escape(platform, value)
136
- end
137
- if injectObj.has_after_convent_to_locale
138
- value = injectObj.load_after_convent_to_locale(lang.to_s, key, value)
126
+ def self.add_escape(platform, lang, key, content, convert_file)
127
+ value = ContentUtil.add_escape(platform, content)
128
+ if convert_file.has_convent_to_locale
129
+ return convert_file.load_convent_to_locale(lang.to_s, key, content, value)
139
130
  end
140
131
  return value
141
132
  end
142
-
143
133
  end
144
134
  end
@@ -8,12 +8,15 @@ require File.expand_path('../ParseCSV/parse_csv', __FILE__)
8
8
  require File.expand_path('../ParserStringFile/parse_localized_resource.rb', __FILE__)
9
9
  require File.expand_path('../convert_to_localefile', __FILE__)
10
10
  require File.expand_path('../FindStrKey/find_str_key', __FILE__)
11
+ require File.expand_path('../CompareStringFile/compare_string_file', __FILE__)
11
12
 
12
13
  require 'open-uri'
13
14
 
14
15
  module Applocale
15
16
 
16
- def self.create_config_file( platformStr = nil, projpath = Dir.pwd)
17
+ def self.create_config_file( platformStr = nil, projpath = Dir.pwd, configFile = FilePathUtil.default_config_filename)
18
+ configfile_name = configFile
19
+ configfile_name = FilePathUtil.default_config_filename if configfile_name.nil?
17
20
  proj_path = projpath
18
21
  proj_path = Dir.pwd if projpath.nil?
19
22
  proj_apath = Applocale::FilePathUtil.get_proj_absoluat_path(proj_path)
@@ -31,15 +34,17 @@ module Applocale
31
34
  if platformsybom.nil?
32
35
  ErrorUtil::CommandError.new("Invalid [platform] : ios | android | json").raise
33
36
  else
34
- Applocale::Config::ConfigUtil.create_configfile_ifneed(platformsybom,proj_apath.to_s )
37
+ Applocale::Config::ConfigUtil.create_configfile_ifneed(platformsybom,proj_apath.to_s, configfile_name )
35
38
  end
36
39
  end
37
40
 
38
- def self.start_update(projpath = Dir.pwd)
41
+ def self.start_update(projpath = Dir.pwd, configFile = FilePathUtil.default_config_filename)
42
+ configfile_name = configFile
43
+ configfile_name = FilePathUtil.default_config_filename if configfile_name.nil?
39
44
  proj_path = projpath
40
45
  proj_path = Dir.pwd if projpath.nil?
41
46
  proj_apath = Applocale::FilePathUtil.get_proj_absoluat_path(proj_path)
42
- obj = Applocale::Config::ConfigUtil.new(proj_apath)
47
+ obj = Applocale::Config::ConfigUtil.new(proj_apath, configfile_name)
43
48
  setting = obj.load_configfile_to_setting
44
49
  if setting.link.to_s.length <= 0
45
50
  ErrorUtil::ConfigFileInValid.new('[link] is missing in config file ').raise
@@ -54,16 +59,18 @@ module Applocale
54
59
  download = open(setting.link)
55
60
  IO.copy_stream(download, setting.xlsxpath)
56
61
  end
57
- Applocale.start_local_update(setting, proj_path)
62
+ Applocale.start_local_update(setting, proj_path, configfile_name)
58
63
  end
59
64
 
60
- def self.start_local_update(asetting = nil, projpath = Dir.pwd)
65
+ def self.start_local_update(asetting = nil, projpath = Dir.pwd, configFile = FilePathUtil.default_config_filename.to_s)
66
+ configfile_name = configFile
67
+ configfile_name = FilePathUtil.default_config_filename if configfile_name.nil?
61
68
  proj_path = projpath
62
69
  proj_path = Dir.pwd if projpath.nil?
63
70
  proj_apath = Applocale::FilePathUtil.get_proj_absoluat_path(proj_path)
64
71
  setting = asetting
65
72
  if setting.nil?
66
- obj = Applocale::Config::ConfigUtil.new(proj_apath)
73
+ obj = Applocale::Config::ConfigUtil.new(proj_apath, configfile_name)
67
74
  setting = obj.load_configfile_to_setting
68
75
  end
69
76
  case setting.export_format
@@ -75,22 +82,52 @@ module Applocale
75
82
  ConvertToStrFile.convert(setting, parser.result)
76
83
  end
77
84
 
78
- def self.start_reverse( is_skip, projpath = Dir.pwd)
85
+ def self.start_reverse( is_skip, projpath = Dir.pwd, configFile = FilePathUtil.default_config_filename)
86
+ configfile_name = configFile
87
+ configfile_name = FilePathUtil.default_config_filename if configfile_name.nil?
79
88
  proj_path = projpath
80
89
  proj_path = Dir.pwd if projpath.nil?
81
90
  proj_apath = Applocale::FilePathUtil.get_proj_absoluat_path(proj_path)
82
- obj = Applocale::Config::ConfigUtil.new(proj_apath)
91
+ obj = Applocale::Config::ConfigUtil.new(proj_apath, configfile_name)
83
92
  setting = obj.load_configfile_to_setting
84
93
  Applocale::ParseLocalizedResource.new(is_skip,setting.platform,setting.xlsxpath, setting.lang_path_list, setting.sheet_obj_list, setting.rubycode )
85
94
  end
86
95
 
87
- def self.findkey( key, projpath = Dir.pwd)
96
+ def self.findkey( key, projpath = Dir.pwd, configFile = FilePathUtil.default_config_filename)
97
+ configfile_name = configFile
98
+ configfile_name = FilePathUtil.default_config_filename if configfile_name.nil?
88
99
  proj_path = projpath
89
100
  proj_path = Dir.pwd if projpath.nil?
90
101
  proj_apath = Applocale::FilePathUtil.get_proj_absoluat_path(proj_path)
91
- obj = Applocale::Config::ConfigUtil.new(proj_apath)
102
+ obj = Applocale::Config::ConfigUtil.new(proj_apath, configfile_name)
92
103
  report_folder = File.dirname(obj.configfile_pathstr)
93
104
  findobj = FindStrKey::FindValue.new(Applocale::Platform::IOS, proj_apath, report_folder, key)
94
105
  findobj.find
95
106
  end
107
+
108
+ def self.compare(file1, file2)
109
+ file1_path = Applocale::FilePathUtil.get_proj_absoluat_path(file1)
110
+ file2_path = Applocale::FilePathUtil.get_proj_absoluat_path(file2)
111
+
112
+ unless File.exist?(file1_path)
113
+ ErrorUtil::FileNotExist.new.raise
114
+ end
115
+ unless File.exist?(file2_path)
116
+ ErrorUtil::FileNotExist.new.raise
117
+ end
118
+
119
+ ext1 = File.extname(file1).strip.downcase[1..-1]
120
+ ext2 = File.extname(file2).strip.downcase[1..-1]
121
+ if ext1 != ext2
122
+ ErrorUtil::FileMustSameExt.new.raise
123
+ end
124
+
125
+ if ext1 == 'strings'
126
+ platformsybom = Platform::IOS
127
+ elsif ext2 == 'xml'
128
+ platformsybom = Platform::ANDROID
129
+ end
130
+
131
+ Applocale::CompareStringFile.new(platformsybom,file1_path,file2_path)
132
+ end
96
133
  end
@@ -1,4 +1,6 @@
1
1
  require 'colorize'
2
+ require File.expand_path('../../Util/convert_util.rb', __FILE__)
3
+
2
4
  # module Applocale
3
5
  # class Setting
4
6
  # class <<self
@@ -21,7 +23,7 @@ require 'colorize'
21
23
  module Applocale
22
24
  module Config
23
25
  class Setting
24
- attr_accessor :configfile_pathstr, :link, :platform, :xlsxpath, :google_credentials_path, :lang_path_list, :sheet_obj_list, :rubycode, :export_format, :export_to, :is_skip_empty_key, :injection
26
+ attr_accessor :configfile_pathstr, :resource_folder,:link, :platform, :xlsxpath, :google_credentials_path, :lang_path_list, :sheet_obj_list, :rubycode, :export_format, :export_to, :is_skip_empty_key, :convert_file
25
27
  def initialize(configfile_pathstr)
26
28
  self.configfile_pathstr = configfile_pathstr
27
29
  self.lang_path_list = Array.new
@@ -32,6 +34,7 @@ module Applocale
32
34
  puts ' In Setting'
33
35
  puts " link = #{self.link}"
34
36
  puts " platform = #{self.platform}"
37
+ puts " resource_folder = #{self.resource_folder}"
35
38
  puts " xlsxpath = #{self.xlsxpath}"
36
39
  puts " google_credentials_path = #{self.google_credentials_path} "
37
40
 
@@ -47,6 +50,7 @@ module Applocale
47
50
  puts " export_format: #{export_format}"
48
51
  puts " export_to: #{export_to}"
49
52
  puts " is_skip_empty_key: #{self.is_skip_empty_key} "
53
+ puts " convertFile: #{self.convert_file.filepath}"
50
54
  # puts self.rubycode
51
55
 
52
56
  end
@@ -3,19 +3,20 @@ require File.expand_path('../file_util.rb', __FILE__)
3
3
  require File.expand_path('../error_util.rb', __FILE__)
4
4
  require File.expand_path('../platform.rb', __FILE__)
5
5
  require File.expand_path('../../Core/setting.rb', __FILE__)
6
- require File.expand_path('../injection.rb', __FILE__)
6
+ require File.expand_path('../convert_util.rb', __FILE__)
7
7
 
8
8
  require 'pathname'
9
9
 
10
10
  module Applocale
11
11
  module Config
12
12
  class ConfigUtil
13
- attr_accessor :configfile_pathstr
13
+ attr_accessor :configfile_pathstr, :configFile
14
14
 
15
- def initialize(projectdir_path)
15
+ def initialize(projectdir_path, config_filename)
16
16
  projpath = Pathname.new(projectdir_path.strip)
17
17
  if File.directory?(projpath)
18
- self.configfile_pathstr = File.join(projpath, FilePathUtil.default_mainfolder, FilePathUtil.default_config_filename)
18
+ self.configFile = config_filename
19
+ self.configfile_pathstr = File.join(projpath, FilePathUtil.default_mainfolder, config_filename)
19
20
  FileUtils.mkdir_p(File.dirname(self.configfile_pathstr))
20
21
  else
21
22
  ErrorUtil::ConfigFileInValid.new('Project Path is invalid.').raise
@@ -25,7 +26,7 @@ module Applocale
25
26
  public
26
27
  def create_configfile(platform)
27
28
  if !File.exist?(self.configfile_pathstr)
28
- src_pathstr = File.expand_path("../../#{FilePathUtil.default_config_filename}", __FILE__)
29
+ src_pathstr = File.expand_path("../../#{self.configFile}", __FILE__)
29
30
  File.open(src_pathstr, 'r') do |form|
30
31
  File.open(configfile_pathstr, 'w') do |to|
31
32
  form.each_line do |line|
@@ -33,6 +34,7 @@ module Applocale
33
34
  newline = newline.gsub("\#{path_zh_TW}", FilePathUtil.default_localefile_relative_pathstr(platform, Locale::ZH_TW))
34
35
  newline = newline.gsub("\#{path_zh_CN}", FilePathUtil.default_localefile_relative_pathstr(platform, Locale::ZH_CN))
35
36
  newline = newline.gsub("\#{path_en_US}", FilePathUtil.default_localefile_relative_pathstr(platform, Locale::EN_US))
37
+ newline = newline.gsub("\#{resource_folder}", FilePathUtil.default_export_to)
36
38
  newline = newline.gsub("\#{xlsxpath}", FilePathUtil.default_xlsx_relativepath_str)
37
39
  newline = newline.gsub("\#{google_credentials_path}", FilePathUtil.default_google_credentials_filename)
38
40
  newline = newline.gsub("\#{export_format}", FilePathUtil.default_export_format.to_s)
@@ -40,18 +42,20 @@ module Applocale
40
42
  end
41
43
  end
42
44
  end
45
+ converfile = "convert.rb"
46
+ src_pathstr = File.expand_path("../../#{converfile}", __FILE__)
47
+ FileUtils.cp(src_pathstr, File.expand_path("convert.rb",File.dirname(self.configfile_pathstr)))
43
48
  end
44
49
  end
45
50
 
46
51
  public
47
- def self.create_configfile_ifneed(platform, projectdir_path)
48
- config = ConfigUtil.new(projectdir_path)
52
+ def self.create_configfile_ifneed(platform, projectdir_path, config_filename)
53
+ config = ConfigUtil.new(projectdir_path, config_filename)
49
54
  config.create_configfile(platform)
50
55
  end
51
56
 
52
57
  private
53
58
  def load_configfile
54
- rubycode = ''
55
59
  unless File.exist?(self.configfile_pathstr)
56
60
  ErrorUtil::MissingConfigFile.new.raise
57
61
  end
@@ -61,21 +65,19 @@ module Applocale
61
65
  reg = /\w*\s*:\s*"?.*"?/
62
66
  if line.match reg
63
67
  yaml += line
64
- else
65
- rubycode += line
66
68
  end
67
69
  end
68
70
  config_yaml = YAML.load( yaml)
69
71
  rescue
70
72
  ErrorUtil::ConfigFileInValid.new('ConfigFile format is invalid.')
71
73
  end
72
- return config_yaml, rubycode
74
+ return config_yaml
73
75
  end
74
76
 
75
77
  public
76
78
  def load_configfile_to_setting
77
79
  error_list = Array.new
78
- config_yaml, rubycode = load_configfile
80
+ config_yaml = load_configfile
79
81
  link = config_yaml['link'].to_s.strip
80
82
  platform = config_yaml['platform'].to_s.strip
81
83
  xlsxpath = config_yaml['xlsxpath'].to_s.strip
@@ -83,11 +85,12 @@ module Applocale
83
85
  langlist = config_yaml['langlist']
84
86
  sheetname = config_yaml['sheetname']
85
87
  export_format = config_yaml['export_format']
88
+ resource_folder = config_yaml['resource_folder']
86
89
  export_to = config_yaml['export_to']
87
90
  isSkipEmptyKey = config_yaml['isSkipEmptyKey']
91
+ configFileFolder = File.dirname(self.configfile_pathstr)
88
92
  setting = Applocale::Config::Setting.new(self.configfile_pathstr)
89
- setting.rubycode = rubycode
90
- setting.injection = Applocale::Injection.load(rubycode)
93
+ setting.convert_file = Applocale::ConvertFile.new(config_yaml['convertFile'],configFileFolder)
91
94
 
92
95
  unless link.nil? || link.length == 0
93
96
  if (link =~ /^https/).nil? && (link =~ /^http/).nil?
@@ -119,7 +122,11 @@ module Applocale
119
122
  error_list.push(error)
120
123
  end
121
124
 
122
- setting.export_to = FilePathUtil.default_export_to
125
+ if resource_folder.nil? || resource_folder.length == 0
126
+ setting.export_to = File.expand_path(FilePathUtil.default_export_to,configFileFolder)
127
+ else
128
+ setting.export_to = File.expand_path(resource_folder,configFileFolder)
129
+ end
123
130
 
124
131
  if !(xlsxpath.nil? || xlsxpath.length == 0)
125
132
  if !(Pathname.new xlsxpath).absolute?
@@ -226,192 +233,3 @@ module Applocale
226
233
  end
227
234
  end
228
235
 
229
- # config = Applocale::Config::ConfigUtil.new("/Users/kennix.chui/Desktop/programTest/")
230
- # config.load_configfile_to_setting
231
- #
232
- # Applocale::Config::ConfigUtil.create_configfile_ifneed(Applocale::Platform::IOS, "/Users/kennix.chui/Desktop/programTest/")
233
- #
234
-
235
- # config = Applocale::Config::ConfigUtil.new("/Users/kennix.chui/Desktop/programTest/")
236
- # config.load_configfile_to_setting
237
-
238
-
239
- # Applocale::Config::ConfigUtil.create_configfile_ifneed(Applocale::Platform::IOS, " /Users/kennix.chui/Desktop/programTest/ ")
240
- # obj = Applocale::ConfigUtil.new()
241
-
242
- # module Applocale
243
- # class ConfigUtil
244
- # def self.create_configfile_ifneed(platform)
245
- # pathstr = FileUtil.configfile_pathstr
246
- # self.create_configfile(platform, pathstr) unless File.exist?(pathstr)
247
- # end
248
- #
249
- # def self.create_configfile(platform, configfile_pathstr)
250
- # src_pathstr = File.expand_path("../../#{FileUtil.filename_config}", __FILE__)
251
- #
252
- # File.open(src_pathstr, 'r') do |form|
253
- # File.open(configfile_pathstr, 'w') do |to|
254
- # form.each_line do |line|
255
- # newline = line.gsub("\#{platform}", "#{platform.to_s}")
256
- # newline = newline.gsub("\#{path_zh_TW}", FileUtil.get_default_localefile_relative_pathstr(platform, Locale::ZH_TW))
257
- # newline = newline.gsub("\#{path_zh_CN}", FileUtil.get_default_localefile_relative_pathstr(platform, Locale::ZH_CN))
258
- # newline = newline.gsub("\#{path_en_US}", FileUtil.get_default_localefile_relative_pathstr(platform, Locale::EN_US))
259
- # newline = newline.gsub("\#{xlsxpath}", FileUtil.get_default_xlsx_relativepath_str)
260
- # to.puts(newline)
261
- # end
262
- #
263
- # end
264
- # end
265
- # end
266
- #
267
- # def self.load_and_validate_xlsx_to_localefile(is_local_update, path)
268
- # config_yaml = self.load_config(path)
269
- # self.validate_xlsx_to_localefile(config_yaml, is_local_update)
270
- # end
271
- #
272
- # def self.load_and_validate_localefile_to_xlsx(path = nil)
273
- # config_yaml = self.load_config(path)
274
- # self.validate_localefile_to_xlsx(config_yaml)
275
- # end
276
- #
277
- # # private
278
- # def self.load_config(path)
279
- # configfile_path = FileUtil.configfile_pathstr
280
- # unless File.exist?(configfile_path)
281
- # ErrorUtil::MissingConfigFile.new.raise
282
- # end
283
- # begin
284
- # config_yaml = YAML.load_file configfile_path
285
- # rescue
286
- # ErrorUtil::ConfigFileInValid.new('ConfigFile format is invalid.').raise
287
- # end
288
- # return config_yaml
289
- # end
290
- #
291
- # def self.validate_xlsx_to_localefile(config_yaml, is_local_update)
292
- # error_list = self.validate_common(config_yaml)
293
- # if is_local_update
294
- # unless File.exist? Setting.xlsxpath
295
- # error = ErrorUtil::ConfigFileInValid.new("#{Setting.xlsxpath} do not exist")
296
- # error_list.push(error)
297
- # end
298
- # else
299
- # if config_yaml['link'].to_s.strip.nil? || config_yaml['link'].to_s.strip.length <= 0
300
- # error = ErrorUtil::ConfigFileInValid.new('[link] should not be empty')
301
- # error_list.push(error)
302
- # end
303
- # end
304
- # ErrorUtil::ConfigFileInValid.raiseArr(error_list)
305
- # end
306
- #
307
- # def self.validate_localefile_to_xlsx(config_yaml)
308
- # error_list = self.validate_common(config_yaml)
309
- # Setting.langlist.each do |_, langinfo|
310
- # unless File.exist? langinfo[:path]
311
- # error = ErrorUtil::ConfigFileInValid.new("#{langinfo[:path]} do not exist")
312
- # error_list.push(error)
313
- # end
314
- # end
315
- # ErrorUtil::ConfigFileInValid.raiseArr(error_list)
316
- # end
317
- #
318
- # def self.validate_common(config_yaml)
319
- # error_list = Array.new
320
- # link = config_yaml['link'].to_s.strip
321
- # platform = config_yaml['platform'].to_s.strip
322
- # keystr = config_yaml['keystr'].to_s.strip
323
- # langlist = config_yaml['langlist']
324
- # xlsxpath = config_yaml['xlsxpath'].to_s.strip
325
- #
326
- # newlink = nil
327
- # newplatform = nil
328
- # newkeystr = nil
329
- # newlanglist = Hash.new
330
- # newxlsxpath = nil
331
- #
332
- # unless link.nil? || link.length == 0
333
- # if (link =~ /^https/).nil? && (link =~ /^http/).nil?
334
- # error = ErrorUtil::ConfigFileInValid.new("Invalid link for [link] : #{link}")
335
- # error_list.push(error)
336
- # else
337
- # newlink = link
338
- # end
339
- # end
340
- #
341
- # if !(xlsxpath.nil? || xlsxpath.length == 0)
342
- # if !(Pathname.new xlsxpath).absolute?
343
- # newxlsxpath = File.expand_path(xlsxpath, File.dirname(FileUtil.configfile_pathstr))
344
- # else
345
- # newxlsxpath = xlsxpath
346
- # end
347
- # else
348
- # error = ErrorUtil::ConfigFileInValid.new('[xlsxpath] should not be empty or missing')
349
- # error_list.push(error)
350
- # end
351
- #
352
- # if platform.nil? || platform.length == 0
353
- # error = ErrorUtil::ConfigFileInValid.new('[platform] should not be empty')
354
- # error_list.push(error)
355
- # else
356
- # if Platform.init(platform).nil?
357
- # error = ErrorUtil::ConfigFileInValid.new("[platform] can only be 'ios' or 'android' ")
358
- # error_list.push(error)
359
- # else
360
- # newplatform = Platform.init(platform)
361
- # end
362
- # end
363
- #
364
- # if keystr.nil? || keystr.length == 0
365
- # error = ErrorUtil::ConfigFileInValid.new('[keystr] should not be empty')
366
- # error_list.push(error)
367
- # else
368
- # newkeystr = keystr.upcase
369
- # end
370
- #
371
- # if langlist.nil?
372
- # error = ErrorUtil::ConfigFileInValid.new('[langlist] should not be empty or missing')
373
- # error_list.push(error)
374
- # elsif !(langlist.is_a? Hash)
375
- # error = ErrorUtil::ConfigFileInValid.new('[langlist] wrong format')
376
- # error_list.push(error)
377
- # else
378
- # if langlist.length <= 0
379
- # error = ErrorUtil::ConfigFileInValid.new('[langlist] should not be empty ')
380
- # error_list.push(error)
381
- # end
382
- # langlist.each do |lang, arr|
383
- # if arr.length != 2
384
- # error = ErrorUtil::ConfigFileInValid.new('[langlist] wrong format')
385
- # error_list.push(error)
386
- # else
387
- # path = arr[1]
388
- # unless (Pathname.new path).absolute?
389
- # path = File.expand_path(path, File.dirname(FileUtil.configfile_pathstr))
390
- # end
391
- # if newplatform != nil
392
- # if Platform.is_valid_path(newplatform, path)
393
- # newlanglist[lang] = {:xlsheader => arr[0], :path => path}
394
- # else
395
- # if newplatform == Platform::IOS
396
- # error = ErrorUtil::ConfigFileInValid.new("wrong locale file type: IOS should be .strings : #{path}")
397
- # else
398
- # error = ErrorUtil::ConfigFileInValid.new("wrong locale file type: Android should be .xml : #{path}")
399
- # end
400
- # error_list.push(error)
401
- # end
402
- # end
403
- # end
404
- # end
405
- # end
406
- #
407
- # Setting.link = newlink
408
- # Setting.platform = newplatform
409
- # Setting.keystr = newkeystr
410
- # Setting.langlist = newlanglist
411
- # Setting.xlsxpath = newxlsxpath
412
- #
413
- # return error_list
414
- # end
415
- #
416
- # end
417
- # end