applocale 0.2.2 → 0.2.3
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.
- checksums.yaml +4 -4
- data/lib/applocale/AppLocaleFile +1 -0
- data/lib/applocale/Core/GoogleHepler/google_helper.rb +28 -15
- data/lib/applocale/Core/ParseCSV/parse_csv.rb +114 -0
- data/lib/applocale/Core/ParseModel/parse_model_module.rb +88 -0
- data/lib/applocale/Core/ParseXLSX/parse_xlsx.rb +12 -6
- data/lib/applocale/Core/ParseXLSX/parse_xlsx_module.rb +3 -92
- data/lib/applocale/Core/init.rb +10 -4
- data/lib/applocale/Core/setting.rb +4 -1
- data/lib/applocale/Util/config_util.rb +14 -2
- data/lib/applocale/Util/error_util.rb +13 -0
- data/lib/applocale/Util/file_util.rb +10 -0
- data/lib/applocale/version.rb +1 -1
- metadata +8 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 269a0b00b1d4a213e8e384836a2114057692c2ef
|
4
|
+
data.tar.gz: e0eb7aabaa4b8cd918382bf43a3dd0b0151a5c27
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 79ba9f4d67ff026796421fab0b36c09fe58bedae3610f9416060da136e385b5905dcbcb995483ad51dbdc17ac6083a85704630380d3884d87f2ac76b722c13b3
|
7
|
+
data.tar.gz: ad628b0dacb5b1492c24c96276ffb3074f147dc56a7b1db4f92e43dc01fe3392a8f09a671f78a47a5a71df57628fab681369e4e2293fcf3abc99a98d01da5812
|
data/lib/applocale/AppLocaleFile
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
link: "https://docs.google.com/spreadsheets/d/1Wy2gN_DSw-TCU2gPCzqvYxLfFG5fyK5rodXs5MLUy8w"
|
2
2
|
platform: "#{platform}"
|
3
3
|
xlsxpath: "#{xlsxpath}"
|
4
|
+
export_format: :#{export_format}
|
4
5
|
#google_credentials_path: "#{google_credentials_path}"
|
5
6
|
langlist:
|
6
7
|
zh_TW: "#{path_zh_TW}"
|
@@ -3,6 +3,7 @@ require 'googleauth'
|
|
3
3
|
require 'googleauth/stores/file_token_store'
|
4
4
|
require 'fileutils'
|
5
5
|
require 'colorize'
|
6
|
+
require 'open-uri'
|
6
7
|
require File.expand_path('../../../Util/file_util.rb', __FILE__)
|
7
8
|
require File.expand_path('../../../Util/error_util.rb', __FILE__)
|
8
9
|
|
@@ -34,23 +35,34 @@ module Applocale
|
|
34
35
|
end
|
35
36
|
|
36
37
|
private
|
37
|
-
def
|
38
|
-
if File.
|
39
|
-
FileUtils.rm(self.xlsx_path)
|
40
|
-
end
|
38
|
+
def remove_old_files(from:)
|
39
|
+
FileUtils.rm_rf Dir.glob("#{from}/*.{csv,xlsx}") if File.directory?(from)
|
41
40
|
end
|
42
41
|
|
43
42
|
public
|
44
|
-
def download
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
service.authorization = authorize
|
43
|
+
def download(sheet_obj_list, export_format:, export_to:)
|
44
|
+
FileUtils.mkdir_p(export_to) unless File.directory?(export_to)
|
45
|
+
remove_old_files(from: export_to)
|
46
|
+
authorization = authorize
|
49
47
|
begin
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
48
|
+
case export_format
|
49
|
+
when 'csv'
|
50
|
+
sheet_obj_list.each do |sheet_obj|
|
51
|
+
sheet_name = sheet_obj.sheetname
|
52
|
+
file_path = File.expand_path("#{sheet_name}.csv", export_to)
|
53
|
+
csv = open("https://docs.google.com/spreadsheets/d/#{self.spreadsheet_id}/gviz/tq?tqx=out:csv&sheet=#{sheet_name}&access_token=#{authorization.access_token}")
|
54
|
+
IO.copy_stream(csv, file_path)
|
55
|
+
end
|
56
|
+
when 'xlsx'
|
57
|
+
service = Google::Apis::DriveV3::DriveService.new
|
58
|
+
service.client_options.application_name = APPLICATION_NAME
|
59
|
+
service.authorization = authorization
|
60
|
+
service.export_file(self.spreadsheet_id,
|
61
|
+
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
62
|
+
download_dest: self.xlsx_path)
|
63
|
+
end
|
64
|
+
|
65
|
+
if Dir["#{export_to}/*"].any?
|
54
66
|
puts 'Download from google finished'.green
|
55
67
|
else
|
56
68
|
ErrorUtil::DownloadFromGoogleFail.new.raise
|
@@ -61,8 +73,8 @@ module Applocale
|
|
61
73
|
failauth
|
62
74
|
rescue Google::Apis::ServerError => e
|
63
75
|
failauth
|
64
|
-
rescue
|
65
|
-
ErrorUtil
|
76
|
+
rescue => execption
|
77
|
+
ErrorUtil.raise(execption)
|
66
78
|
end
|
67
79
|
end
|
68
80
|
|
@@ -108,6 +120,7 @@ module Applocale
|
|
108
120
|
credentials = authorizer.get_and_store_credentials_from_code(
|
109
121
|
user_id: user_id, code: code, base_url: OOB_URI)
|
110
122
|
end
|
123
|
+
credentials.refresh! if credentials.expired?
|
111
124
|
credentials
|
112
125
|
end
|
113
126
|
|
@@ -0,0 +1,114 @@
|
|
1
|
+
require File.expand_path('../../setting.rb', __FILE__)
|
2
|
+
require File.expand_path('../../../Util/error_util.rb', __FILE__)
|
3
|
+
require File.expand_path('../../../Util/regex_util.rb', __FILE__)
|
4
|
+
require File.expand_path('../../ParseModel/parse_model_module.rb', __FILE__)
|
5
|
+
|
6
|
+
require 'colorize'
|
7
|
+
require 'csv'
|
8
|
+
|
9
|
+
module Applocale
|
10
|
+
class ParseCSV
|
11
|
+
|
12
|
+
@sheetcontent_list = nil
|
13
|
+
@allkey_dict = {}
|
14
|
+
@all_error = nil
|
15
|
+
|
16
|
+
@platform
|
17
|
+
@csv_directory
|
18
|
+
@langlist
|
19
|
+
@sheetobj_list
|
20
|
+
|
21
|
+
def initialize(platfrom, csv_directory, langlist, sheetobj_list)
|
22
|
+
@platform = platfrom
|
23
|
+
@csv_directory = csv_directory
|
24
|
+
@langlist = langlist
|
25
|
+
@sheetobj_list = sheetobj_list
|
26
|
+
@sheetcontent_list = Array.new
|
27
|
+
@allkey_dict = {}
|
28
|
+
@all_error = Array.new
|
29
|
+
# puts "Start to Parse CSV: \"#{csv_directory}\" ...".green
|
30
|
+
parse
|
31
|
+
end
|
32
|
+
|
33
|
+
def parse
|
34
|
+
@sheetcontent_list = @sheetobj_list.map do |sheet_obj|
|
35
|
+
sheet_name = sheet_obj.sheetname
|
36
|
+
sheet_content = ParseModelModule::SheetContent.new(sheet_name)
|
37
|
+
|
38
|
+
csv_path = File.expand_path("#{sheet_name}.csv", @csv_directory)
|
39
|
+
unless File.exist? csv_path
|
40
|
+
ErrorUtil.warning("File does not exist: #{csv_path}")
|
41
|
+
next
|
42
|
+
end
|
43
|
+
rows = CSV.read(csv_path)
|
44
|
+
header = find_header(sheet_obj, rows)
|
45
|
+
sheet_content.header_rowno = header[:header_row_index]
|
46
|
+
sheet_content.keyStr_with_colno = header[:key_header_info]
|
47
|
+
sheet_content.lang_with_colno_list = header[:language_header_list]
|
48
|
+
|
49
|
+
rows.each_with_index do |row, index|
|
50
|
+
next if sheet_content.header_rowno == index
|
51
|
+
row_content = parse_row(sheet_name, index, row, sheet_content.keyStr_with_colno, sheet_content.lang_with_colno_list)
|
52
|
+
handle_duplicate_key_if_any!(row_content)
|
53
|
+
sheet_content.rowinfo_list.push(row_content)
|
54
|
+
end
|
55
|
+
sheet_content
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def result
|
60
|
+
@sheetcontent_list
|
61
|
+
end
|
62
|
+
|
63
|
+
def find_header(sheet, rows)
|
64
|
+
sheet_name = sheet.sheetname
|
65
|
+
sheet_info_obj = sheet.obj
|
66
|
+
sheet_language_list = sheet_info_obj.lang_headers
|
67
|
+
sheet_key_header = sheet_info_obj.key_header
|
68
|
+
|
69
|
+
header_row_index = rows.index do |row|
|
70
|
+
row.include?(sheet_key_header)
|
71
|
+
end
|
72
|
+
|
73
|
+
header_row_info = rows[header_row_index] unless header_row_index.nil?
|
74
|
+
header_column_index = header_row_info&.index { |cell| cell == sheet_key_header }
|
75
|
+
if header_row_index.nil? || header_column_index.nil?
|
76
|
+
raise "ParseCSVError: Header not found in sheet #{sheet_name}"
|
77
|
+
end
|
78
|
+
key_header_info = ParseModelModule::KeyStrWithColNo.new(sheet_key_header, header_column_index)
|
79
|
+
|
80
|
+
language_header_list = sheet_language_list.map do |key, value|
|
81
|
+
cell_index = header_row_info.index { |cell| cell == value }
|
82
|
+
cell_index.nil? ? nil : ParseModelModule::LangWithColNo.new(value, key, cell_index)
|
83
|
+
end.compact
|
84
|
+
unless language_header_list.length == sheet_language_list.length
|
85
|
+
raise "ParseCSVError: Wrong language keys in sheet #{sheet_name}"
|
86
|
+
end
|
87
|
+
{
|
88
|
+
header_row_index: header_row_index,
|
89
|
+
key_header_info: key_header_info,
|
90
|
+
language_header_list: language_header_list
|
91
|
+
}
|
92
|
+
end
|
93
|
+
|
94
|
+
def parse_row(sheet_name, index, row, key_header_info, language_header_list)
|
95
|
+
key_str = row[key_header_info.colno]
|
96
|
+
|
97
|
+
unless ValidKey.is_validkey(@platform, key_str)
|
98
|
+
raise "ParseCSVError: Invaild Key in sheet #{sheet_name}, row: #{index}, key_str: #{key_str}"
|
99
|
+
end
|
100
|
+
rowinfo = ParseModelModule::RowInfo.new(sheet_name, index, key_str)
|
101
|
+
rowinfo.content_dict = Hash[language_header_list.map { |language_header| [language_header.lang, ContentUtil.from_excel(row[language_header.colno] || '')] }]
|
102
|
+
rowinfo
|
103
|
+
end
|
104
|
+
|
105
|
+
def handle_duplicate_key_if_any!(row_content)
|
106
|
+
previous_row_content = @allkey_dict[row_content.key_str.downcase]
|
107
|
+
if previous_row_content.nil?
|
108
|
+
@allkey_dict[row_content.key_str.downcase] = row_content
|
109
|
+
else
|
110
|
+
raise "ParseCSVError:: Duplicate keys:\n sheet #{row_content.sheetname}, row: #{row_content.rowno}, key_str: #{row_content.key_str}\nduplicateWithSheet: #{previous_row_content.sheetname}, row: #{previous_row_content.rowno}, key_str: #{previous_row_content.key_str}"
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
module Applocale
|
2
|
+
module ParseModelModule
|
3
|
+
class SheetContent
|
4
|
+
attr_accessor :sheetname, :header_rowno, :keyStr_with_colno, :lang_with_colno_list, :rowinfo_list, :comment
|
5
|
+
def initialize(sheetname)
|
6
|
+
self.sheetname = sheetname
|
7
|
+
self.rowinfo_list = Array.new
|
8
|
+
self.lang_with_colno_list = Array.new
|
9
|
+
self.comment = sheetname
|
10
|
+
end
|
11
|
+
|
12
|
+
def get_rowInfo_sortby_key
|
13
|
+
return self.rowinfo_list.sort_by { |obj| obj.key_str.to_s }
|
14
|
+
end
|
15
|
+
|
16
|
+
def get_rowInfo_sortby_rowno
|
17
|
+
return self.rowinfo_list.sort_by { |obj| obj.rowno.to_i }
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_s
|
21
|
+
str_keyStr_with_colno = ''
|
22
|
+
unless keyStr_with_colno.nil?
|
23
|
+
str_keyStr_with_colno = "\n\t#{keyStr_with_colno.to_s}"
|
24
|
+
end
|
25
|
+
str_lang_with_colno_list = ''
|
26
|
+
self.lang_with_colno_list.each do |langWithColNo|
|
27
|
+
str_lang_with_colno_list += "\n\t#{langWithColNo.to_s}"
|
28
|
+
end
|
29
|
+
str_contentlist = '\n'
|
30
|
+
self.get_rowInfo_sortby_rowno.each do |value|
|
31
|
+
str_contentlist += "\t #{value.to_s}\n"
|
32
|
+
end
|
33
|
+
"sheetname = #{sheetname}\n" +
|
34
|
+
"header_rowno = #{header_rowno}\n" +
|
35
|
+
"keyStrWithColNo = #{str_keyStr_with_colno}\n" +
|
36
|
+
"langWithColNo_list = #{str_lang_with_colno_list}\n" +
|
37
|
+
"rowinfo_list = #{str_contentlist}"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
class RowInfo
|
42
|
+
|
43
|
+
attr_accessor :sheetname, :rowno, :key_str, :content_dict
|
44
|
+
|
45
|
+
def initialize(sheetname = nil, rowno = nil, key_str = nil)
|
46
|
+
self.sheetname = sheetname
|
47
|
+
self.rowno = rowno
|
48
|
+
self.key_str = key_str
|
49
|
+
self.content_dict = {}
|
50
|
+
end
|
51
|
+
|
52
|
+
def to_s
|
53
|
+
"sheetname = #{sheetname}, rowno = #{rowno}, key_str = #{key_str}, content_dict = #{content_dict}"
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
class KeyStrWithColNo
|
59
|
+
|
60
|
+
attr_accessor :header_str, :colno
|
61
|
+
|
62
|
+
def initialize(header_str, colno)
|
63
|
+
self.header_str = header_str
|
64
|
+
self.colno = colno
|
65
|
+
end
|
66
|
+
|
67
|
+
def to_s
|
68
|
+
"{header_str => #{header_str}, colno => #{colno}}"
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
class LangWithColNo
|
74
|
+
attr_accessor :header_str, :lang, :colno
|
75
|
+
|
76
|
+
def initialize(header_str, lang, colno)
|
77
|
+
self.header_str = header_str
|
78
|
+
self.lang = lang
|
79
|
+
self.colno = colno
|
80
|
+
end
|
81
|
+
|
82
|
+
def to_s
|
83
|
+
"{header_str => #{header_str}, lang => #{lang}, colno => #{colno}}"
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -2,6 +2,7 @@ require File.expand_path('../../setting.rb', __FILE__)
|
|
2
2
|
require File.expand_path('../parse_xlsx_module.rb', __FILE__)
|
3
3
|
require File.expand_path('../../../Util/error_util.rb', __FILE__)
|
4
4
|
require File.expand_path('../../../Util/regex_util.rb', __FILE__)
|
5
|
+
require File.expand_path('../../ParseModel/parse_model_module.rb', __FILE__)
|
5
6
|
|
6
7
|
require 'rubyXL'
|
7
8
|
require 'colorize'
|
@@ -46,7 +47,12 @@ module Applocale
|
|
46
47
|
ErrorUtil::CannotOpenXlsxFile.new(@xlsxpath).raise
|
47
48
|
end
|
48
49
|
sheetnamelist = Applocale::Config::Sheet.get_sheetlist(@sheetobj_list)
|
49
|
-
workbook.worksheets
|
50
|
+
worksheets = workbook.worksheets
|
51
|
+
sorted_worksheets = sheetnamelist
|
52
|
+
.map { |sheet_name| worksheets.find { |worksheet| worksheet.sheet_name == sheet_name } }
|
53
|
+
.compact
|
54
|
+
|
55
|
+
sorted_worksheets.each do |worksheet|
|
50
56
|
sheetname = worksheet.sheet_name
|
51
57
|
sheetinfoobj = Applocale::Config::Sheet.get_sheetobj_by_sheetname(@sheetobj_list, sheetname)
|
52
58
|
if sheetinfoobj.nil?
|
@@ -54,7 +60,7 @@ module Applocale
|
|
54
60
|
end
|
55
61
|
sheetnamelist.delete(sheetname)
|
56
62
|
|
57
|
-
sheetcontent =
|
63
|
+
sheetcontent = ParseModelModule::SheetContent.new(sheetname)
|
58
64
|
if sheetinfoobj.is_a? Applocale::Config::SheetInfoByRow
|
59
65
|
keycolno = Applocale::ParseXLSXModule::Helper.collabel_to_colno(sheetinfoobj.key_col)
|
60
66
|
sheetinfoobj.to_keyStrWithColNo(sheetcontent)
|
@@ -121,7 +127,7 @@ module Applocale
|
|
121
127
|
end
|
122
128
|
|
123
129
|
unless keystr.nil?
|
124
|
-
rowinfo =
|
130
|
+
rowinfo = ParseModelModule::RowInfo.new(sheetname, rowno, keystr)
|
125
131
|
lang_with_colno_list.each do |lang_with_colno|
|
126
132
|
cell = cells[lang_with_colno.colno - 1]
|
127
133
|
val = cell && cell.value
|
@@ -139,7 +145,7 @@ module Applocale
|
|
139
145
|
if ValidKey.is_validkey(@platform, new_value)
|
140
146
|
return new_value
|
141
147
|
else
|
142
|
-
rowinfo =
|
148
|
+
rowinfo = ParseModelModule::RowInfo.new(nil, nil, value)
|
143
149
|
raise ErrorUtil::ParseXlsxError::InValidKey.new(rowinfo)
|
144
150
|
end
|
145
151
|
end
|
@@ -162,11 +168,11 @@ module Applocale
|
|
162
168
|
value = cell && cell.value
|
163
169
|
unless value.nil?
|
164
170
|
if value == sheetinfoobj.key_header && keystr_with_colno.nil?
|
165
|
-
keystr_with_colno =
|
171
|
+
keystr_with_colno = ParseModelModule::KeyStrWithColNo.new(value, colno)
|
166
172
|
else
|
167
173
|
sheetinfoobj.lang_headers.each do |lang, keyforlang|
|
168
174
|
if value == keyforlang && k_header_lang_dict.index(lang).nil?
|
169
|
-
lang_with_colno_list.push(
|
175
|
+
lang_with_colno_list.push(ParseModelModule::LangWithColNo.new(keyforlang, lang, colno))
|
170
176
|
k_header_lang_dict.push(lang)
|
171
177
|
end
|
172
178
|
end
|
@@ -14,94 +14,6 @@ module Applocale
|
|
14
14
|
return number
|
15
15
|
end
|
16
16
|
end
|
17
|
-
|
18
|
-
|
19
|
-
class SheetContent
|
20
|
-
attr_accessor :sheetname, :header_rowno, :keyStr_with_colno, :lang_with_colno_list, :rowinfo_list, :comment
|
21
|
-
|
22
|
-
def initialize(sheetname)
|
23
|
-
self.sheetname = sheetname
|
24
|
-
self.rowinfo_list = Array.new
|
25
|
-
self.lang_with_colno_list = Array.new
|
26
|
-
self.comment = sheetname
|
27
|
-
end
|
28
|
-
|
29
|
-
def get_rowInfo_sortby_key
|
30
|
-
return self.rowinfo_list.sort_by { |obj| obj.key_str.to_s }
|
31
|
-
end
|
32
|
-
|
33
|
-
def get_rowInfo_sortby_rowno
|
34
|
-
return self.rowinfo_list.sort_by { |obj| obj.rowno.to_i }
|
35
|
-
end
|
36
|
-
|
37
|
-
def to_s
|
38
|
-
str_keyStr_with_colno = ''
|
39
|
-
unless keyStr_with_colno.nil?
|
40
|
-
str_keyStr_with_colno = "\n\t#{keyStr_with_colno.to_s}"
|
41
|
-
end
|
42
|
-
str_lang_with_colno_list = ''
|
43
|
-
self.lang_with_colno_list.each do |langWithColNo|
|
44
|
-
str_lang_with_colno_list += "\n\t#{langWithColNo.to_s}"
|
45
|
-
end
|
46
|
-
str_contentlist = '\n'
|
47
|
-
self.get_rowInfo_sortby_rowno.each do |value|
|
48
|
-
str_contentlist += "\t #{value.to_s}\n"
|
49
|
-
end
|
50
|
-
"sheetname = #{sheetname}\n" +
|
51
|
-
"header_rowno = #{header_rowno}\n" +
|
52
|
-
"keyStrWithColNo = #{str_keyStr_with_colno}\n" +
|
53
|
-
"langWithColNo_list = #{str_lang_with_colno_list}\n" +
|
54
|
-
"rowinfo_list = #{str_contentlist}"
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
class RowInfo
|
59
|
-
|
60
|
-
attr_accessor :sheetname, :rowno, :key_str, :content_dict
|
61
|
-
|
62
|
-
def initialize(sheetname = nil, rowno = nil, key_str = nil)
|
63
|
-
self.sheetname = sheetname
|
64
|
-
self.rowno = rowno
|
65
|
-
self.key_str = key_str
|
66
|
-
self.content_dict = {}
|
67
|
-
end
|
68
|
-
|
69
|
-
def to_s
|
70
|
-
"sheetname = #{sheetname}, rowno = #{rowno}, key_str = #{key_str}, content_dict = #{content_dict}"
|
71
|
-
end
|
72
|
-
|
73
|
-
end
|
74
|
-
|
75
|
-
class KeyStrWithColNo
|
76
|
-
|
77
|
-
attr_accessor :header_str, :colno
|
78
|
-
|
79
|
-
def initialize(header_str, colno)
|
80
|
-
self.header_str = header_str
|
81
|
-
self.colno = colno
|
82
|
-
end
|
83
|
-
|
84
|
-
def to_s
|
85
|
-
"{header_str => #{header_str}, colno => #{colno}}"
|
86
|
-
end
|
87
|
-
|
88
|
-
end
|
89
|
-
|
90
|
-
class LangWithColNo
|
91
|
-
attr_accessor :header_str, :lang, :colno
|
92
|
-
|
93
|
-
def initialize(header_str, lang, colno)
|
94
|
-
self.header_str = header_str
|
95
|
-
self.lang = lang
|
96
|
-
self.colno = colno
|
97
|
-
end
|
98
|
-
|
99
|
-
def to_s
|
100
|
-
"{header_str => #{header_str}, lang => #{lang}, colno => #{colno}}"
|
101
|
-
end
|
102
|
-
|
103
|
-
end
|
104
|
-
|
105
17
|
end
|
106
18
|
end
|
107
19
|
|
@@ -112,15 +24,14 @@ module Applocale
|
|
112
24
|
def to_keyStrWithColNo(sheetcontent)
|
113
25
|
sheetcontent.header_rowno = self.row
|
114
26
|
keycolno = Applocale::ParseXLSXModule::Helper.collabel_to_colno(self.key_col)
|
115
|
-
sheetcontent.keyStr_with_colno =
|
27
|
+
sheetcontent.keyStr_with_colno = Applocale::ParseModelModule::KeyStrWithColNo.new(nil, keycolno)
|
116
28
|
sheetcontent.lang_with_colno_list = Array.new
|
117
29
|
self.lang_cols.each do |lang, collabel|
|
118
30
|
colno = Applocale::ParseXLSXModule::Helper.collabel_to_colno(collabel)
|
119
|
-
obj =
|
31
|
+
obj = Applocale::ParseModelModule::LangWithColNo.new(nil,lang, colno)
|
120
32
|
sheetcontent.lang_with_colno_list.push(obj)
|
121
33
|
end
|
122
34
|
end
|
123
35
|
end
|
124
36
|
end
|
125
|
-
end
|
126
|
-
|
37
|
+
end
|
data/lib/applocale/Core/init.rb
CHANGED
@@ -4,6 +4,7 @@ require File.expand_path('../../Util/error_util.rb', __FILE__)
|
|
4
4
|
require File.expand_path('../../Util/config_util.rb', __FILE__)
|
5
5
|
require File.expand_path('../GoogleHepler/google_helper.rb', __FILE__)
|
6
6
|
require File.expand_path('../ParseXLSX/parse_xlsx', __FILE__)
|
7
|
+
require File.expand_path('../ParseCSV/parse_csv', __FILE__)
|
7
8
|
require File.expand_path('../ParserStringFile/parse_localized_resource.rb', __FILE__)
|
8
9
|
require File.expand_path('../convert_to_localefile', __FILE__)
|
9
10
|
require File.expand_path('../FindStrKey/find_str_key', __FILE__)
|
@@ -48,12 +49,12 @@ module Applocale
|
|
48
49
|
setting.google_credentials_path = File.expand_path(FilePathUtil.default_google_credentials_filename, File.dirname(setting.configfile_pathstr))
|
49
50
|
end
|
50
51
|
googleobj = Applocale::GoogleHelper.new(setting.link, setting.google_credentials_path, setting.xlsxpath)
|
51
|
-
googleobj.download
|
52
|
+
googleobj.download(setting.sheet_obj_list, export_format: setting.export_format, export_to: setting.export_to)
|
52
53
|
else
|
53
54
|
download = open(setting.link)
|
54
55
|
IO.copy_stream(download, setting.xlsxpath)
|
55
56
|
end
|
56
|
-
Applocale.start_local_update(
|
57
|
+
Applocale.start_local_update(setting, proj_path)
|
57
58
|
end
|
58
59
|
|
59
60
|
def self.start_local_update(asetting = nil, projpath = Dir.pwd)
|
@@ -65,8 +66,13 @@ module Applocale
|
|
65
66
|
obj = Applocale::Config::ConfigUtil.new(proj_apath)
|
66
67
|
setting = obj.load_configfile_to_setting
|
67
68
|
end
|
68
|
-
|
69
|
-
|
69
|
+
case setting.export_format
|
70
|
+
when 'csv'
|
71
|
+
parser = Applocale::ParseCSV.new(setting.platform, setting.export_to, setting.lang_path_list, setting.sheet_obj_list)
|
72
|
+
when 'xlsx'
|
73
|
+
parser = Applocale::ParseXLSX.new(setting.platform, setting.xlsxpath, setting.lang_path_list, setting.sheet_obj_list)
|
74
|
+
end
|
75
|
+
ConvertToStrFile.convert(setting.platform, setting.lang_path_list,parser.result, setting.rubycode)
|
70
76
|
end
|
71
77
|
|
72
78
|
def self.start_reverse( is_skip, projpath = Dir.pwd)
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'colorize'
|
2
|
+
require 'colorize'
|
2
3
|
# module Applocale
|
3
4
|
# class Setting
|
4
5
|
# class <<self
|
@@ -21,7 +22,7 @@ require 'colorize'
|
|
21
22
|
module Applocale
|
22
23
|
module Config
|
23
24
|
class Setting
|
24
|
-
attr_accessor :configfile_pathstr, :link, :platform, :xlsxpath, :google_credentials_path, :lang_path_list, :sheet_obj_list, :rubycode
|
25
|
+
attr_accessor :configfile_pathstr, :link, :platform, :xlsxpath, :google_credentials_path, :lang_path_list, :sheet_obj_list, :rubycode, :export_format, :export_to
|
25
26
|
def initialize(configfile_pathstr)
|
26
27
|
self.configfile_pathstr = configfile_pathstr
|
27
28
|
self.lang_path_list = Array.new
|
@@ -44,6 +45,8 @@ module Applocale
|
|
44
45
|
puts " #{sheet_obj.to_s}"
|
45
46
|
end
|
46
47
|
|
48
|
+
puts " export_format: #{export_format}"
|
49
|
+
puts " export_to: #{export_to}"
|
47
50
|
# puts self.rubycode
|
48
51
|
|
49
52
|
end
|
@@ -34,6 +34,7 @@ module Applocale
|
|
34
34
|
newline = newline.gsub("\#{path_en_US}", FilePathUtil.default_localefile_relative_pathstr(platform, Locale::EN_US))
|
35
35
|
newline = newline.gsub("\#{xlsxpath}", FilePathUtil.default_xlsx_relativepath_str)
|
36
36
|
newline = newline.gsub("\#{google_credentials_path}", FilePathUtil.default_google_credentials_filename)
|
37
|
+
newline = newline.gsub("\#{export_format}", FilePathUtil.default_export_format.to_s)
|
37
38
|
to.puts(newline)
|
38
39
|
end
|
39
40
|
end
|
@@ -80,7 +81,8 @@ module Applocale
|
|
80
81
|
google_credentials_path = config_yaml['google_credentials_path'].to_s.strip
|
81
82
|
langlist = config_yaml['langlist']
|
82
83
|
sheetname = config_yaml['sheetname']
|
83
|
-
|
84
|
+
export_format = config_yaml['export_format']
|
85
|
+
export_to = config_yaml['export_to']
|
84
86
|
|
85
87
|
setting = Applocale::Config::Setting.new(self.configfile_pathstr)
|
86
88
|
setting.rubycode = rubycode
|
@@ -105,9 +107,19 @@ module Applocale
|
|
105
107
|
end
|
106
108
|
end
|
107
109
|
|
110
|
+
case export_format
|
111
|
+
when 'csv', 'xlsx'
|
112
|
+
setting.export_format = export_format
|
113
|
+
else
|
114
|
+
error = ErrorUtil::ConfigFileInValid.new("[export_format] for item can only be 'csv' or 'xlsx' ")
|
115
|
+
error_list.push(error)
|
116
|
+
end
|
117
|
+
|
118
|
+
setting.export_to = FilePathUtil.default_export_to
|
119
|
+
|
108
120
|
if !(xlsxpath.nil? || xlsxpath.length == 0)
|
109
121
|
if !(Pathname.new xlsxpath).absolute?
|
110
|
-
setting.xlsxpath = File.expand_path(xlsxpath,
|
122
|
+
setting.xlsxpath = File.expand_path(xlsxpath, setting.export_to)
|
111
123
|
else
|
112
124
|
setting.xlsxpath = xlsxpath
|
113
125
|
end
|
@@ -205,4 +205,17 @@ module Applocale
|
|
205
205
|
end
|
206
206
|
end
|
207
207
|
end
|
208
|
+
end
|
209
|
+
|
210
|
+
module Applocale
|
211
|
+
module ErrorUtil
|
212
|
+
def self.warning(message)
|
213
|
+
puts "** Warning: #{message}".yellow
|
214
|
+
end
|
215
|
+
|
216
|
+
def self.raise(message)
|
217
|
+
puts "** Error: #{message}".red
|
218
|
+
abort('')
|
219
|
+
end
|
220
|
+
end
|
208
221
|
end
|
@@ -10,6 +10,7 @@ module Applocale
|
|
10
10
|
FILENAME_CONFIG = 'AppLocaleFile'
|
11
11
|
FILENAME_XLSX = 'string.xlsx'
|
12
12
|
GOOGLE_CREDENTIALS = 'google_credentials.yaml'
|
13
|
+
EXPORT_FORMAT = 'xlsx'
|
13
14
|
|
14
15
|
def self.get_proj_absoluat_path(proj_path)
|
15
16
|
path = proj_path
|
@@ -27,10 +28,15 @@ module Applocale
|
|
27
28
|
return FILENAME_CONFIG
|
28
29
|
end
|
29
30
|
|
31
|
+
def self.default_export_to
|
32
|
+
return DIRNAME_MAIN + "/Resource"
|
33
|
+
end
|
34
|
+
|
30
35
|
def self.default_mainfolder
|
31
36
|
return DIRNAME_MAIN
|
32
37
|
end
|
33
38
|
|
39
|
+
|
34
40
|
def self.default_localefile_relative_pathstr(platform, lang)
|
35
41
|
if platform == Platform::IOS
|
36
42
|
dirname = DIRNAME_IOS
|
@@ -49,6 +55,10 @@ module Applocale
|
|
49
55
|
return filename
|
50
56
|
end
|
51
57
|
|
58
|
+
def self.default_export_format
|
59
|
+
EXPORT_FORMAT
|
60
|
+
end
|
61
|
+
|
52
62
|
def self.str_to_folderpathstr(str)
|
53
63
|
pathstr = Pathname.new(str.strip)
|
54
64
|
if File.directory?(pathstr)
|
data/lib/applocale/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: applocale
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kennix
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-06-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -115,8 +115,8 @@ dependencies:
|
|
115
115
|
- !ruby/object:Gem::Version
|
116
116
|
version: 3.3.23
|
117
117
|
description: It can convert file between string and xlsx, also support download xlsx
|
118
|
-
from google. You can also setup conversion logic for string value of each
|
119
|
-
Support ios and android.
|
118
|
+
or csv from google. You can also setup conversion logic for string value of each
|
119
|
+
project. Support ios and android.
|
120
120
|
email:
|
121
121
|
- kennixdev@gmail.com
|
122
122
|
executables:
|
@@ -134,6 +134,8 @@ files:
|
|
134
134
|
- lib/applocale/Core/FindStrKey/find_str_key_result.rb
|
135
135
|
- lib/applocale/Core/GoogleHepler/client_secret.json
|
136
136
|
- lib/applocale/Core/GoogleHepler/google_helper.rb
|
137
|
+
- lib/applocale/Core/ParseCSV/parse_csv.rb
|
138
|
+
- lib/applocale/Core/ParseModel/parse_model_module.rb
|
137
139
|
- lib/applocale/Core/ParseXLSX/parse_xlsx.rb
|
138
140
|
- lib/applocale/Core/ParseXLSX/parse_xlsx_module.rb
|
139
141
|
- lib/applocale/Core/ParserStringFile/parse_localized_resource.rb
|
@@ -170,8 +172,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
170
172
|
version: '0'
|
171
173
|
requirements: []
|
172
174
|
rubyforge_project:
|
173
|
-
rubygems_version: 2.
|
175
|
+
rubygems_version: 2.6.6
|
174
176
|
signing_key:
|
175
177
|
specification_version: 4
|
176
178
|
summary: for mobile application to manage locale
|
177
179
|
test_files: []
|
180
|
+
has_rdoc:
|