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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 31a7dcd314ffff0b048da49dec9ce0535d8002c0
4
- data.tar.gz: 181e9f985cfe69505f9ce1863945472a1f5a65d0
3
+ metadata.gz: 9d8869b79798773984196bbfc33f3358f9c52e50
4
+ data.tar.gz: aaab67885d67212dc783ed7be4560e3549739315
5
5
  SHA512:
6
- metadata.gz: 85ef2622d09a3a69c3130ba330e1ad3d320b7e701077e7d702e9d4e15a2f6172cb9a527b445f69194c5797b906fe40cb8c0ce79753272b44e7e37010b2e5f753
7
- data.tar.gz: a7db380a93dde08008a3a45951c7b60bf780fad3c1c2cd5549fdd9a006a5d544a8fdcf37a83178979b08455fd3e770c4c73ab574ddbe064b0d9507f428dd32af
6
+ metadata.gz: 0f6ee6f3cde1bcc235fb7cb6eefb042ad54bdb711921212f925e0f7ac978bd6066110d031b5da420ea486438dc173046b66128f3dd8d782b5941a113a93703e7
7
+ data.tar.gz: 81d2a69a19d328b2b9568783d9ce436d491eb4bdf25930febebc054795dd4efb7a809736ec20779e2eeda8f273730549ec7871f1dadeae73c9c11707a7dd0cf8
@@ -4,6 +4,7 @@ require File.expand_path('../../Util/error_util.rb', __FILE__)
4
4
  require File.expand_path('../../Core/setting.rb', __FILE__)
5
5
  require File.expand_path('../../Core/init.rb', __FILE__)
6
6
  require File.expand_path('../../Core/ParserStringFile/parse_localized_resource.rb', __FILE__)
7
+ require File.expand_path('../../version', __FILE__)
7
8
 
8
9
  require 'thor'
9
10
 
@@ -30,7 +31,7 @@ module Applocale
30
31
  self.class.help(shell)
31
32
  ErrorUtil::CommandError.new("Invalid [platform] : ios | android ").raise
32
33
  else
33
- ConfigUtil.createConfigFileIfNeed(platformsybom)
34
+ ConfigUtil.create_configfile_ifneed(platformsybom)
34
35
  end
35
36
  end
36
37
 
@@ -38,19 +39,23 @@ module Applocale
38
39
  option :local, :desc => "Convert local xlsx file to localization string file"
39
40
  def update()
40
41
  is_local = !options[:local].nil?
41
- puts is_local
42
- ConfigUtil.loadAndValidateForXlsxToStringFile(false)
42
+ ConfigUtil.load_and_validate_xlsx_to_localefile(is_local)
43
43
  Setting.printlog
44
- Applocale.start(is_local, Applocale::Setting)
44
+ Applocale.start_update(is_local, Applocale::Setting)
45
45
  end
46
46
 
47
47
  desc "reverse", "Convert localization string file to xlsx"
48
48
  option :skip, :desc => "Skip Error"
49
49
  def reverse()
50
50
  is_skip = !options[:skip].nil?
51
- ConfigUtil.loadAndValidateForStringFileToXlsx()
51
+ ConfigUtil.load_and_validate_localefile_to_xlsx()
52
52
  Setting.printlog
53
- Applocale::ParseLocalizedResource.new(is_skip)
53
+ Applocale::start_reverse(is_skip)
54
+ end
55
+
56
+ desc "version", "show the AppLocale verions"
57
+ def version()
58
+ puts Applocale::VERSION
54
59
  end
55
60
 
56
61
  end
@@ -0,0 +1,2 @@
1
+ class CompareXlsxStr
2
+ end
@@ -3,9 +3,9 @@ require 'googleauth'
3
3
  require 'googleauth/stores/file_token_store'
4
4
  require 'google/apis/sheets_v4'
5
5
  require 'fileutils'
6
- require File.expand_path('../../Util/file_util.rb', __FILE__)
7
- require File.expand_path('../../Util/color_util.rb', __FILE__)
8
- require File.expand_path('../../Util/error_util.rb', __FILE__)
6
+ require 'colorize'
7
+ require File.expand_path('../../../Util/file_util.rb', __FILE__)
8
+ require File.expand_path('../../../Util/error_util.rb', __FILE__)
9
9
 
10
10
  module Applocale
11
11
 
@@ -14,10 +14,10 @@ module Applocale
14
14
  APPLICATION_NAME = 'AppLocale'
15
15
  CLIENT_SECRETS_PATH = 'client_secret.json'
