applocale 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,149 @@
1
+ require File.expand_path('../color_util.rb', __FILE__)
2
+
3
+
4
+ module Applocale
5
+ module ErrorUtil
6
+ class CommonError < StandardError
7
+ def raise
8
+ puts "** Error: #{self.message}".red
9
+ abort("")
10
+ end
11
+
12
+ def to_warn
13
+ puts "** Warning: #{self.message}".yellow
14
+ end
15
+ end
16
+
17
+ class CommandError < CommonError;
18
+ end
19
+
20
+ class MissingConfigFileError < CommonError;
21
+ end
22
+
23
+ class ConfigFileValidError < CommonError
24
+ def self.raiseArr(list = nil)
25
+ if !list.nil? && list.length > 0
26
+ puts "*** ConfigError ***".red
27
+ list.each do |err|
28
+ puts "#{err.message}".red
29
+ end
30
+ abort("")
31
+ end
32
+ end
33
+ # attr_accessor :msg
34
+ # def initialize(msg)
35
+ # self.msg = msg
36
+ # end
37
+ end
38
+
39
+ class DownloadXlsxError < CommonError
40
+
41
+ end
42
+
43
+
44
+ module ParseXlsxError
45
+ class ParseError < CommonError
46
+
47
+ attr_accessor :rowinfo, :msg
48
+
49
+ def initialize(rowinfo = nil, msg = nil)
50
+ @rowinfo = rowinfo
51
+ @msg = msg
52
+ end
53
+
54
+ def message
55
+ "#{rowinfo.to_s} - #{msg}"
56
+ end
57
+
58
+ def self.raiseArr(list = nil)
59
+ if !list.nil? && list.length > 0
60
+ puts "*** ParseError ***".red
61
+ list.each do |err|
62
+ puts "#{err.message}".red
63
+ end
64
+ abort("")
65
+ end
66
+ end
67
+
68
+ end
69
+
70
+ class HeadeNotFoundError < ParseError;
71
+ end
72
+ class ErrorDuplicateKey < ParseError;
73
+ end
74
+ class ErrorInValidKey < ParseError;
75
+ end
76
+ end
77
+
78
+ module ParseLocalizedError
79
+ class ParseLocalizedError < CommonError
80
+ attr_accessor :file, :lang, :row_no
81
+
82
+ def initialize(file, lang, row_no)
83
+ @file = file
84
+ @lang = lang
85
+ @row_no = row_no
86
+ end
87
+
88
+ def message
89
+ self.msg
90
+ end
91
+
92
+ def msg
93
+ return "lang: #{lang}, rowno: #{row_no}, file: #{file}"
94
+ end
95
+
96
+ def raise(is_exit = true)
97
+ puts "** Error: #{self.message}".red
98
+ abort("") if is_exit
99
+ end
100
+
101
+ def self.raiseArr(list = nil, is_exit = true)
102
+ if !list.nil? && list.length > 0
103
+ puts "*** ParseLocalizedError ***".red
104
+ list.each do |err|
105
+ puts "#{err.message}".red
106
+ end
107
+ abort("") if is_exit
108
+ end
109
+ end
110
+
111
+ end
112
+
113
+ class InvalidKey < ParseLocalizedError
114
+ attr_accessor :key
115
+
116
+ def initialize(key, file, lang, row_no)
117
+ @key = key
118
+ @file = file
119
+ @lang = lang
120
+ @row_no = row_no
121
+ end
122
+
123
+ def message
124
+ "InvalidKey [#{key}] - #{self.msg}"
125
+ end
126
+ end
127
+
128
+ class WrongFormat < ParseLocalizedError;
129
+ def message
130
+ "WrongFormat - #{self.msg}"
131
+ end
132
+ end
133
+ class DuplicateKey < ParseLocalizedError
134
+ attr_accessor :key, :duplicate_rowno
135
+ def initialize(key, duplicate_rowno, file, lang, row_no)
136
+ @key = key
137
+ @duplicate_rowno = duplicate_rowno
138
+ @file = file
139
+ @lang = lang
140
+ @row_no = row_no
141
+ end
142
+
143
+ def message
144
+ "DuplicateKey [#{key}] - #{self.msg} : duplicateWithRow: #{duplicate_rowno}"
145
+ end
146
+ end
147
+ end
148
+ end
149
+ end
@@ -0,0 +1,61 @@
1
+ require File.expand_path('../platform.rb', __FILE__)
2
+ require File.expand_path('../lang.rb', __FILE__)
3
+ require 'pathname'
4
+
5
+ module Applocale
6
+ class FileUtil
7
+ @@dirname_main = "AppLocale"
8
+ @@dirname_ios = "IOS"
9
+ @@dirname_android = "Android"
10
+ @@filename_config = "AppLocaleFile.yaml"
11
+ @@filename_xlsx = "string.xlsx"
12
+
13
+ def self.filename_config
14
+ return @@filename_config
15
+ end
16
+
17
+ def self.mainFolderPathStr
18
+ pathstr = File.join(Dir.pwd, @@dirname_main)
19
+ Dir.mkdir pathstr unless File.exist?(pathstr)
20
+ return pathstr
21
+ end
22
+
23
+ def self.configFilePathStr
24
+ filename = @@filename_config
25
+ pathstr = File.join(self.mainFolderPathStr, filename)
26
+ return pathstr
27
+ end
28
+
29
+ def self.createConfigFileIfNeed(platform)
30
+ pathstr = self.configFilePathStr
31
+ self.createConfigFile(pathstr, platform) unless File.exist?(pathstr)
32
+ end
33
+
34
+ def self.defaultLocaleFileRelativePathStr(platform, lang)
35
+ if platform == Platform::IOS
36
+ dirname = @@dirname_ios
37
+ elsif platform == Platform::ANDROID
38
+ dirname = @@dirname_android
39
+ end
40
+ if !dirname.nil?
41
+ dirpathstr = File.join(self.mainFolderPathStr, dirname)
42
+ Dir.mkdir dirpathstr unless File.exist?(dirpathstr)
43
+ filename = Locale.filename(platform, lang)
44
+ filepathstr = File.join(dirpathstr, filename)
45
+ filepath = Pathname.new(filepathstr)
46
+ configfilepath = Pathname.new(File.dirname(self.configFilePathStr))
47
+ return filepath.relative_path_from(configfilepath).to_s
48
+ end
49
+ return nil
50
+ end
51
+
52
+ def self.defaultXlsxRelativePathStr
53
+ filename = @@filename_xlsx
54
+ pathstr = File.join(self.mainFolderPathStr, filename)
55
+ filepath = Pathname.new(pathstr)
56
+ configfilepath = Pathname.new(File.dirname(self.configFilePathStr))
57
+ return filepath.relative_path_from(configfilepath).to_s
58
+ end
59
+ end
60
+ end
61
+
@@ -0,0 +1,30 @@
1
+
2
+ module Applocale
3
+ module Locale
4
+ ZH_TW = :zh_TW
5
+ ZH_CN = :zh_CN
6
+ EN_US = :en_US
7
+ FILENAME_IOS = {Locale::ZH_CN => 'zh_CN.strings', Locale::ZH_TW => 'zh_TW.strings', Locale::EN_US => 'en_US.strings'}
8
+ FILENAME_ANDROID = {Locale::ZH_CN => 'values-zh-rCN', Locale::ZH_TW => 'values-zh-rTW', Locale::EN_US => 'values'}
9
+
10
+ def self.filename(devicemodel, locale)
11
+ if devicemodel == Platform::IOS
12
+ return !FILENAME_IOS[locale].nil? ? FILENAME_IOS[locale] : "#{locale}.strings"
13
+ elsif devicemodel == Platform::ANDROID
14
+ return File.join(FILENAME_ANDROID[locale],"strings.xml")
15
+ end
16
+ return nil
17
+ end
18
+
19
+ def self.init(langstring)
20
+ if langstring.upcase == 'ZH_TW'
21
+ return Locale::ZH_TW
22
+ elsif langstring.upcase == 'ZH_CN'
23
+ return Locale::ZH_CN
24
+ elsif langstring.upcase == 'EN_US'
25
+ return Locale::EN_US
26
+ end
27
+ return langstring
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,17 @@
1
+ module Applocale
2
+
3
+ module Platform
4
+ IOS = :ios
5
+ ANDROID = :Android
6
+
7
+ def self.init(platform)
8
+ if platform.upcase == "IOS"
9
+ return Platform::IOS
10
+ elsif platform.upcase == "ANDROID"
11
+ return Platform::ANDROID
12
+ end
13
+ return nil
14
+ end
15
+ end
16
+
17
+ end
@@ -0,0 +1,110 @@
1
+ require 'colorize'
2
+ require File.expand_path('../platform.rb', __FILE__)
3
+
4
+
5
+ module Applocale
6
+ class ValidKey
7
+ REGEX_KEYSTR_IOS = /\A[0-9a-zA-Z\_]+\z/
8
+
9
+ def self.isValidKey(platfrom, key)
10
+ return false if key.nil?
11
+ return false if key.strip == ""
12
+ result = !REGEX_KEYSTR_IOS.match(key).nil?
13
+ return result
14
+ end
15
+ end
16
+
17
+ class ContentUtil
18
+ REGEX_ESCAPED_QUOTE = /(?<!\\)(?:\\{2})*(\\")/
19
+ REGEX_NON_ESCAPE_QUOTE = /(?<!\\)(?:\\{2})*(")/
20
+
21
+ def self.removeEscape(platform, content)
22
+ if platform == Platform::IOS
23
+ return self.removeEscapedDoubleQuote(content)
24
+ elsif platform == Platform::ANDROID
25
+ return self.removeEscapedForAndroid(content)
26
+ end
27
+ return content
28
+ end
29
+
30
+ def self.addEscape(platform, content)
31
+ if platform == Platform::IOS
32
+ return self.addEscapedDoubleQuote(content)
33
+ elsif platform == Platform::ANDROID
34
+ return self.addEscapedForAndroid(content)
35
+ end
36
+ return content
37
+ end
38
+
39
+ def self.addEscapedForAndroid(content)
40
+ # \u \U \0 don't know
41
+ reg = /(?<!\\)((?:\\{2})+)*\\[c-eg-mo-qsw-zA-TW-Z!$%()*+,-.\/;:>\[\]^_`{|}~89]/
42
+ new_value = content.gsub(reg) {|match|
43
+ match.slice!(0)
44
+ match
45
+ }
46
+ reg = /(?<!\\)((?:\\{2})+)*(\\r)/
47
+ new_value = new_value.gsub(reg) {|match|
48
+ match.slice!(-1)
49
+ match + "n"
50
+ }
51
+ new_value = new_value.gsub(/&/, "&amp;")
52
+ new_value = new_value.gsub(/</, "&lt;")
53
+ # new_value = new_value.gsub(/>/, "&gt;")
54
+ return new_value
55
+ end
56
+
57
+ def self.removeEscapedForAndroid(content)
58
+ new_value = content.gsub(/&lt;/, "<")
59
+ new_value = new_value.gsub(/&amp;/, "&")
60
+ puts "test=#{content}==#{new_value}"
61
+ return new_value
62
+ end
63
+
64
+ def self.addEscapedDoubleQuote(content)
65
+ reg = /(?<!\\)((?:\\{2})+)"|(?<!\\)"|^"/
66
+ new_value = content.gsub(reg) {|match|
67
+ "\\" + match
68
+ }
69
+ return new_value
70
+ end
71
+
72
+ def self.removeEscapedDoubleQuote(content)
73
+ reg = /(?<!\\)((?:\\{2})+)*\\"/
74
+ new_value = content.gsub(reg) {|match|
75
+ match.slice!(0)
76
+ match
77
+ }
78
+ return new_value
79
+ end
80
+
81
+ end
82
+ end
83
+
84
+ # test = "aasb\\c"
85
+ # new = test.slice(-1)
86
+ # test.slice!(-2)
87
+ # puts test
88
+ # puts new
89
+
90
+ # ex = "\\"
91
+ # qu = "&"
92
+ #
93
+ # (0..10).each do |i|
94
+ # test = ([ex]*i).join("") + qu + "abcd" + ([ex]*i).join("") + qu + "def"
95
+ # puts "#{test}"
96
+ # puts Applocale::ContentUtil.addEscapedForAndroid(test)
97
+ # puts "------------------------------------"
98
+ # end
99
+
100
+
101
+ #
102
+ # #
103
+ # #
104
+ # # test = qu
105
+ # # test1 = ex + qu
106
+ # # test2 = ex + ex + qu
107
+ # # test3 = ex + ex + ex + qu
108
+ # # test4 = ex + ex + ex + ex + qu
109
+ # #
110
+ # # Applocale::ContentUtil.removeEscapeFroXlsx(test)
@@ -0,0 +1,3 @@
1
+ module Applocale
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,206 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: applocale
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Kennix Chui
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-05-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: activesupport
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '5.1'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5.1'
69
+ - !ruby/object:Gem::Dependency
70
+ name: thor
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.19.4
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.19.4
83
+ - !ruby/object:Gem::Dependency
84
+ name: google-api-client
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.11.1
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.11.1
97
+ - !ruby/object:Gem::Dependency
98
+ name: google_drive
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '2.1'
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: 2.1.3
107
+ type: :runtime
108
+ prerelease: false
109
+ version_requirements: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - "~>"
112
+ - !ruby/object:Gem::Version
113
+ version: '2.1'
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: 2.1.3
117
+ - !ruby/object:Gem::Dependency
118
+ name: colorize
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - "~>"
122
+ - !ruby/object:Gem::Version
123
+ version: 0.8.1
124
+ type: :runtime
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - "~>"
129
+ - !ruby/object:Gem::Version
130
+ version: 0.8.1
131
+ - !ruby/object:Gem::Dependency
132
+ name: rubyXL
133
+ requirement: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - "~>"
136
+ - !ruby/object:Gem::Version
137
+ version: '3.3'
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: 3.3.23
141
+ type: :runtime
142
+ prerelease: false
143
+ version_requirements: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - "~>"
146
+ - !ruby/object:Gem::Version
147
+ version: '3.3'
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ version: 3.3.23
151
+ description: It can convert file between string and xlsx, also support download xlsx
152
+ from google
153
+ email:
154
+ - kennixdev@gmail.com
155
+ executables:
156
+ - applocale
157
+ extensions: []
158
+ extra_rdoc_files: []
159
+ files:
160
+ - exe/applocale
161
+ - lib/applocale.rb
162
+ - lib/applocale/AppLocaleFile.yaml
163
+ - lib/applocale/Command/init.rb
164
+ - lib/applocale/Core/ParserStringFile/parse_localized_resource.rb
165
+ - lib/applocale/Core/ParserStringFile/parse_strings_file.rb
166
+ - lib/applocale/Core/ParserStringFile/parse_xml_file.rb
167
+ - lib/applocale/Core/client_secret.json
168
+ - lib/applocale/Core/convert_to_str_file.rb
169
+ - lib/applocale/Core/google_helper.rb
170
+ - lib/applocale/Core/init.rb
171
+ - lib/applocale/Core/parse_xlsx.rb
172
+ - lib/applocale/Core/parse_xlsx_module.rb
173
+ - lib/applocale/Core/setting.rb
174
+ - lib/applocale/Util/color_util.rb
175
+ - lib/applocale/Util/config_util.rb
176
+ - lib/applocale/Util/error_util.rb
177
+ - lib/applocale/Util/file_util.rb
178
+ - lib/applocale/Util/lang.rb
179
+ - lib/applocale/Util/platform.rb
180
+ - lib/applocale/Util/regex_util.rb
181
+ - lib/applocale/version.rb
182
+ homepage: https://github.com/kennix426/applocale
183
+ licenses:
184
+ - MIT
185
+ metadata: {}
186
+ post_install_message:
187
+ rdoc_options: []
188
+ require_paths:
189
+ - lib
190
+ required_ruby_version: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ required_rubygems_version: !ruby/object:Gem::Requirement
196
+ requirements:
197
+ - - ">="
198
+ - !ruby/object:Gem::Version
199
+ version: '0'
200
+ requirements: []
201
+ rubyforge_project:
202
+ rubygems_version: 2.6.11
203
+ signing_key:
204
+ specification_version: 4
205
+ summary: for mobile application to manage locale
206
+ test_files: []