applocale 0.2.4 → 0.2.5
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 +1 -1
- data/lib/applocale/Core/ParserStringFile/parse_localized_resource.rb +3 -1
- data/lib/applocale/Core/convert_to_localefile.rb +25 -1
- data/lib/applocale/Core/init.rb +2 -2
- data/lib/applocale/Util/config_util.rb +1 -1
- data/lib/applocale/Util/file_util.rb +3 -0
- data/lib/applocale/Util/lang.rb +2 -0
- data/lib/applocale/Util/platform.rb +5 -0
- data/lib/applocale/Util/regex_util.rb +11 -0
- data/lib/applocale/version.rb +1 -1
- metadata +2 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c867fde40c4818fa8274896d0386329514bc356b
|
4
|
+
data.tar.gz: 572063f121578458ff781751eda3a4a5ca7104ca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e77ca0d49da189afc99bc5d94a16dc600c9bc53bde9bb26c99456e53a158059bb89f78bcb63ca503516a7ec4e98b260018221b73374bdf727bc6acc541a03f4c
|
7
|
+
data.tar.gz: 4fe91b4192ac5a3cb4b4d861a07f18cdf03bc039e3b8c4a27e0743d37143b41a736fe46dde4c85701f9675ac6401f9a6eef8d4137e55db4d91728122c2513d0e
|
@@ -12,7 +12,7 @@ require 'thor'
|
|
12
12
|
module Applocale
|
13
13
|
class Command
|
14
14
|
class Init < Thor
|
15
|
-
desc "init [platform]", "Create Config File, platform: ios | android"
|
15
|
+
desc "init [platform]", "Create Config File, platform: ios | android | json"
|
16
16
|
option :path, :desc => "Project dir path"
|
17
17
|
def init(platform = nil)
|
18
18
|
Applocale.create_config_file(platform, options[:path])
|
@@ -38,9 +38,11 @@ module Applocale
|
|
38
38
|
if @platform == Platform::IOS
|
39
39
|
result = self.parse_ios
|
40
40
|
write_to_xlsx(@xlsxpath, sheetobj, result[:errorlist], result[:content], result[:keylist])
|
41
|
-
|
41
|
+
elsif @platform == Platform::ANDROID
|
42
42
|
result = self.parse_android
|
43
43
|
write_to_xlsx(@xlsxpath, sheetobj, result[:errorlist], result[:content], result[:keylist])
|
44
|
+
else
|
45
|
+
ErrorUtil::CommandError.new('Platform not supported').raise
|
44
46
|
end
|
45
47
|
end
|
46
48
|
|
@@ -4,7 +4,7 @@ require File.expand_path('../../Util/regex_util.rb', __FILE__)
|
|
4
4
|
require File.expand_path('../../Util/injection.rb', __FILE__)
|
5
5
|
|
6
6
|
require 'colorize'
|
7
|
-
|
7
|
+
require 'json'
|
8
8
|
|
9
9
|
module Applocale
|
10
10
|
class ConvertToStrFile
|
@@ -19,6 +19,8 @@ module Applocale
|
|
19
19
|
self.convert_to_stringfile(platform, langpath_obj, sheetcontent_list, injectObj)
|
20
20
|
elsif platform == Platform::ANDROID
|
21
21
|
self.convert_to_xml(platform, langpath_obj, sheetcontent_list, injectObj)
|
22
|
+
elsif platform == Platform::JSON
|
23
|
+
self.convert_to_json(platform, langpath_obj, sheetcontent_list, injectObj)
|
22
24
|
end
|
23
25
|
end
|
24
26
|
puts 'Convert Finished !!!'.green
|
@@ -62,6 +64,28 @@ module Applocale
|
|
62
64
|
target.close
|
63
65
|
end
|
64
66
|
|
67
|
+
def self.convert_to_json(platform, lang_path_obj, sheet_content_list, inject_obj)
|
68
|
+
FileUtils.mkdir_p(File.dirname(lang_path_obj.filepath))
|
69
|
+
hash = sheet_content_list.map do |sheet_content|
|
70
|
+
sheet_content.get_rowInfo_sortby_key.map do |row|
|
71
|
+
content = ContentUtil.remove_escaped_new_line(row.content_dict[lang_path_obj.lang])
|
72
|
+
value = add_escape(platform, lang_path_obj.lang, row.key_str, content, inject_obj)
|
73
|
+
[row.key_str, value]
|
74
|
+
end.to_h
|
75
|
+
end.reduce({}, :merge)
|
76
|
+
section_last_row = sheet_content_list
|
77
|
+
.map {|sheet_content| sheet_content.get_rowInfo_sortby_key.last&.key_str }
|
78
|
+
.compact
|
79
|
+
.reverse
|
80
|
+
.drop(1)
|
81
|
+
.reverse
|
82
|
+
json = JSON.pretty_generate(hash)
|
83
|
+
section_last_row.each { |row| json.gsub!(/(.*)("#{row}")(.*)/, '\1\2\3' + "\n") }
|
84
|
+
target = open(lang_path_obj.filepath, 'w')
|
85
|
+
target.puts(json)
|
86
|
+
target.close
|
87
|
+
end
|
88
|
+
|
65
89
|
def self.add_escape(platform, lang, key, content, injectObj)
|
66
90
|
value = content
|
67
91
|
if injectObj.has_before_convent_to_locale
|
data/lib/applocale/Core/init.rb
CHANGED
@@ -23,13 +23,13 @@ module Applocale
|
|
23
23
|
elsif Dir.glob("#{proj_apath}/**/*.gradle").length > 0
|
24
24
|
platformsybom = Platform::ANDROID
|
25
25
|
else
|
26
|
-
Applocale::ErrorUtil::CommandError.new("
|
26
|
+
Applocale::ErrorUtil::CommandError.new("Missing [platform] : ios | android | json").raise
|
27
27
|
end
|
28
28
|
else
|
29
29
|
platformsybom = Platform.init(platformStr.strip)
|
30
30
|
end
|
31
31
|
if platformsybom.nil?
|
32
|
-
ErrorUtil::CommandError.new("Invalid [platform] : ios | android ").raise
|
32
|
+
ErrorUtil::CommandError.new("Invalid [platform] : ios | android | json").raise
|
33
33
|
else
|
34
34
|
Applocale::Config::ConfigUtil.create_configfile_ifneed(platformsybom,proj_apath.to_s )
|
35
35
|
end
|
@@ -100,7 +100,7 @@ module Applocale
|
|
100
100
|
error_list.push(error)
|
101
101
|
else
|
102
102
|
if Platform.init(platform).nil?
|
103
|
-
error = ErrorUtil::ConfigFileInValid.new("[platform] can only be 'ios' or '
|
103
|
+
error = ErrorUtil::ConfigFileInValid.new("[platform] can only be 'ios', 'android' or 'json'.")
|
104
104
|
error_list.push(error)
|
105
105
|
else
|
106
106
|
setting.platform = Platform.init(platform)
|
@@ -7,6 +7,7 @@ module Applocale
|
|
7
7
|
DIRNAME_MAIN = 'AppLocale'
|
8
8
|
DIRNAME_IOS = 'IOS'
|
9
9
|
DIRNAME_ANDROID = 'Android'
|
10
|
+
DIRNAME_JSON = 'locales'
|
10
11
|
FILENAME_CONFIG = 'AppLocaleFile'
|
11
12
|
FILENAME_XLSX = 'string.xlsx'
|
12
13
|
GOOGLE_CREDENTIALS = 'google_credentials.yaml'
|
@@ -42,6 +43,8 @@ module Applocale
|
|
42
43
|
dirname = DIRNAME_IOS
|
43
44
|
elsif platform == Platform::ANDROID
|
44
45
|
dirname = DIRNAME_ANDROID
|
46
|
+
elsif platform == Platform::JSON
|
47
|
+
dirname = DIRNAME_JSON
|
45
48
|
end
|
46
49
|
unless dirname.nil?
|
47
50
|
filename = Locale.filename(platform, lang)
|
data/lib/applocale/Util/lang.rb
CHANGED
@@ -12,6 +12,8 @@ module Applocale
|
|
12
12
|
return !FILENAME_IOS[locale].nil? ? FILENAME_IOS[locale] : "#{locale}.strings"
|
13
13
|
elsif devicemodel == Platform::ANDROID
|
14
14
|
return File.join(FILENAME_ANDROID[locale],'strings.xml')
|
15
|
+
elsif devicemodel == Platform::JSON
|
16
|
+
return "#{locale}.json"
|
15
17
|
end
|
16
18
|
return nil
|
17
19
|
end
|
@@ -3,12 +3,15 @@ module Applocale
|
|
3
3
|
module Platform
|
4
4
|
IOS = :ios
|
5
5
|
ANDROID = :Android
|
6
|
+
JSON = :json
|
6
7
|
|
7
8
|
def self.init(platform)
|
8
9
|
if platform.upcase == 'IOS'
|
9
10
|
return Platform::IOS
|
10
11
|
elsif platform.upcase == 'ANDROID'
|
11
12
|
return Platform::ANDROID
|
13
|
+
elsif platform.upcase == 'JSON'
|
14
|
+
return Platform::JSON
|
12
15
|
end
|
13
16
|
return nil
|
14
17
|
end
|
@@ -24,6 +27,8 @@ module Applocale
|
|
24
27
|
if extn.downcase == '.xml'
|
25
28
|
return true
|
26
29
|
end
|
30
|
+
elsif platform == Platform::JSON
|
31
|
+
return extn.downcase == '.json'
|
27
32
|
end
|
28
33
|
return false
|
29
34
|
end
|
@@ -90,5 +90,16 @@ module Applocale
|
|
90
90
|
new_value = new_value.gsub(/\t/, "\\t")
|
91
91
|
return new_value
|
92
92
|
end
|
93
|
+
|
94
|
+
def self.remove_escaped_new_line(content)
|
95
|
+
reg = /(?<!\\)((?:\\{2})+)*\\"/
|
96
|
+
new_value = content.gsub(reg) {|match|
|
97
|
+
match.slice!(0)
|
98
|
+
match
|
99
|
+
}
|
100
|
+
new_value
|
101
|
+
.gsub(/\\n/, "\n")
|
102
|
+
.gsub(/\\t/, "\t")
|
103
|
+
end
|
93
104
|
end
|
94
105
|
end
|
data/lib/applocale/version.rb
CHANGED
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.2.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kennix
|
@@ -173,9 +173,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
173
173
|
version: '0'
|
174
174
|
requirements: []
|
175
175
|
rubyforge_project:
|
176
|
-
rubygems_version: 2.6.
|
176
|
+
rubygems_version: 2.6.10
|
177
177
|
signing_key:
|
178
178
|
specification_version: 4
|
179
179
|
summary: for mobile application to manage locale
|
180
180
|
test_files: []
|
181
|
-
has_rdoc:
|