16
16
  CREDENTIALS_PATH = File.join(Dir.home, '.applan_credentials',
17
- "drive-ruby-applocale.yaml")
17
+ 'drive-ruby-applocale.yaml')
18
18
  SCOPE = [Google::Apis::DriveV3::AUTH_DRIVE_METADATA_READONLY, Google::Apis::DriveV3::AUTH_DRIVE, Google::Apis::DriveV3::AUTH_DRIVE_FILE]
19
19
 
20
- def self.isGoogleLink(link)
20
+ def self.is_googlelink(link)
21
21
  if !link.nil? && link.length > 0
22
22
  if link.match(/https:\/\/docs.google.com\/spreadsheets\/d\/([^\/]*)/i)
23
23
  if $1.length > 0
@@ -27,18 +27,22 @@ module Applocale
27
27
  end
28
28
  end
29
29
 
30
- def self.downloadSpreadSheet(spreadSheetId, filename)
31
- puts "Start download from google, fileId: #{spreadSheetId} ...".green
30
+ def self.download_spreadsheet(spreadsheet_Id, filename)
31
+ puts "Start download from google, fileId: #{spreadsheet_Id} ...".green
32
32
  service = Google::Apis::DriveV3::DriveService.new
33
33
  service.client_options.application_name = APPLICATION_NAME
34
34
  service.authorization = self.authorize
35
- content = service.export_file(spreadSheetId,
36
- 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
37
- download_dest: filename)
38
- if File.exist? filename
39
- puts "Download from google finished".green
40
- else
41
- ErrorUtil::DownloadXlsxError.new("Cannot download from google").raise
35
+ begin
36
+ content = service.export_file(spreadsheet_Id,
37
+ 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
38
+ download_dest: filename)
39
+ if File.exist? filename
40
+ puts 'Download from google finished'.green
41
+ else
42
+ ErrorUtil::DownloadFromGoogleFail.new.raise
43
+ end
44
+ rescue
45
+ ErrorUtil::DownloadFromGoogleFail.new.raise
42
46
  end
43
47
  end
44
48
 
@@ -55,8 +59,8 @@ module Applocale
55
59
  if credentials.nil?
56
60
  url = authorizer.get_authorization_url(
57
61
  base_url: OOB_URI)
58
- puts "!!! Open the following URL in the browser and enter the ".red +
59
- "resulting code after authorization:".red
62
+ puts '!!! Open the following URL in the browser and enter the '.red +
63
+ 'resulting code after authorization:'.red
60
64
  puts url.blue.on_white
61
65
  code = STDIN.gets.chomp
