applocale 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,56 +4,56 @@ require 'pathname'
4
4
 
5
5
  module Applocale
6
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"
7
+ DIRNAME_MAIN = 'AppLocale'
8
+ DIRNAME_IOS = 'IOS'
9
+ DIRNAME_ANDROID = 'Android'
10
+ FILENAME_CONFIG = 'AppLocaleFile.yaml'
11
+ FILENAME_XLSX = 'string.xlsx'
12
12
 
13
13
  def self.filename_config
14
- return @@filename_config
14
+ return FILENAME_CONFIG
15
15
  end
16
16
 
17
- def self.mainFolderPathStr
18
- pathstr = File.join(Dir.pwd, @@dirname_main)
17
+ def self.mainfolder_pathstr
18
+ pathstr = File.join(Dir.pwd, DIRNAME_MAIN)
19
19
  Dir.mkdir pathstr unless File.exist?(pathstr)
20
20
  return pathstr
21
21
  end
22
22
 
23
- def self.configFilePathStr
24
- filename = @@filename_config
25
- pathstr = File.join(self.mainFolderPathStr, filename)
23
+ def self.configfile_pathstr
24
+ filename = FILENAME_CONFIG
25
+ pathstr = File.join(self.mainfolder_pathstr, filename)
26
26
  return pathstr
27
27
  end
28
+ #
29
+ # def self.create_configfile_ifneed(platform)
30
+ # pathstr = self.configfile_pathstr
31
+ # ConfigUtil.create_configfile(platform, pathstr) unless File.exist?(pathstr)
32
+ # end
28
33
 
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)
34
+ def self.get_default_localefile_relative_pathstr(platform, lang)
35
35
  if platform == Platform::IOS
36
- dirname = @@dirname_ios
36
+ dirname = DIRNAME_IOS
37
37
  elsif platform == Platform::ANDROID
38
- dirname = @@dirname_android
38
+ dirname = DIRNAME_ANDROID
39
39
  end
40
- if !dirname.nil?
41
- dirpathstr = File.join(self.mainFolderPathStr, dirname)
40
+ unless dirname.nil?
41
+ dirpathstr = File.join(self.mainfolder_pathstr, dirname)
42
42
  Dir.mkdir dirpathstr unless File.exist?(dirpathstr)
43
43
  filename = Locale.filename(platform, lang)
44
44
  filepathstr = File.join(dirpathstr, filename)
45
45
  filepath = Pathname.new(filepathstr)
46
- configfilepath = Pathname.new(File.dirname(self.configFilePathStr))
46
+ configfilepath = Pathname.new(File.dirname(self.configfile_pathstr))
47
47
  return filepath.relative_path_from(configfilepath).to_s
48
48
  end
49
49
  return nil
50
50
  end
51
51
 
52
- def self.defaultXlsxRelativePathStr
53
- filename = @@filename_xlsx
54
- pathstr = File.join(self.mainFolderPathStr, filename)
52
+ def self.get_default_xlsx_relativepath_str
53
+ filename = FILENAME_XLSX
54
+ pathstr = File.join(self.mainfolder_pathstr, filename)
55
55
  filepath = Pathname.new(pathstr)
56
- configfilepath = Pathname.new(File.dirname(self.configFilePathStr))
56
+ configfilepath = Pathname.new(File.dirname(self.configfile_pathstr))
57
57
  return filepath.relative_path_from(configfilepath).to_s
58
58
  end
59
59
  end
@@ -11,7 +11,7 @@ module Applocale
11
11
  if devicemodel == Platform::IOS
12
12
  return !FILENAME_IOS[locale].nil? ? FILENAME_IOS[locale] : "#{locale}.strings"
13
13
  elsif devicemodel == Platform::ANDROID
14
- return File.join(FILENAME_ANDROID[locale],"strings.xml")
14
+ return File.join(FILENAME_ANDROID[locale],'strings.xml')
15
15
  end
16
16
  return nil
17
17
  end
@@ -5,13 +5,28 @@ module Applocale
5
5
  ANDROID = :Android
6
6
 
7
7
  def self.init(platform)
8
- if platform.upcase == "IOS"
8
+ if platform.upcase == 'IOS'
9
9
  return Platform::IOS
10
- elsif platform.upcase == "ANDROID"
10
+ elsif platform.upcase == 'ANDROID'
11
11
  return Platform::ANDROID
12
12
  end
13
13
  return nil
14
14
  end
15
+
16
+ def self.is_valid_path(platform, path)
17
+ newpath = path.to_s.strip
18
+ extn = File.extname newpath
19
+ if platform == Platform::IOS
20
+ if extn.downcase == '.strings'
21
+ return true
22
+ end
23
+ elsif platform == Platform::ANDROID
24
+ if extn.downcase == '.xml'
25
+ return true
26
+ end
27
+ end
28
+ return false
29
+ end
15
30
  end
