applocale 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/applocale/Command/init.rb +11 -6
- data/lib/applocale/Core/Compare/compare_xlsx_str.rb +2 -0
- data/lib/applocale/Core/{client_secret.json → GoogleHepler/client_secret.json} +0 -0
- data/lib/applocale/Core/{google_helper.rb → GoogleHepler/google_helper.rb} +20 -16
- data/lib/applocale/Core/ParseXLSX/parse_xlsx.rb +155 -0
- data/lib/applocale/Core/{parse_xlsx_module.rb → ParseXLSX/parse_xlsx_module.rb} +19 -19
- data/lib/applocale/Core/ParserStringFile/parse_localized_resource.rb +17 -31
- data/lib/applocale/Core/ParserStringFile/parse_strings_file.rb +8 -2
- data/lib/applocale/Core/ParserStringFile/parse_xml_file.rb +2 -3
- data/lib/applocale/Core/{convert_to_str_file.rb → convert_to_localefile.rb} +18 -24
- data/lib/applocale/Core/init.rb +15 -11
- data/lib/applocale/Core/setting.rb +3 -2
- data/lib/applocale/Util/config_util.rb +65 -50
- data/lib/applocale/Util/error_util.rb +78 -20
- data/lib/applocale/Util/file_util.rb +26 -26
- data/lib/applocale/Util/lang.rb +1 -1
- data/lib/applocale/Util/platform.rb +17 -2
- data/lib/applocale/Util/regex_util.rb +18 -18
- data/lib/applocale/version.rb +1 -1
- metadata +7 -7
- data/lib/applocale/Core/parse_xlsx.rb +0 -166
- data/lib/applocale/Util/color_util.rb +0 -28
@@ -27,6 +27,8 @@ module Applocale
|
|
27
27
|
@in_multiline_comments = false
|
28
28
|
keyrowno = {}
|
29
29
|
linenum = 0
|
30
|
+
begin
|
31
|
+
|
30
32
|
IO.foreach(strings_path, mode: 'r:bom|utf-8') {|line|
|
31
33
|
linenum += 1
|
32
34
|
line.strip!
|
@@ -64,7 +66,7 @@ module Applocale
|
|
64
66
|
break
|
65
67
|
end
|
66
68
|
|
67
|
-
if !ValidKey.
|
69
|
+
if !ValidKey.is_validkey(@platform, key)
|
68
70
|
error = ErrorUtil::ParseLocalizedError::InvalidKey.new(key, strings_path, lang, linenum)
|
69
71
|
@errorlist.push(error)
|
70
72
|
break
|
@@ -76,7 +78,7 @@ module Applocale
|
|
76
78
|
if @strings_keys[key][lang.to_s].nil?
|
77
79
|
@strings_keys[key][lang.to_s] = Hash.new
|
78
80
|
@strings_keys[key][lang.to_s][:rowno] = linenum
|
79
|
-
@strings_keys[key][lang.to_s][:value] = ContentUtil.
|
81
|
+
@strings_keys[key][lang.to_s][:value] = ContentUtil.remove_escape(@platform, value)
|
80
82
|
keyrowno[key] = linenum
|
81
83
|
else
|
82
84
|
error = ErrorUtil::ParseLocalizedError::DuplicateKey.new(key, keyrowno[key], strings_path, lang, linenum)
|
@@ -87,6 +89,9 @@ module Applocale
|
|
87
89
|
end
|
88
90
|
end
|
89
91
|
}
|
92
|
+
rescue
|
93
|
+
ErrorUtil::ParseLocalizedError::InvalidFile.new(strings_path).raise
|
94
|
+
end
|
90
95
|
end
|
91
96
|
|
92
97
|
def parse_token(linenum, line, sep, lang, file)
|
@@ -153,5 +158,6 @@ module Applocale
|
|
153
158
|
end
|
154
159
|
return value, line[n..-1]
|
155
160
|
end
|
161
|
+
|
156
162
|
end
|
157
163
|
end
|
@@ -22,7 +22,6 @@ module Applocale
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def to_parse_strings_file(lang, strings_path)
|
25
|
-
xml_doc = nil
|
26
25
|
return if !File.exist? strings_path
|
27
26
|
puts "Start to Parse xml file: \"#{strings_path}\" ...".green
|
28
27
|
|
@@ -38,7 +37,7 @@ module Applocale
|
|
38
37
|
end
|
39
38
|
if @strings_keys[key][lang.to_s].nil?
|
40
39
|
@strings_keys[key][lang.to_s] = Hash.new
|
41
|
-
@strings_keys[key][lang.to_s][:value] = ContentUtil.
|
40
|
+
@strings_keys[key][lang.to_s][:value] = ContentUtil.remove_escape(@platform, value)
|
42
41
|
else
|
43
42
|
error = ErrorUtil::ParseLocalizedError::DuplicateKey.new(key, -1, strings_path, lang, -1)
|
44
43
|
@errorlist.push(error)
|
@@ -46,6 +45,6 @@ module Applocale
|
|
46
45
|
end
|
47
46
|
end
|
48
47
|
end
|
49
|
-
end
|
50
48
|
|
49
|
+
end
|
51
50
|
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
|
-
require File.expand_path('../../Util/color_util.rb', __FILE__)
|
4
3
|
require File.expand_path('../../Util/regex_util.rb', __FILE__)
|
4
|
+
require 'colorize'
|
5
5
|
|
6
6
|
module Applocale
|
7
7
|
class ConvertToStrFile
|
@@ -10,57 +10,51 @@ module Applocale
|
|
10
10
|
setting.langlist.each do |lang, langinfo|
|
11
11
|
puts "Start to convert to string file for [\"#{lang}\"] #{langinfo[:path]}...".green
|
12
12
|
if setting.platform == Platform::IOS
|
13
|
-
self.
|
13
|
+
self.convert_to_localefile(setting.platform, lang, langinfo[:path], sheetcontent_list)
|
14
14
|
elsif setting.platform == Platform::ANDROID
|
15
|
-
self.
|
15
|
+
self.convert_to_xml(setting.platform, lang, langinfo[:path], sheetcontent_list)
|
16
16
|
end
|
17
17
|
end
|
18
|
-
|
19
|
-
puts "Convert Finished !!!".green
|
18
|
+
puts 'Convert Finished !!!'.green
|
20
19
|
end
|
21
20
|
|
22
|
-
def self.
|
21
|
+
def self.convert_to_localefile(platform, lang, langfilepath, sheetcontent_list)
|
23
22
|
FileUtils.mkdir_p(File.dirname(langfilepath))
|
24
23
|
target = open(langfilepath, 'w')
|
25
|
-
|
26
24
|
sheetcontent_list.each do |sheetcontent|
|
27
|
-
|
25
|
+
contentlist = sheetcontent.get_rowInfo_sortby_key
|
26
|
+
next if contentlist.length <= 0
|
27
|
+
target.puts('/*******************************')
|
28
28
|
target.puts(" * #{sheetcontent.comment}")
|
29
|
-
target.puts(
|
30
|
-
target.puts(
|
31
|
-
contentlist = sheetcontent.getRowInfoSortByKey()
|
29
|
+
target.puts(' *******************************/')
|
30
|
+
target.puts('')
|
32
31
|
contentlist.each do |rowinfo|
|
33
32
|
content = rowinfo.content_dict[lang]
|
34
|
-
value = ContentUtil.
|
33
|
+
value = ContentUtil.add_escape(platform, content)
|
35
34
|
target.puts("\"#{rowinfo.key_str.downcase}\" = \"#{value}\";")
|
36
35
|
end
|
37
|
-
target.puts(
|
36
|
+
target.puts('')
|
38
37
|
end
|
39
38
|
target.close
|
40
|
-
|
41
39
|
end
|
42
40
|
|
43
|
-
def self.
|
41
|
+
def self.convert_to_xml(platform, lang, langfilepath, sheetcontent_list)
|
44
42
|
FileUtils.mkdir_p(File.dirname(langfilepath))
|
45
43
|
target = open(langfilepath, 'w')
|
46
|
-
target.puts(
|
47
|
-
|
44
|
+
target.puts('<resources>')
|
48
45
|
sheetcontent_list.each do |sheetcontent|
|
49
46
|
target.puts(" <!-- #{sheetcontent.comment} -->")
|
50
|
-
contentlist = sheetcontent.
|
47
|
+
contentlist = sheetcontent.get_rowInfo_sortby_key
|
51
48
|
contentlist.each do |rowinfo|
|
52
49
|
content = rowinfo.content_dict[lang]
|
53
|
-
value = ContentUtil.
|
50
|
+
value = ContentUtil.add_escape(platform, content)
|
54
51
|
target.puts(" <string name=\"#{rowinfo.key_str.downcase}\">#{value}</string>")
|
55
52
|
end
|
56
|
-
target.puts(
|
53
|
+
target.puts('')
|
57
54
|
end
|
58
|
-
|
59
|
-
target.puts("</resources>")
|
55
|
+
target.puts('</resources>')
|
60
56
|
target.close
|
61
57
|
end
|
62
58
|
|
63
59
|
end
|
64
60
|
end
|
65
|
-
|
66
|
-
# attr_accessor :link, :platform, :keystr, :langlist, :langfilepathlist, :xlsxpath
|
data/lib/applocale/Core/init.rb
CHANGED
@@ -1,19 +1,23 @@
|
|
1
1
|
require File.expand_path('../setting.rb', __FILE__)
|
2
|
-
require File.expand_path('../google_helper.rb', __FILE__)
|
3
|
-
require File.expand_path('../parse_xlsx', __FILE__)
|
4
|
-
require File.expand_path('../
|
2
|
+
require File.expand_path('../GoogleHepler/google_helper.rb', __FILE__)
|
3
|
+
require File.expand_path('../ParseXLSX/parse_xlsx', __FILE__)
|
4
|
+
require File.expand_path('../convert_to_localefile', __FILE__)
|
5
5
|
|
6
6
|
module Applocale
|
7
|
-
def self.
|
8
|
-
|
9
|
-
google_file_id = GoogleHelper.
|
10
|
-
|
11
|
-
GoogleHelper.
|
7
|
+
def self.start_update(is_localupdate, setting)
|
8
|
+
unless is_localupdate
|
9
|
+
google_file_id = GoogleHelper.is_googlelink(setting.link)
|
10
|
+
unless google_file_id.nil?
|
11
|
+
GoogleHelper.download_spreadsheet(google_file_id, setting.xlsxpath)
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
|
16
|
-
ConvertToStrFile.convert(
|
15
|
+
parse_xlsx = ParseXLSX.new
|
16
|
+
ConvertToStrFile.convert(parse_xlsx.result)
|
17
17
|
end
|
18
18
|
|
19
|
-
|
19
|
+
def self.start_reverse(is_skip)
|
20
|
+
Applocale::ParseLocalizedResource.new(is_skip)
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'colorize'
|
2
2
|
|
3
3
|
module Applocale
|
4
4
|
class Setting
|
@@ -7,12 +7,13 @@ module Applocale
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def self.printlog
|
10
|
-
puts
|
10
|
+
puts ' In Setting'
|
11
11
|
puts " link = #{self.link}"
|
12
12
|
puts " platform = #{self.platform}"
|
13
13
|
puts " keystr = #{self.keystr}"
|
14
14
|
puts " langlist = #{self.langlist}"
|
15
15
|
puts " xlsxpath = #{self.xlsxpath}"
|
16
16
|
end
|
17
|
+
|
17
18
|
end
|
18
19
|
end
|
@@ -8,22 +8,22 @@ require 'pathname'
|
|
8
8
|
|
9
9
|
module Applocale
|
10
10
|
class ConfigUtil
|
11
|
-
def self.
|
12
|
-
pathstr = FileUtil.
|
13
|
-
self.
|
11
|
+
def self.create_configfile_ifneed(platform)
|
12
|
+
pathstr = FileUtil.configfile_pathstr
|
13
|
+
self.create_configfile(platform, pathstr) unless File.exist?(pathstr)
|
14
14
|
end
|
15
15
|
|
16
|
-
def self.
|
16
|
+
def self.create_configfile(platform, configfile_pathstr)
|
17
17
|
src_pathstr = File.expand_path("../../#{FileUtil.filename_config}", __FILE__)
|
18
18
|
|
19
|
-
File.open(src_pathstr,
|
20
|
-
File.open(configfile_pathstr,
|
19
|
+
File.open(src_pathstr, 'r') do |form|
|
20
|
+
File.open(configfile_pathstr, 'w') do |to|
|
21
21
|
form.each_line do |line|
|
22
22
|
newline = line.gsub("\#{platform}", "#{platform.to_s}")
|
23
|
-
newline = newline.gsub("\#{path_zh_TW}", FileUtil.
|
24
|
-
newline = newline.gsub("\#{path_zh_CN}", FileUtil.
|
25
|
-
newline = newline.gsub("\#{path_en_US}", FileUtil.
|
26
|
-
newline = newline.gsub("\#{xlsxpath}", FileUtil.
|
23
|
+
newline = newline.gsub("\#{path_zh_TW}", FileUtil.get_default_localefile_relative_pathstr(platform, Locale::ZH_TW))
|
24
|
+
newline = newline.gsub("\#{path_zh_CN}", FileUtil.get_default_localefile_relative_pathstr(platform, Locale::ZH_CN))
|
25
|
+
newline = newline.gsub("\#{path_en_US}", FileUtil.get_default_localefile_relative_pathstr(platform, Locale::EN_US))
|
26
|
+
newline = newline.gsub("\#{xlsxpath}", FileUtil.get_default_xlsx_relativepath_str)
|
27
27
|
to.puts(newline)
|
28
28
|
end
|
29
29
|
|
@@ -31,60 +31,64 @@ module Applocale
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
def self.
|
34
|
+
def self.load_and_validate_xlsx_to_localefile(is_local_update)
|
35
35
|
config_yaml = self.load_config
|
36
|
-
self.
|
36
|
+
self.validate_xlsx_to_localefile(config_yaml, is_local_update)
|
37
37
|
end
|
38
38
|
|
39
|
-
def self.
|
39
|
+
def self.load_and_validate_localefile_to_xlsx()
|
40
40
|
config_yaml = self.load_config
|
41
|
-
self.
|
41
|
+
self.validate_localefile_to_xlsx(config_yaml)
|
42
42
|
end
|
43
43
|
|
44
44
|
# private
|
45
45
|
def self.load_config
|
46
|
-
configfile_path = FileUtil.
|
46
|
+
configfile_path = FileUtil.configfile_pathstr
|
47
47
|
unless File.exist?(configfile_path)
|
48
|
-
ErrorUtil::
|
48
|
+
ErrorUtil::MissingConfigFile.new.raise
|
49
|
+
end
|
50
|
+
begin
|
51
|
+
config_yaml = YAML.load_file configfile_path
|
52
|
+
rescue
|
53
|
+
ErrorUtil::ConfigFileInValid.new('ConfigFile format is invalid.').raise
|
49
54
|
end
|
50
|
-
config_yaml = YAML.load_file configfile_path
|
51
55
|
return config_yaml
|
52
56
|
end
|
53
57
|
|
54
|
-
def self.
|
55
|
-
error_list = self.
|
58
|
+
def self.validate_xlsx_to_localefile(config_yaml, is_local_update)
|
59
|
+
error_list = self.validate_common(config_yaml)
|
56
60
|
if is_local_update
|
57
|
-
|
58
|
-
error = ErrorUtil::
|
61
|
+
unless File.exist? Setting.xlsxpath
|
62
|
+
error = ErrorUtil::ConfigFileInValid.new("#{Setting.xlsxpath} do not exist")
|
59
63
|
error_list.push(error)
|
60
64
|
end
|
61
65
|
else
|
62
|
-
if
|
63
|
-
error = ErrorUtil::
|
66
|
+
if config_yaml['link'].to_s.strip.nil? || config_yaml['link'].to_s.strip.length <= 0
|
67
|
+
error = ErrorUtil::ConfigFileInValid.new('[link] should not be empty')
|
64
68
|
error_list.push(error)
|
65
69
|
end
|
66
70
|
end
|
67
|
-
ErrorUtil::
|
71
|
+
ErrorUtil::ConfigFileInValid.raiseArr(error_list)
|
68
72
|
end
|
69
73
|
|
70
|
-
def self.
|
71
|
-
error_list = self.
|
72
|
-
Setting.langlist.each do |
|
73
|
-
|
74
|
-
error = ErrorUtil::
|
74
|
+
def self.validate_localefile_to_xlsx(config_yaml)
|
75
|
+
error_list = self.validate_common(config_yaml)
|
76
|
+
Setting.langlist.each do |_, langinfo|
|
77
|
+
unless File.exist? langinfo[:path]
|
78
|
+
error = ErrorUtil::ConfigFileInValid.new("#{langinfo[:path]} do not exist")
|
75
79
|
error_list.push(error)
|
76
80
|
end
|
77
81
|
end
|
78
|
-
ErrorUtil::
|
82
|
+
ErrorUtil::ConfigFileInValid.raiseArr(error_list)
|
79
83
|
end
|
80
84
|
|
81
|
-
def self.
|
85
|
+
def self.validate_common(config_yaml)
|
82
86
|
error_list = Array.new
|
83
|
-
link = config_yaml[
|
84
|
-
platform = config_yaml[
|
85
|
-
keystr = config_yaml[
|
86
|
-
langlist = config_yaml[
|
87
|
-
xlsxpath = config_yaml[
|
87
|
+
link = config_yaml['link'].to_s.strip
|
88
|
+
platform = config_yaml['platform'].to_s.strip
|
89
|
+
keystr = config_yaml['keystr'].to_s.strip
|
90
|
+
langlist = config_yaml['langlist']
|
91
|
+
xlsxpath = config_yaml['xlsxpath'].to_s.strip
|
88
92
|
|
89
93
|
newlink = nil
|
90
94
|
newplatform = nil
|
@@ -92,9 +96,9 @@ module Applocale
|
|
92
96
|
newlanglist = Hash.new
|
93
97
|
newxlsxpath = nil
|
94
98
|
|
95
|
-
|
99
|
+
unless link.nil? || link.length == 0
|
96
100
|
if (link =~ /^https/).nil? && (link =~ /^http/).nil?
|
97
|
-
error = ErrorUtil::
|
101
|
+
error = ErrorUtil::ConfigFileInValid.new("Invalid link for [link] : #{link}")
|
98
102
|
error_list.push(error)
|
99
103
|
else
|
100
104
|
newlink = link
|
@@ -103,21 +107,21 @@ module Applocale
|
|
103
107
|
|
104
108
|
if !(xlsxpath.nil? || xlsxpath.length == 0)
|
105
109
|
if !(Pathname.new xlsxpath).absolute?
|
106
|
-
newxlsxpath = File.expand_path(xlsxpath, File.dirname(FileUtil.
|
110
|
+
newxlsxpath = File.expand_path(xlsxpath, File.dirname(FileUtil.configfile_pathstr))
|
107
111
|
else
|
108
112
|
newxlsxpath = xlsxpath
|
109
113
|
end
|
110
114
|
else
|
111
|
-
error = ErrorUtil::
|
115
|
+
error = ErrorUtil::ConfigFileInValid.new('[xlsxpath] should not be empty or missing')
|
112
116
|
error_list.push(error)
|
113
117
|
end
|
114
118
|
|
115
119
|
if platform.nil? || platform.length == 0
|
116
|
-
error = ErrorUtil::
|
120
|
+
error = ErrorUtil::ConfigFileInValid.new('[platform] should not be empty')
|
117
121
|
error_list.push(error)
|
118
122
|
else
|
119
123
|
if Platform.init(platform).nil?
|
120
|
-
error = ErrorUtil::
|
124
|
+
error = ErrorUtil::ConfigFileInValid.new("[platform] can only be 'ios' or 'android' ")
|
121
125
|
error_list.push(error)
|
122
126
|
else
|
123
127
|
newplatform = Platform.init(platform)
|
@@ -125,33 +129,44 @@ module Applocale
|
|
125
129
|
end
|
126
130
|
|
127
131
|
if keystr.nil? || keystr.length == 0
|
128
|
-
error = ErrorUtil::
|
132
|
+
error = ErrorUtil::ConfigFileInValid.new('[keystr] should not be empty')
|
129
133
|
error_list.push(error)
|
130
134
|
else
|
131
135
|
newkeystr = keystr
|
132
136
|
end
|
133
137
|
|
134
138
|
if langlist.nil?
|
135
|
-
error = ErrorUtil::
|
139
|
+
error = ErrorUtil::ConfigFileInValid.new('[langlist] should not be empty or missing')
|
136
140
|
error_list.push(error)
|
137
141
|
elsif !(langlist.is_a? Hash)
|
138
|
-
error = ErrorUtil::
|
142
|
+
error = ErrorUtil::ConfigFileInValid.new('[langlist] wrong format')
|
139
143
|
error_list.push(error)
|
140
144
|
else
|
141
145
|
if langlist.length <= 0
|
142
|
-
error = ErrorUtil::
|
146
|
+
error = ErrorUtil::ConfigFileInValid.new('[langlist] should not be empty ')
|
143
147
|
error_list.push(error)
|
144
148
|
end
|
145
149
|
langlist.each do |lang, arr|
|
146
150
|
if arr.length != 2
|
147
|
-
error = ErrorUtil::
|
151
|
+
error = ErrorUtil::ConfigFileInValid.new('[langlist] wrong format')
|
148
152
|
error_list.push(error)
|
149
153
|
else
|
150
154
|
path = arr[1]
|
151
|
-
|
152
|
-
path = File.expand_path(path, File.dirname(FileUtil.
|
155
|
+
unless (Pathname.new path).absolute?
|
156
|
+
path = File.expand_path(path, File.dirname(FileUtil.configfile_pathstr))
|
157
|
+
end
|
158
|
+
if newplatform != nil
|
159
|
+
if Platform.is_valid_path(newplatform, path)
|
160
|
+
newlanglist[lang] = {:xlsheader => arr[0], :path => path}
|
161
|
+
else
|
162
|
+
if newplatform == Platform::IOS
|
163
|
+
error = ErrorUtil::ConfigFileInValid.new("wrong locale file type: IOS should be .strings : #{path}")
|
164
|
+
else
|
165
|
+
error = ErrorUtil::ConfigFileInValid.new("wrong locale file type: Android should be .xml : #{path}")
|
166
|
+
end
|
167
|
+
error_list.push(error)
|
168
|
+
end
|
153
169
|
end
|
154
|
-
newlanglist[lang] = {:xlsheader => arr[0], :path => path}
|
155
170
|
end
|
156
171
|
end
|
157
172
|
end
|
@@ -1,12 +1,11 @@
|
|
1
|
-
require
|
2
|
-
|
1
|
+
require 'colorize'
|
3
2
|
|
4
3
|
module Applocale
|
5
4
|
module ErrorUtil
|
6
5
|
class CommonError < StandardError
|
7
6
|
def raise
|
8
7
|
puts "** Error: #{self.message}".red
|
9
|
-
abort(
|
8
|
+
abort('')
|
10
9
|
end
|
11
10
|
|
12
11
|
def to_warn
|
@@ -17,10 +16,13 @@ module Applocale
|
|
17
16
|
class CommandError < CommonError;
|
18
17
|
end
|
19
18
|
|
20
|
-
class
|
19
|
+
class MissingConfigFile < CommonError
|
20
|
+
def message
|
21
|
+
"Missing ConfigFile"
|
22
|
+
end
|
21
23
|
end
|
22
24
|
|
23
|
-
class
|
25
|
+
class ConfigFileInValid < CommonError
|
24
26
|
def self.raiseArr(list = nil)
|
25
27
|
if !list.nil? && list.length > 0
|
26
28
|
puts "*** ConfigError ***".red
|
@@ -30,29 +32,44 @@ module Applocale
|
|
30
32
|
abort("")
|
31
33
|
end
|
32
34
|
end
|
33
|
-
# attr_accessor :msg
|
34
|
-
# def initialize(msg)
|
35
|
-
# self.msg = msg
|
36
|
-
# end
|
37
35
|
end
|
38
36
|
|
39
|
-
class
|
37
|
+
class DownloadFromGoogleFail < CommonError
|
38
|
+
def message
|
39
|
+
"Cannot download from google"
|
40
|
+
end
|
41
|
+
end
|
40
42
|
|
43
|
+
class CannotOpenXlsxFile < CommonError
|
44
|
+
attr_accessor :path
|
45
|
+
def initialize(path)
|
46
|
+
@path = path
|
47
|
+
end
|
48
|
+
def message
|
49
|
+
"Can't open xlsx file #{self.path}"
|
50
|
+
end
|
41
51
|
end
|
52
|
+
end
|
53
|
+
end
|
42
54
|
|
55
|
+
module Applocale
|
56
|
+
module ErrorUtil
|
43
57
|
|
44
58
|
module ParseXlsxError
|
45
59
|
class ParseError < CommonError
|
46
60
|
|
47
|
-
attr_accessor :rowinfo
|
61
|
+
attr_accessor :rowinfo
|
48
62
|
|
49
|
-
def initialize(rowinfo = nil
|
63
|
+
def initialize(rowinfo = nil)
|
50
64
|
@rowinfo = rowinfo
|
51
|
-
@msg = msg
|
52
65
|
end
|
53
66
|
|
54
67
|
def message
|
55
|
-
|
68
|
+
self.msg
|
69
|
+
end
|
70
|
+
|
71
|
+
def msg
|
72
|
+
return rowinfo.to_s
|
56
73
|
end
|
57
74
|
|
58
75
|
def self.raiseArr(list = nil)
|
@@ -67,13 +84,43 @@ module Applocale
|
|
67
84
|
|
68
85
|
end
|
69
86
|
|
70
|
-
class
|
87
|
+
class HeadeNotFound < ParseError
|
88
|
+
attr_accessor :sheetname
|
89
|
+
def initialize(sheetname)
|
90
|
+
@sheetname = sheetname
|
91
|
+
end
|
92
|
+
|
93
|
+
def message
|
94
|
+
"Header not found in sheet: #{self.sheetname}"
|
95
|
+
end
|
71
96
|
end
|
72
|
-
|
97
|
+
|
98
|
+
class DuplicateKey < ParseError
|
99
|
+
attr_accessor :duplicate_sheetname, :duplicate_rowno
|
100
|
+
|
101
|
+
def initialize(rowinfo, duplicate_sheetname, duplicate_rowno)
|
102
|
+
@rowinfo = rowinfo
|
103
|
+
@duplicate_sheetname = duplicate_sheetname
|
104
|
+
@duplicate_rowno = duplicate_rowno
|
105
|
+
end
|
106
|
+
|
107
|
+
def message
|
108
|
+
"DuplicateKey [#{self.rowinfo.key_str}] - #{self.msg} : duplicateWithSheet: #{self.duplicate_sheetname} Row: #{self.duplicate_rowno+1}"
|
109
|
+
end
|
73
110
|
end
|
74
|
-
|
111
|
+
|
112
|
+
class InValidKey < ParseError;
|
113
|
+
def message
|
114
|
+
"InvalidKey [#{self.rowinfo.key_str}] - #{self.msg}"
|
115
|
+
end
|
75
116
|
end
|
76
117
|
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
|
122
|
+
module Applocale
|
123
|
+
module ErrorUtil
|
77
124
|
|
78
125
|
module ParseLocalizedError
|
79
126
|
class ParseLocalizedError < CommonError
|
@@ -90,7 +137,7 @@ module Applocale
|
|
90
137
|
end
|
91
138
|
|
92
139
|
def msg
|
93
|
-
return "lang: #{lang}, rowno: #{row_no}, file: #{file}"
|
140
|
+
return "lang: #{self.lang}, rowno: #{self.row_no}, file: #{self.file}"
|
94
141
|
end
|
95
142
|
|
96
143
|
def raise(is_exit = true)
|
@@ -110,6 +157,16 @@ module Applocale
|
|
110
157
|
|
111
158
|
end
|
112
159
|
|
160
|
+
class InvalidFile < ParseLocalizedError
|
161
|
+
attr_accessor :path
|
162
|
+
def initialize(path)
|
163
|
+
@path = path
|
164
|
+
end
|
165
|
+
def message
|
166
|
+
"Can't open file #{self.path}"
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
113
170
|
class InvalidKey < ParseLocalizedError
|
114
171
|
attr_accessor :key
|
115
172
|
|
@@ -121,7 +178,7 @@ module Applocale
|
|
121
178
|
end
|
122
179
|
|
123
180
|
def message
|
124
|
-
"InvalidKey [#{key}] - #{self.msg}"
|
181
|
+
"InvalidKey [#{self.key}] - #{self.msg}"
|
125
182
|
end
|
126
183
|
end
|
127
184
|
|
@@ -132,6 +189,7 @@ module Applocale
|
|
132
189
|
end
|
133
190
|
class DuplicateKey < ParseLocalizedError
|
134
191
|
attr_accessor :key, :duplicate_rowno
|
192
|
+
|
135
193
|
def initialize(key, duplicate_rowno, file, lang, row_no)
|
136
194
|
@key = key
|
137
195
|
@duplicate_rowno = duplicate_rowno
|
@@ -141,7 +199,7 @@ module Applocale
|
|
141
199
|
end
|
142
200
|
|
143
201
|
def message
|
144
|
-
"DuplicateKey [#{key}] - #{self.msg} : duplicateWithRow: #{duplicate_rowno}"
|
202
|
+
"DuplicateKey [#{self.key}] - #{self.msg} : duplicateWithRow: #{self.duplicate_rowno}"
|
145
203
|
end
|
146
204
|
end
|
147
205
|
end
|