62
66
  credentials = authorizer.get_and_store_credentials_from_code(
@@ -0,0 +1,155 @@
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/regex_util.rb', __FILE__)
5
+
6
+ require 'rubyXL'
7
+ require 'colorize'
8
+
9
+ module Applocale
10
+ class ParseXLSX
11
+
12
+ @xlsx = nil
13
+ @sheetcontent_list = nil
14
+ @allkey_dict = {}
15
+ @all_error = nil
16
+ @setting = Setting
17
+
18
+ def initialize
19
+ @setting = Setting
20
+ puts "Start to Parse XLSX: \"#{@setting.xlsxpath}\" ...".green
21
+ @sheetcontent_list = Array.new
22
+ @allkey_dict = {}
23
+ @all_error = Array.new
24
+ self.parse
25
+ end
26
+
27
+ def result
28
+ return @sheetcontent_list
29
+ end
30
+
31
+ def parse
32
+ begin
33
+ workbook = RubyXL::Parser.parse(@setting.xlsxpath)
34
+ rescue
35
+ ErrorUtil::CannotOpenXlsxFile.new(@setting.xlsxpath).raise
36
+ end
37
+ workbook.worksheets.each do |worksheet|
38
+ sheetname = worksheet.sheet_name
39
+ sheetcontent = ParseXLSXModule::SheetContent.new(sheetname)
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 = find_header(cells)
48
+ unless headerinfo.nil?
49
+ sheetcontent.header_rowno = rowno
50
+ sheetcontent.keyStr_with_colno = headerinfo[:keystr_colno]
51
+ sheetcontent.lang_with_colno_list = headerinfo[:lang_colno]
52
+ end
53
+ else
54
+ begin
55
+ rowcontent = parse_row(sheetname, rowno, worksheet.sheet_data[rowno], sheetcontent.keyStr_with_colno, sheetcontent.lang_with_colno_list)
56
+ unless rowcontent.nil?
57
+ prev_rowcontent = @allkey_dict[rowcontent.key_str.downcase]
58
+ if prev_rowcontent.nil?
59
+ @allkey_dict[rowcontent.key_str.downcase] = rowcontent
60
+ sheetcontent.rowinfo_list.push(rowcontent)
61
+ else
62
+ error = ErrorUtil::ParseXlsxError::DuplicateKey.new(rowcontent, prev_rowcontent.sheetname, prev_rowcontent.rowno)
63
+ @all_error.push(error)
64
+ end
65
+ end
66
+ rescue ErrorUtil::ParseXlsxError::ParseError => e
67
+ @all_error.push(e)
68
+
69
+ end
70
+ end
71
+ }
72
+ if sheetcontent.header_rowno.nil?
73
+ ErrorUtil::ParseXlsxError::HeadeNotFound.new(sheetname).to_warn
74
+ end
75
+ @sheetcontent_list.push(sheetcontent)
76
+ end
77
+ if @all_error.length > 0
78
+ ErrorUtil::ParseXlsxError::ParseError.raiseArr(@all_error)
79
+ end
80
+
81
+ end
82
+
83
+ def parse_row(sheetname, rowno, cells, keystr_with_colno, lang_with_colno_list)
84
+ begin
85
+ cell = cells[keystr_with_colno.colno]
86
+ val = cell && cell.value
87
+ keystr = to_value_key(val)
88
+ rescue ErrorUtil::ParseXlsxError::InValidKey => e
89
+ e.rowinfo.sheetname = sheetname
90
+ e.rowinfo.rowno = rowno
91
+ raise e
92
+ end
93
+
94
+ unless keystr.nil?
95
+ rowinfo = ParseXLSXModule::RowInfo.new(sheetname, rowno, keystr)
96
+ (0..lang_with_colno_list.length-1).each do |k|
97
+ lang_with_colno = lang_with_colno_list[k]
98
+ cell = cells[lang_with_colno.colno]
99
+ val = cell && cell.value
100
+ cell_value = val.to_s
101
+ lang_name = lang_with_colno.lang
102
+ rowinfo.content_dict[lang_name] = convert_contect(cell_value)
103
+ end
104
+ return rowinfo
105
+ end
106
+ end
107
+
108
+ def to_value_key(value)
109
+ if !value.nil? && value != ''
110
+ new_value = value.to_s
111
+ if ValidKey.is_validkey(@setting.platform, new_value)
112
+ return new_value
113
+ else
114
+ rowinfo = ParseXLSXModule::RowInfo.new(nil, nil, value)
115
+ raise ErrorUtil::ParseXlsxError::InValidKey.new(rowinfo)
116
+ end
117
+ end
118
+ end
119
+
120
+ def convert_contect(cell_value)
121
+ if cell_value.nil?
122
+ return ''
123
+ else
124
+ return ContentUtil.add_escaped_double_quote(cell_value)
125
+ end
126
+ end
127
+
128
+ def find_header(cells)
129
+ keystr_with_colno = nil
130
+ lang_with_colno_list = Array.new
131
+ k_header_lang_dict = []
132
+ colno = 0
133
+ cells.each{ |cell|
134
+ value = cell && cell.value
135
+ unless value.nil?
136
+ if value == @setting.keystr && keystr_with_colno.nil?
137
+ keystr_with_colno = ParseXLSXModule::KeyStrWithColNo.new(value, colno)
138
+ else
139
+ @setting.langlist.each do |lang, info|
140
+ if value == info[:xlsheader] && k_header_lang_dict.index(lang).nil?
141
+ lang_with_colno_list.push(ParseXLSXModule::LangWithColNo.new(info[:xlsheader], lang, colno))
142
+ k_header_lang_dict.push(lang)
143
+ end
144
+ end
145
+ end
146
+ end
147
+ colno += 1
148
+ }
149
+ if !keystr_with_colno.nil? && lang_with_colno_list.length == @setting.langlist.length
150
+ return {:keystr_colno => keystr_with_colno, :lang_colno => lang_with_colno_list}
151
+ end
152
+ end
153
+
154
+ end
155
+ end
@@ -2,41 +2,40 @@ module Applocale
2
2
 
3
3
  module ParseXLSXModule
4
4
  class SheetContent
5
- attr_accessor :sheetname, :header_rowno, :keyStrWithColNo, :langWithColNo_list, :rowinfo_list, :comment
5
+ attr_accessor :sheetname, :header_rowno, :keyStr_with_colno, :lang_with_colno_list, :rowinfo_list, :comment
6
6
 