16
31
 
17
32
  end
@@ -4,11 +4,11 @@ require File.expand_path('../platform.rb', __FILE__)
4
4
 
5
5
  module Applocale
6
6
  class ValidKey
7
- REGEX_KEYSTR_IOS = /\A[0-9a-zA-Z\_]+\z/
7
+ REGEX_KEYSTR_IOS = /\A[0-9a-zA-Z_]+\z/
8
8
 
9
- def self.isValidKey(platfrom, key)
9
+ def self.is_validkey(platfrom, key)
10
10
  return false if key.nil?
11
- return false if key.strip == ""
11
+ return false if key.strip.length <= 0
12
12
  result = !REGEX_KEYSTR_IOS.match(key).nil?
13
13
  return result
14
14
  end
@@ -18,25 +18,25 @@ module Applocale
18
18
  REGEX_ESCAPED_QUOTE = /(?<!\\)(?:\\{2})*(\\")/
19
19
  REGEX_NON_ESCAPE_QUOTE = /(?<!\\)(?:\\{2})*(")/
20
20
 
21
- def self.removeEscape(platform, content)
21
+ def self.remove_escape(platform, content)
22
22
  if platform == Platform::IOS
23
- return self.removeEscapedDoubleQuote(content)
23
+ return self.remove_escaped_double_quote(content)
24
24
  elsif platform == Platform::ANDROID
25
- return self.removeEscapedForAndroid(content)
25
+ return self.remove_escaped_android(content)
26
26
  end
27
27
  return content
28
28
  end
29
29
 
30
- def self.addEscape(platform, content)
30
+ def self.add_escape(platform, content)
31
31
  if platform == Platform::IOS
32
- return self.addEscapedDoubleQuote(content)
32
+ return self.add_escaped_double_quote(content)
33
33
  elsif platform == Platform::ANDROID
34
- return self.addEscapedForAndroid(content)
34
+ return self.add_escaped_android(content)
35
35
  end
36
36
  return content
37
37
  end
38
38
 
39
- def self.addEscapedForAndroid(content)
39
+ def self.add_escaped_android(content)
40
40
  # \u \U \0 don't know
41
41
  reg = /(?<!\\)((?:\\{2})+)*\\[c-eg-mo-qsw-zA-TW-Z!$%()*+,-.\/;:>\[\]^_`{|}~89]/
42
42
  new_value = content.gsub(reg) {|match|
@@ -46,22 +46,22 @@ module Applocale
46
46
  reg = /(?<!\\)((?:\\{2})+)*(\\r)/
47
47
  new_value = new_value.gsub(reg) {|match|
48
48
  match.slice!(-1)
49
- match + "n"
49
+ match + 'n'
50
50
  }
51
- new_value = new_value.gsub(/&/, "&amp;")
52
- new_value = new_value.gsub(/</, "&lt;")
51
+ new_value = new_value.gsub(/&/, '&amp;')
52
+ new_value = new_value.gsub(/</, '&lt;')
53
53
  # new_value = new_value.gsub(/>/, "&gt;")
54
54
  return new_value
55
55
  end
56
56
 
57
- def self.removeEscapedForAndroid(content)
58
- new_value = content.gsub(/&lt;/, "<")
59
- new_value = new_value.gsub(/&amp;/, "&")
57
+ def self.remove_escaped_android(content)
58
+ new_value = content.gsub(/&lt;/, '<')
59
+ new_value = new_value.gsub(/&amp;/, '&')
60
60
  puts "test=#{content}==#{new_value}"
61
61
  return new_value
62
62
  end
63
63
 
64
- def self.addEscapedDoubleQuote(content)
64
+ def self.add_escaped_double_quote(content)
65
65
  reg = /(?<!\\)((?:\\{2})+)"|(?<!\\)"|^"/
66
66
  new_value = content.gsub(reg) {|match|
67
67
  "\\" + match
@@ -69,7 +69,7 @@ module Applocale
69
69
  return new_value
70
70
  end
71
71
 
72
- def self.removeEscapedDoubleQuote(content)
72
+ def self.remove_escaped_double_quote(content)
73
73
  reg = /(?<!\\)((?:\\{2})+)*\\"/
74
74
  new_value = content.gsub(reg) {|match|
75
75
  match.slice!(0)
@@ -1,3 +1,3 @@
1
1
  module Applocale
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: applocale
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kennix
@@ -161,17 +161,17 @@ files:
161
161
  - lib/applocale.rb
162
162
  - lib/applocale/AppLocaleFile.yaml
163
163
  - lib/applocale/Command/init.rb
164
+ - lib/applocale/Core/Compare/compare_xlsx_str.rb
165
+ - lib/applocale/Core/GoogleHepler/client_secret.json
166
+ - lib/applocale/Core/GoogleHepler/google_helper.rb
167
+ - lib/applocale/Core/ParseXLSX/parse_xlsx.rb
168
+ - lib/applocale/Core/ParseXLSX/parse_xlsx_module.rb
164
169
  - lib/applocale/Core/ParserStringFile/parse_localized_resource.rb
165
170
  - lib/applocale/Core/ParserStringFile/parse_strings_file.rb
166
171
  - 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
172
+ - lib/applocale/Core/convert_to_localefile.rb
170
173
  - lib/applocale/Core/init.rb
171
- - lib/applocale/Core/parse_xlsx.rb
172
- - lib/applocale/Core/parse_xlsx_module.rb
173
174
  - lib/applocale/Core/setting.rb
174
- - lib/applocale/Util/color_util.rb
175
175
  - lib/applocale/Util/config_util.rb
176
176
  - lib/applocale/Util/error_util.rb
177
177
  - lib/applocale/Util/file_util.rb
@@ -1,166 +0,0 @@
1
- require File.expand_path('../setting.rb', __FILE__)
2
- require File.expand_path('../parse_xlsx_module.rb', __FILE__)
3
- require File.expand_path('../../Util/error_util.rb', __FILE__)
4
- require File.expand_path('../../Util/color_util.rb', __FILE__)
5
- require File.expand_path('../../Util/regex_util.rb', __FILE__)
6
-
7
- require 'rubyXL'
8
-
9
-
10
- module Applocale
11
- class ParseXLSX
12
-
13
- @xlsx = nil
14
- @sheetcontent_list = nil
15
- @allError = nil
16
- @setting = Setting
17
-
18
- def initialize()
19
- @setting = Setting
20
- puts "Start to Parse XLSX: \"#{@setting.xlsxpath}\" ...".green
21
- # @xlsx = Roo::Spreadsheet.open(@@setting.xlsxpath)
22
- @sheetcontent_list = Array.new
23
- @allKeyDict = {}
24
- @allError = Array.new
25
-
26
- self.parse()
27
- end
28
-
29
- def result
30
- return @sheetcontent_list
31
- end
32
-
33
- def parse()
34
-
35
- workbook = RubyXL::Parser.parse(@setting.xlsxpath)
36
- workbook.worksheets.each do |worksheet|
37
- sheetName = worksheet.sheet_name
38
- sheetcontent = ParseXLSXModule::SheetContent.new(sheetName)
39
-
40
- rowno = -1
41
- worksheet.each {|row|
42
- rowno += 1
43
- # colno = 0
44
- next if row.nil?
45
- cells = row && row.cells
46
- if sheetcontent.header_rowno.nil?
47
- headerinfo = findHeader(cells)
48
- if !headerinfo.nil?
49
- sheetcontent.header_rowno = rowno
50
- sheetcontent.keyStrWithColNo = headerinfo[:keystr_colno]
51
- sheetcontent.langWithColNo_list = headerinfo[:lang_colno]
52
- end
53
- else
54
- begin
55
- rowcontent = parseRow(sheetName, rowno, worksheet.sheet_data[rowno], sheetcontent.keyStrWithColNo, sheetcontent.langWithColNo_list)
56
- if !rowcontent.nil?
57
- prev_rowcontent = @allKeyDict[rowcontent.key_str.downcase]
58
- if prev_rowcontent.nil?
59
- @allKeyDict[rowcontent.key_str.downcase] = rowcontent
60
- sheetcontent.rowinfo_list.push(rowcontent)
61
- else
62
- error = ErrorUtil::ParseXlsxError::ErrorDuplicateKey.new(rowcontent, "duplicate with sheet '#{prev_rowcontent.sheetname}' row '#{prev_rowcontent.rowno}'")
63
- @allError.push(error)
64
- end
65
- end
66
- rescue ErrorUtil::ParseXlsxError::ParseError => e
67
- @allError.push(e)
68
-
69
- end
70
- end
71
- }
72
- if sheetcontent.header_rowno.nil?
73
- ErrorUtil::ParseXlsxError::HeadeNotFoundError.new("Header not found in sheet: #{sheetName}").to_warn
74
- end
75
- @sheetcontent_list.push(sheetcontent)
76
- end
77
- if @allError.length > 0
78
- ErrorUtil::ParseXlsxError::ParseError.raiseArr(@allError)
79
- end
80
-
81
- end
82
-
83
- def parseRow(sheetname, rowno, cells, keyStrWithColNo, langWithColNo_list)
84
- begin
85
- cell = cells[keyStrWithColNo.colno]
86
- val = cell && cell.value
87
- keystr = toValueKey(val)
88
- rescue ErrorUtil::ParseXlsxError::ErrorInValidKey => e
89
- e.rowinfo.sheetname = sheetname
90
- e.rowinfo.rowno = rowno
91
- raise e
92
- end
93
-
94
- if !keystr.nil?
95
- rowinfo = ParseXLSXModule::RowInfo.new(sheetname, rowno, keystr)
96
- for k in 0..langWithColNo_list.length-1
97
- langWithColNo = langWithColNo_list[k]
98
- cell = cells[langWithColNo.colno]
99
- val = cell && cell.value
100
- cell_value = val.to_s
101
- lang_name = langWithColNo.lang
102
- rowinfo.content_dict[lang_name] = convertContect(cell_value)
103
- end
104
- return rowinfo
105
- end
106
- return nil
107
- end
108
-
109
- def toValueKey(value)
110
- if !value.nil? && value != ""
111
- new_value = value.to_s
112
- if ValidKey.isValidKey(@setting.platform, new_value)
113
- return new_value
114
- else
115
- rowinfo = ParseXLSXModule::RowInfo.new(nil, nil, value)
116
- raise ErrorUtil::ParseXlsxError::ErrorInValidKey.new(rowinfo, "Invaild Key: #{value}")
117
- end
118
- end
119
- return nil
120
- end
121
-
122
- def convertContect(cell_value)
123
- if cell_value.nil?
124
- return ""
125
- else
126
- return ContentUtil.addEscapedDoubleQuote(cell_value)
127
- end
128
- end
129
-
130
- def findHeader(cells)
131
- keyStrWithColNo = nil
132
- langWithColNo_list = Array.new()
133
- k_header_lang_dict = []
134
- colno = 0
135
- cells.each{ |cell|
136
- value = cell && cell.value
137
- if !value.nil?
138
- if value == @setting.keystr && keyStrWithColNo.nil?
139
- keyStrWithColNo = ParseXLSXModule::KeyStrWithColNo.new(value, colno)
140
- else
141
- @setting.langlist.each do |lang, info|
142
- if value == info[:xlsheader] && k_header_lang_dict.index(lang).nil?
143
- langWithColNo_list.push(ParseXLSXModule::LangWithColNo.new(info[:xlsheader], lang, colno))
144
- k_header_lang_dict.push(lang)
145
- end
146
- end
147
- end
148
- end
149
- colno += 1
150
- }
151
-
152
- allPass = true
153
- for i in 0..langWithColNo_list.length-1
154
- if langWithColNo_list[i].nil?
155
- allPass = false
156
- break
157
- end
158
- end
159
- if !keyStrWithColNo.nil? && langWithColNo_list.length == @setting.langlist.length
160
- return {:keystr_colno => keyStrWithColNo, :lang_colno => langWithColNo_list}
161
- end
162
- return nil
163
- end
164
-
165
- end
166
- end
@@ -1,28 +0,0 @@
1
- require 'colorize'
2
-
3
-
4
- # class String
5
- # def black; "\e[30m#{self}\e[0m" end
6
- # def red; "\e[31m#{self}\e[0m" end
7
- # def green; "\e[32m#{self}\e[0m" end
8
- # def brown; "\e[33m#{self}\e[0m" end
9
- # def blue; "\e[34m#{self}\e[0m" end
10
- # def magenta; "\e[35m#{self}\e[0m" end
11
- # def cyan; "\e[36m#{self}\e[0m" end
12
- # def gray; "\e[37m#{self}\e[0m" end
13
- #
14
- # def bg_black; "\e[40m#{self}\e[0m" end
15
- # def bg_red; "\e[41m#{self}\e[0m" end
16
- # def bg_green; "\e[42m#{self}\e[0m" end
17
- # def bg_brown; "\e[43m#{self}\e[0m" end
18
- # def bg_blue; "\e[44m#{self}\e[0m" end
19
- # def bg_magenta; "\e[45m#{self}\e[0m" end
20
- # def bg_cyan; "\e[46m#{self}\e[0m" end
21
- # def bg_gray; "\e[47m#{self}\e[0m" end
22
- #
23
- # def bold; "\e[1m#{self}\e[22m" end
24
- # def italic; "\e[3m#{self}\e[23m" end
25
- # def underline; "\e[4m#{self}\e[24m" end
26
- # def blink; "\e[5m#{self}\e[25m" end
27
- # def reverse_color; "\e[7m#{self}\e[27m" end
28
- # end