lokale 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 +4 -4
- data/bin/lokale +37 -13
- data/lib/lokale/options.rb +51 -27
- data/lib/lokale/version.rb +1 -1
- data/lib/lokale.rb +30 -6
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 28a49cbbd5450645fa6067b0fd096191bb7a1760
|
4
|
+
data.tar.gz: 578fbe40eee917b39badc508ad62a5b63d748b9d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d8bcfbc01c0144b33d804a0b0d60b1b9224ffcb1b87af2730f4cf27f86ddb2e5eca0f032dcd6486279c2bfbdeb3506cea4661bdd5445fdc74372723357594c73
|
7
|
+
data.tar.gz: 063b8a079d93f1189f9d261896d818472d0b6d193c80a044f2d70810e8426f758b4e0676678b8703433a2506b0c6edc343804e927fd2917021d4718e4712b4c7
|
data/bin/lokale
CHANGED
@@ -5,36 +5,60 @@ require 'lokale/find_dir'
|
|
5
5
|
require 'lokale/colorize'
|
6
6
|
require 'lokale/options'
|
7
7
|
|
8
|
+
Settings.init
|
9
|
+
|
8
10
|
git_path = find_git_repo
|
9
11
|
if git_path.nil?
|
10
12
|
puts "Could not find any git repository."
|
11
13
|
exit
|
12
14
|
end
|
13
15
|
|
14
|
-
|
15
|
-
if
|
16
|
+
project_name = xcode_project_name(git_path)
|
17
|
+
if project_name.nil?
|
16
18
|
puts "Found git repository (#{git_path}) does not contain an Xcode project."
|
17
19
|
exit
|
18
20
|
end
|
19
21
|
|
22
|
+
puts "Target Xcode project: '#{project_name}'".green
|
20
23
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
24
|
+
########################################################################################
|
25
|
+
|
26
|
+
class Action
|
27
|
+
def perform(agent, reporter)
|
28
|
+
send(("perform_" + @type.to_s).to_sym, agent, reporter)
|
29
|
+
end
|
30
|
+
|
31
|
+
def perform_summary(agent, reporter)
|
32
|
+
puts "Printing summary".blue
|
33
|
+
reporter.print_summary
|
34
|
+
end
|
35
|
+
|
36
|
+
def perform_copy_base(agent, reporter)
|
37
|
+
puts "Copying `en` strings files to `Base`".blue
|
38
|
+
agent.copy_base
|
39
|
+
puts
|
40
|
+
end
|
41
|
+
|
42
|
+
def perform_append(agent, reporter)
|
43
|
+
|
44
|
+
end
|
27
45
|
end
|
28
46
|
|
29
|
-
|
47
|
+
|
48
|
+
|
49
|
+
settings = Settings.get
|
30
50
|
|
31
51
|
macros = [
|
32
|
-
Lokale::Macro.new("NSLocalizedString", /NSLocalizedString\("(.+?)",\s*comment:\s*"(.*?)"\)
|
33
|
-
Lokale::Macro.new("PluralString", /String.localizedPlural\("(.+?)"
|
52
|
+
Lokale::Macro.new("NSLocalizedString", /NSLocalizedString\("(.+?)",\s*comment:\s*"(.*?)"\)/, "Localizable.strings"),
|
53
|
+
Lokale::Macro.new("PluralString", /String.localizedPlural\("(.+?)"/, nil),
|
34
54
|
#LocalizationMacro.new("ObjC String", /NSLocalizedString\("(.*)",\s*(.*)\)/),
|
35
55
|
#LocalizationMacro.new("ObjC Table String", /NSLocalizedStringFromTableInBundle\((.*?),/)
|
36
56
|
]
|
37
57
|
|
38
|
-
agent = Lokale::Agent.new(
|
58
|
+
agent = Lokale::Agent.new(git_path, macros)
|
39
59
|
reporter = Lokale::Reporter.new(agent)
|
40
|
-
|
60
|
+
|
61
|
+
|
62
|
+
settings.actions.each do |action|
|
63
|
+
action.perform(agent, reporter)
|
64
|
+
end
|
data/lib/lokale/options.rb
CHANGED
@@ -1,46 +1,70 @@
|
|
1
1
|
|
2
2
|
require "optparse"
|
3
3
|
|
4
|
+
class Action
|
5
|
+
attr_reader :type, :arg, :precedence
|
6
|
+
def initialize(type, arg, precedence)
|
7
|
+
@type = type; @arg = arg; @precedence = precedence
|
8
|
+
end
|
4
9
|
|
10
|
+
def self.summary
|
11
|
+
Action.new(:summary, nil, 10)
|
12
|
+
end
|
13
|
+
def self.copy_base
|
14
|
+
Action.new(:copy_base, nil, 50)
|
15
|
+
end
|
16
|
+
def self.append
|
17
|
+
Action.new(:append, nil, 60)
|
18
|
+
end
|
19
|
+
end
|
5
20
|
|
6
|
-
|
7
|
-
|
8
|
-
class Settings
|
9
|
-
attr_reader :actions
|
21
|
+
class Settings
|
22
|
+
attr_reader :actions
|
10
23
|
|
11
|
-
|
12
|
-
|
24
|
+
def self.init
|
25
|
+
actions = []
|
13
26
|
|
14
|
-
|
15
|
-
|
27
|
+
OptionParser.new do |opts|
|
28
|
+
opts.banner = "Usage: lokale [-bsh]"
|
16
29
|
|
17
|
-
|
18
|
-
|
19
|
-
|
30
|
+
opts.on("-b", "--copy-base", "Copies 'en' localization files to 'Base'") do |n|
|
31
|
+
actions << Action.copy_base
|
32
|
+
end
|
20
33
|
|
21
|
-
|
22
|
-
|
23
|
-
|
34
|
+
opts.on("-s", "--summary", "Prints project summary") do |n|
|
35
|
+
actions << Action.summary
|
36
|
+
end
|
24
37
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
end
|
29
|
-
end.parse!
|
38
|
+
opts.on("-a", "--append", "Appends new strings to english localization file") do |n|
|
39
|
+
actions << Action.append
|
40
|
+
end
|
30
41
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
actions.sort_by! { |e| e.precedence }
|
42
|
+
opts.on("-h", "--help", "Prints this help") do
|
43
|
+
puts opts
|
44
|
+
exit
|
35
45
|
end
|
46
|
+
end.parse!
|
47
|
+
|
36
48
|
|
37
|
-
Settings.new(actions)
|
38
|
-
end
|
39
49
|
|
40
|
-
|
41
|
-
|
50
|
+
if actions.empty?
|
51
|
+
actions << Action.summary
|
52
|
+
else
|
53
|
+
actions.sort_by! { |e| -e.precedence }
|
42
54
|
end
|
55
|
+
|
56
|
+
@shared_settings = Settings.new(actions)
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.get
|
60
|
+
init if @shared_settings.nil?
|
61
|
+
@shared_settings
|
62
|
+
end
|
63
|
+
|
64
|
+
def initialize(actions)
|
65
|
+
@actions = actions
|
43
66
|
end
|
67
|
+
end
|
44
68
|
|
45
69
|
|
46
70
|
|
data/lib/lokale/version.rb
CHANGED
data/lib/lokale.rb
CHANGED
@@ -92,16 +92,22 @@ module Lokale
|
|
92
92
|
return nil if parsed.nil?
|
93
93
|
parsed.map(&:key)
|
94
94
|
end
|
95
|
+
|
96
|
+
|
97
|
+
def strings_file?
|
98
|
+
@type == "strings" || @type == "stringsdict"
|
99
|
+
end
|
95
100
|
end
|
96
101
|
|
97
102
|
#
|
98
103
|
|
99
104
|
class Macro
|
100
|
-
attr_reader :regex, :found_strings, :name
|
105
|
+
attr_reader :regex, :found_strings, :name, :file_name
|
101
106
|
|
102
|
-
def initialize(name, regex)
|
107
|
+
def initialize(name, regex, file_name)
|
103
108
|
@name = name
|
104
109
|
@regex = regex
|
110
|
+
@file_name = file_name
|
105
111
|
clear_calls
|
106
112
|
end
|
107
113
|
|
@@ -140,7 +146,11 @@ module Lokale
|
|
140
146
|
end
|
141
147
|
|
142
148
|
def proj_files
|
143
|
-
|
149
|
+
if block_given?
|
150
|
+
Dir.glob("#{@proj_path}/**/**") { |f| yield f }
|
151
|
+
else
|
152
|
+
Dir.glob("#{@proj_path}/**/**")
|
153
|
+
end
|
144
154
|
end
|
145
155
|
|
146
156
|
def get_localization_files
|
@@ -152,7 +162,7 @@ module Lokale
|
|
152
162
|
@macros.each { |m| m.clear_calls }
|
153
163
|
|
154
164
|
@sfiles_proceeded = 0
|
155
|
-
proj_files
|
165
|
+
proj_files do |file|
|
156
166
|
next unless file.source_file?
|
157
167
|
|
158
168
|
file_content = File.read(file)
|
@@ -160,6 +170,21 @@ module Lokale
|
|
160
170
|
@sfiles_proceeded += 1
|
161
171
|
end
|
162
172
|
end
|
173
|
+
|
174
|
+
def copy_base
|
175
|
+
en_files = @lfiles.group_by { |f| f.lang }["en"].select { |f| f.strings_file? }
|
176
|
+
base_files = @lfiles.group_by { |f| f.lang }["Base"].select { |f| f.strings_file? }
|
177
|
+
|
178
|
+
en_files.each do |en|
|
179
|
+
base = base_files.select { |f| f.full_name == en.full_name }.sample
|
180
|
+
next if base.nil?
|
181
|
+
IO.copy_stream(en.path, base.path)
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
def append_new_macro_calls
|
186
|
+
|
187
|
+
end
|
163
188
|
end
|
164
189
|
|
165
190
|
#
|
@@ -185,7 +210,6 @@ module Lokale
|
|
185
210
|
puts
|
186
211
|
end
|
187
212
|
|
188
|
-
|
189
213
|
def print_files_table
|
190
214
|
languages = @agent.lfiles.map { |e| e.lang }.to_set.to_a
|
191
215
|
files = @agent.lfiles.map { |e| e.full_name }.to_set.to_a
|
@@ -249,7 +273,7 @@ module Lokale
|
|
249
273
|
diferences_repot << "Missing keys in file \"#{file_name}\":\n"
|
250
274
|
all_keys.zip(files) do |missing_keys, lfile|
|
251
275
|
next if missing_keys.size.zero?
|
252
|
-
diferences_repot << "* #{lfile.lang} - #{missing_keys.size} key(s):\n"
|
276
|
+
diferences_repot << "*".red + " #{lfile.lang} - #{missing_keys.size} key(s):\n"
|
253
277
|
missing_keys.each { |k| diferences_repot << "#{k}\n" }
|
254
278
|
end
|
255
279
|
diferences_repot << "\n"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lokale
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anton Onizhuk
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-10-
|
11
|
+
date: 2017-10-25 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Write a longer description or delete this line.
|
14
14
|
email:
|
@@ -18,7 +18,7 @@ executables:
|
|
18
18
|
extensions: []
|
19
19
|
extra_rdoc_files: []
|
20
20
|
files:
|
21
|
-
- .gitignore
|
21
|
+
- ".gitignore"
|
22
22
|
- Gemfile
|
23
23
|
- LICENSE.txt
|
24
24
|
- README.md
|
@@ -42,17 +42,17 @@ require_paths:
|
|
42
42
|
- lib
|
43
43
|
required_ruby_version: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
49
|
requirements:
|
50
|
-
- -
|
50
|
+
- - ">="
|
51
51
|
- !ruby/object:Gem::Version
|
52
52
|
version: '0'
|
53
53
|
requirements: []
|
54
54
|
rubyforge_project:
|
55
|
-
rubygems_version: 2.
|
55
|
+
rubygems_version: 2.6.14
|
56
56
|
signing_key:
|
57
57
|
specification_version: 4
|
58
58
|
summary: Lokale is a small tool that inspects localization of Xcode projects.
|