7
7
  def initialize(sheetname)
8
8
  self.sheetname = sheetname
9
- self.rowinfo_list = Array.new()
10
- self.langWithColNo_list = Array.new()
9
+ self.rowinfo_list = Array.new
10
+ self.lang_with_colno_list = Array.new
11
11
  self.comment = sheetname
12
12
  end
13
13
 
14
- def getRowInfoSortByKey()
14
+ def get_rowInfo_sortby_key
15
15
  return self.rowinfo_list.sort_by { |obj| obj.key_str.to_s }
16
16
  end
17
17
 
18
- def getRowInfoSortByRowNo()
18
+ def get_rowInfo_sortby_rowno
19
19
  return self.rowinfo_list.sort_by { |obj| obj.rowno.to_i }
20
20
  end
21
21
 
22
22
  def to_s
23
- str_keyStrWithColNo = ""
24
- if !keyStrWithColNo.nil?
25
- str_keyStrWithColNo = "\n\t#{keyStrWithColNo.to_s}"
23
+ str_keyStr_with_colno = ''
24
+ unless keyStr_with_colno.nil?
25
+ str_keyStr_with_colno = "\n\t#{keyStr_with_colno.to_s}"
26
26
  end
27
- str_langWithColNo_list = ""
28
- self.langWithColNo_list.each do |langWithColNo|
29
- str_langWithColNo_list += "\n\t#{langWithColNo.to_s}"
27
+ str_lang_with_colno_list = ''
28
+ self.lang_with_colno_list.each do |langWithColNo|
29
+ str_lang_with_colno_list += "\n\t#{langWithColNo.to_s}"
30
30
  end
31
- str_contentlist = "\n"
32
- self.getRowInfoSortByRowNo().each do |value|
31
+ str_contentlist = '\n'
32
+ self.get_rowInfo_sortby_rowno.each do |value|
33
33
  str_contentlist += "\t #{value.to_s}\n"
34
34
  end
35
-
36
35
  "sheetname = #{sheetname}\n" +
37
36
  "header_rowno = #{header_rowno}\n" +
38
- "keyStrWithColNo = #{str_keyStrWithColNo}\n" +
39
- "langWithColNo_list = #{str_langWithColNo_list}\n" +
37
+ "keyStrWithColNo = #{str_keyStr_with_colno}\n" +
38
+ "langWithColNo_list = #{str_lang_with_colno_list}\n" +
40
39
  "rowinfo_list = #{str_contentlist}"
41
40
  end
42
41
  end
@@ -53,7 +52,7 @@ module Applocale
53
52
  end
54
53
 
55
54
  def to_s
56
- "sheetname = #{sheetname}, rowno = #{rowno}, key_str = #{key_str}, content_dict = #{content_dict}"
55
+ "sheetname = #{sheetname}, rowno = #{rowno+1}, key_str = #{key_str}, content_dict = #{content_dict}"
57
56
  end
58
57
 
59
58
  end
@@ -68,7 +67,7 @@ module Applocale
68
67
  end
69
68
 
70
69
  def to_s
71
- "{header_str => #{header_str}, colno => #{colno}}"
70
+ "{header_str => #{header_str}, colno => #{colno+1}}"
72
71
  end
73
72
 
74
73
  end
@@ -83,8 +82,9 @@ module Applocale
83
82
  end
84
83
 
85
84
  def to_s
86
- "{header_str => #{header_str}, lang => #{lang}, colno => #{colno}}"
85
+ "{header_str => #{header_str}, lang => #{lang}, colno => #{colno+1}}"
87
86
  end
87
+
88
88
  end
89
89
 
90
90
  end
@@ -1,71 +1,58 @@
1
1
  require File.expand_path('../../setting.rb', __FILE__)
2
2
  require File.expand_path('../../../Util/platform.rb', __FILE__)
3
- require File.expand_path('../../parse_xlsx_module', __FILE__)
4
- require File.expand_path('../../../Util/color_util.rb', __FILE__)
3
+ require File.expand_path('../../ParseXLSX/parse_xlsx_module', __FILE__)
5
4
  require File.expand_path('../parse_strings_file', __FILE__)
6
5
  require File.expand_path('../parse_xml_file', __FILE__)
7
6
 
8
7
  require 'rubyXL'
8
+ require 'colorize'
9
9
 
10
10
  module Applocale
11
11
  class ParseLocalizedResource
12
-
13
- # @xlsx = nil
14
-
15
12
  @skip_error = false
16
13
  @setting = Setting
17
- # @xlsx = RubyXL::Workbook
18
- # @allError = Array
19
- # @sheetcontent_list = Array
20
14
 
21
15
  def initialize(skip_error = false)
22
16
  @skip_error = skip_error
23
17
  @setting = Setting
24
-
25
18
  FileUtils.mkdir_p(File.dirname(@setting.xlsxpath))
26
19
  FileUtils.rm(@setting.xlsxpath) if File.exist? @setting.xlsxpath
27
-
28
- keystrwithColNo = ParseXLSXModule::KeyStrWithColNo.new(@setting.keystr, 0)
29
- langwithColNolist = Array.new
20
+ keystr_with_colno = ParseXLSXModule::KeyStrWithColNo.new(@setting.keystr, 0)
21
+ lang_with_colno_list = Array.new
30
22
  colno = 1
31
-
32
23
  @setting.langlist.each do |key, langinfo|
33
- langwithColNo = ParseXLSXModule::LangWithColNo.new(langinfo[:xlsheader], key, colno)
24
+ langwith_colno = ParseXLSXModule::LangWithColNo.new(langinfo[:xlsheader], key, colno)
34
25
  colno+=1
35
- langwithColNolist.push(langwithColNo)
26
+ lang_with_colno_list.push(langwith_colno)
36
27
  end
37
-
38
28
  if @setting.platform == Platform::IOS
39
- result = self.parseIOS()
40
- writeToXlSX(@setting.xlsxpath, keystrwithColNo, langwithColNolist, result[:errorlist], result[:content], result[:keylist])
29
+ result = self.parse_ios
30
+ write_to_xlsx(@setting.xlsxpath, keystr_with_colno, lang_with_colno_list, result[:errorlist], result[:content], result[:keylist])
41
31
  else
42
- result = self.parseAndroid()
43
- writeToXlSX(@setting.xlsxpath, keystrwithColNo, langwithColNolist, result[:errorlist], result[:content], result[:keylist])
32
+ result = self.parse_android
33
+ write_to_xlsx(@setting.xlsxpath, keystr_with_colno, lang_with_colno_list, result[:errorlist], result[:content], result[:keylist])
44
34
  end
45
-
46
-
47
35
  end
48
36
 
49
- def parseIOS()
50
- result = ParseStringsFile.new()
37
+ def parse_ios
38
+ result = ParseStringsFile.new
51
39
  errorlist = result.errorlist
52
40
  content = result.strings_keys
53
41
  keylist = result.keys_list
54
42
  return {:errorlist => errorlist, :content => content, :keylist => keylist}
55
43
  end
56
44
 
57
- def parseAndroid()
58
- result = ParseXMLFile.new()
45
+ def parse_android
46
+ result = ParseXMLFile.new
59
47
  errorlist = result.errorlist
60
48
  content = result.strings_keys
61
49
  keylist = result.keys_list
62
50
  return {:errorlist => errorlist, :content => content, :keylist => keylist}
63
51
  end
64
52
 
65
- def writeToXlSX(path, keystrwithColNo, langwithColNolist, errorlist, content, keylist)
53
+ def write_to_xlsx(path, keystrwithColNo, langwithColNolist, errorlist, content, keylist)
66
54
  ErrorUtil::ParseLocalizedError::ParseLocalizedError.raiseArr(errorlist, !@skip_error)
67
55
  puts "Start write to file: \"#{path}\" ...".green
68
-
69
56
  workbook = RubyXL::Workbook.new
70
57
  worksheet = workbook.worksheets[0]
71
58
  rowno = 0
@@ -73,11 +60,10 @@ module Applocale
73
60
  langwithColNolist.each do |langwithColNo|
74
61
  worksheet.add_cell(rowno, langwithColNo.colno, langwithColNo.header_str)
75
62
  end
76
-
77
63
  rowno+=1
78
64
  keylist.each do |key|
79
65
  worksheet.add_cell(rowno, keystrwithColNo.colno, key)
80
- if !content[key].nil?
66
+ unless content[key].nil?
81
67
  langwithColNolist.each do |langwithColNo|
82
68
  lang = langwithColNo.lang.to_s
83
69
  worksheet.add_cell(rowno, langwithColNo.colno, content[key][lang][:value]) if !content[key][lang].nil? && !content[key][lang][:value].nil?
@@ -86,7 +72,7 @@ module Applocale
86
72
  rowno+=1
87
73
  end
88
74
  workbook.write(path)
89
-
90
75
  end
76
+
91
77
  end
92
78
  end