lokale 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/bin/lokale +26 -1
- data/lib/lokale/colorize.rb +25 -0
- data/lib/lokale/find_dir.rb +39 -0
- data/lib/lokale/options.rb +46 -0
- data/lib/lokale/version.rb +1 -1
- data/lib/lokale.rb +21 -20
- data/lokale.gemspec +1 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 72e68f6bb7e1876f79575ae055c261147df25727
|
4
|
+
data.tar.gz: 6343b1266d7b686224a0d728b4baecd8d4b6c92c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dc97049e348d6aedb0a8c54d112f8cbc4c963799c0ecc90227a28daf90dad03d2b9f9ca6652d58e189ad07c862c89e49beec59b5ea364ac84ab55751fc456482
|
7
|
+
data.tar.gz: e3a0565425d0e21b9cb2c67148489af5dc4e225afb58f671bbd9391b3fc3a957d753c54434cad8ffe5fd852845dfbcc3f606244f6559bc2aa5181eab2e87c5ef
|
data/README.md
CHANGED
@@ -32,7 +32,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
32
32
|
|
33
33
|
## Contributing
|
34
34
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/ordinec7/lokale.
|
36
36
|
|
37
37
|
## License
|
38
38
|
|
data/bin/lokale
CHANGED
@@ -1,6 +1,32 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require 'lokale'
|
4
|
+
require 'lokale/find_dir'
|
5
|
+
require 'lokale/colorize'
|
6
|
+
require 'lokale/options'
|
7
|
+
|
8
|
+
git_path = find_git_repo
|
9
|
+
if git_path.nil?
|
10
|
+
puts "Could not find any git repository."
|
11
|
+
exit
|
12
|
+
end
|
13
|
+
|
14
|
+
xcode_project = xcode_project_name(git_path)
|
15
|
+
if xcode_project.nil?
|
16
|
+
puts "Found git repository (#{git_path}) does not contain an Xcode project."
|
17
|
+
exit
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
settings = Settings.get
|
22
|
+
settings.actions.each do |s|
|
23
|
+
puts s
|
24
|
+
puts s.type
|
25
|
+
puts s.arg
|
26
|
+
puts s.precedence
|
27
|
+
end
|
28
|
+
|
29
|
+
puts "Analyzing Xcode project '#{xcode_project}'".green
|
4
30
|
|
5
31
|
macros = [
|
6
32
|
Lokale::Macro.new("NSLocalizedString", /NSLocalizedString\("(.+?)",\s*comment:\s*"(.*?)"\)/),
|
@@ -9,7 +35,6 @@ macros = [
|
|
9
35
|
#LocalizationMacro.new("ObjC Table String", /NSLocalizedStringFromTableInBundle\((.*?),/)
|
10
36
|
]
|
11
37
|
|
12
|
-
puts Dir.pwd
|
13
38
|
agent = Lokale::Agent.new(Dir.pwd, macros)
|
14
39
|
reporter = Lokale::Reporter.new(agent)
|
15
40
|
reporter.print_summary
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class String
|
2
|
+
def black; "\e[30m#{self}\e[0m" end
|
3
|
+
def red; "\e[31m#{self}\e[0m" end
|
4
|
+
def green; "\e[32m#{self}\e[0m" end
|
5
|
+
def brown; "\e[33m#{self}\e[0m" end
|
6
|
+
def blue; "\e[34m#{self}\e[0m" end
|
7
|
+
def magenta; "\e[35m#{self}\e[0m" end
|
8
|
+
def cyan; "\e[36m#{self}\e[0m" end
|
9
|
+
def gray; "\e[37m#{self}\e[0m" end
|
10
|
+
|
11
|
+
def bg_black; "\e[40m#{self}\e[0m" end
|
12
|
+
def bg_red; "\e[41m#{self}\e[0m" end
|
13
|
+
def bg_green; "\e[42m#{self}\e[0m" end
|
14
|
+
def bg_brown; "\e[43m#{self}\e[0m" end
|
15
|
+
def bg_blue; "\e[44m#{self}\e[0m" end
|
16
|
+
def bg_magenta; "\e[45m#{self}\e[0m" end
|
17
|
+
def bg_cyan; "\e[46m#{self}\e[0m" end
|
18
|
+
def bg_gray; "\e[47m#{self}\e[0m" end
|
19
|
+
|
20
|
+
def bold; "\e[1m#{self}\e[22m" end
|
21
|
+
def italic; "\e[3m#{self}\e[23m" end
|
22
|
+
def underline; "\e[4m#{self}\e[24m" end
|
23
|
+
def blink; "\e[5m#{self}\e[25m" end
|
24
|
+
def reverse_color; "\e[7m#{self}\e[27m" end
|
25
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# Script: Find the current git repository
|
2
|
+
# Based on https://github.com/mojombo/grit/pull/178 by https://github.com/derricks
|
3
|
+
|
4
|
+
|
5
|
+
# Returns true if the given path represents a root directory (/ or C:/)
|
6
|
+
def root_directory?(file_path)
|
7
|
+
# Implementation inspired by http://stackoverflow.com/a/4969416:
|
8
|
+
# Does file + ".." resolve to the same directory as file_path?
|
9
|
+
File.directory?(file_path) &&
|
10
|
+
File.expand_path(file_path) == File.expand_path(File.join(file_path, '..'))
|
11
|
+
end
|
12
|
+
|
13
|
+
# Returns the git root directory given a path inside the repo. Returns nil if
|
14
|
+
# the path is not in a git repo.
|
15
|
+
def find_git_repo(start_path = '.')
|
16
|
+
raise NoSuchPathError unless File.exists?(start_path)
|
17
|
+
|
18
|
+
current_path = File.expand_path(start_path)
|
19
|
+
|
20
|
+
# for clarity: set to an explicit nil and then just return whatever
|
21
|
+
# the current value of this variable is (nil or otherwise)
|
22
|
+
return_path = nil
|
23
|
+
|
24
|
+
until root_directory?(current_path)
|
25
|
+
if File.exists?(File.join(current_path, '.git'))
|
26
|
+
# done
|
27
|
+
return_path = current_path
|
28
|
+
break
|
29
|
+
else
|
30
|
+
# go up a directory and try again
|
31
|
+
current_path = File.dirname(current_path)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
return_path
|
35
|
+
end
|
36
|
+
|
37
|
+
def xcode_project_name(path)
|
38
|
+
Dir.glob("#{path}/**/**") { |file| return $1 if file =~ /\/(.+?)\.(?:xcodeproj|xcworkspace)$/ }
|
39
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
|
2
|
+
require "optparse"
|
3
|
+
|
4
|
+
|
5
|
+
|
6
|
+
Action = Struct.new("Action", :type, :arg, :precedence)
|
7
|
+
|
8
|
+
class Settings
|
9
|
+
attr_reader :actions
|
10
|
+
|
11
|
+
def self.get
|
12
|
+
actions = []
|
13
|
+
|
14
|
+
OptionParser.new do |opts|
|
15
|
+
opts.banner = "Usage: lokale [-bsh]"
|
16
|
+
|
17
|
+
opts.on("-b", "--copy-base", "Copies 'en' localization files to 'Base'") do |n|
|
18
|
+
actions << Action.new(:copy_base, nil, 10)
|
19
|
+
end
|
20
|
+
|
21
|
+
opts.on("-s", "--summary", "Prints project summary") do |n|
|
22
|
+
actions << Action.new(:summary, nil, 100)
|
23
|
+
end
|
24
|
+
|
25
|
+
opts.on("-h", "--help", "Prints this help") do
|
26
|
+
puts opts
|
27
|
+
exit
|
28
|
+
end
|
29
|
+
end.parse!
|
30
|
+
|
31
|
+
if actions.empty?
|
32
|
+
actions.sort_by! { |e| e.precedence }
|
33
|
+
else
|
34
|
+
actions.sort_by! { |e| e.precedence }
|
35
|
+
end
|
36
|
+
|
37
|
+
Settings.new(actions)
|
38
|
+
end
|
39
|
+
|
40
|
+
def initialize(actions)
|
41
|
+
@actions = actions
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
|
data/lib/lokale/version.rb
CHANGED
data/lib/lokale.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
|
1
|
+
require "lokale/version"
|
2
|
+
require "lokale/colorize"
|
2
3
|
require "set"
|
3
4
|
|
4
5
|
class String
|
@@ -22,9 +23,9 @@ class String
|
|
22
23
|
end
|
23
24
|
end
|
24
25
|
|
25
|
-
module Lokale
|
26
26
|
|
27
|
-
|
27
|
+
module Lokale
|
28
|
+
class LString
|
28
29
|
attr_accessor :key, :str, :note, :target
|
29
30
|
|
30
31
|
def initialize(key, str, note, target)
|
@@ -33,13 +34,13 @@ module Lokale
|
|
33
34
|
|
34
35
|
def self.strings_from_file(file_path, lang)
|
35
36
|
regex = /(?:\/* (.+) *\/.*\n)?"(.+)" *= *"(.+)";/
|
36
|
-
File.read(file_path).scan(regex).map { |m|
|
37
|
+
File.read(file_path).scan(regex).map { |m| LString.new(m[1], m[2], m[0], lang) }
|
37
38
|
end
|
38
39
|
end
|
39
40
|
|
40
41
|
#
|
41
42
|
|
42
|
-
class
|
43
|
+
class LFile
|
43
44
|
attr_reader :path, :lang, :name, :type
|
44
45
|
def initialize(file_path)
|
45
46
|
@path = file_path
|
@@ -54,7 +55,7 @@ module Lokale
|
|
54
55
|
|
55
56
|
def self.try_to_read(file_path)
|
56
57
|
return nil unless file_path.localization_file?
|
57
|
-
|
58
|
+
LFile.new(file_path)
|
58
59
|
end
|
59
60
|
|
60
61
|
def inspect
|
@@ -68,7 +69,7 @@ module Lokale
|
|
68
69
|
def parsed
|
69
70
|
return @parsed unless @parsed.nil?
|
70
71
|
@parsed = case type
|
71
|
-
when "strings" then
|
72
|
+
when "strings" then LString.strings_from_file(@path, @lang)
|
72
73
|
when "stringsdict" then []
|
73
74
|
else nil
|
74
75
|
end
|
@@ -144,7 +145,7 @@ module Lokale
|
|
144
145
|
|
145
146
|
def get_localization_files
|
146
147
|
return @lfiles unless @lfiles.nil?
|
147
|
-
@lfiles = proj_files.map { |file|
|
148
|
+
@lfiles = proj_files.map { |file| LFile.try_to_read(file) }.compact
|
148
149
|
end
|
149
150
|
|
150
151
|
def find_all_localization_calls
|
@@ -224,9 +225,10 @@ module Lokale
|
|
224
225
|
end
|
225
226
|
|
226
227
|
if repeats_repot.empty?
|
227
|
-
puts "Repeats not found."
|
228
|
+
puts "Repeats not found.".green
|
228
229
|
puts
|
229
230
|
else
|
231
|
+
puts "Found repeats in strings files.".red
|
230
232
|
puts repeats_repot
|
231
233
|
puts
|
232
234
|
end
|
@@ -236,29 +238,28 @@ module Lokale
|
|
236
238
|
diferences_repot = ""
|
237
239
|
|
238
240
|
@agent.lfiles.group_by { |f| f.full_name }.each do |file_name, files|
|
239
|
-
base_lang = files.
|
241
|
+
base_lang = files.any? { |f| f.lang == "Base" } ? "Base" : "en"
|
240
242
|
files = files.select { |f| f.lang != base_lang }
|
241
243
|
all_keys = files.map(&:keys).compact.map(&:to_set)
|
242
244
|
next if all_keys.empty?
|
243
|
-
|
244
|
-
all_keys.map! { |ks|
|
245
|
+
united_keys = all_keys.reduce(:|)
|
246
|
+
all_keys.map! { |ks| united_keys - ks }
|
245
247
|
next if all_keys.map(&:length).reduce(:+).zero?
|
246
248
|
|
247
|
-
diferences_repot << "
|
248
|
-
all_keys.zip(files) do |
|
249
|
-
next if
|
250
|
-
diferences_repot << "* #{lfile.lang}
|
251
|
-
|
249
|
+
diferences_repot << "Missing keys in file \"#{file_name}\":\n"
|
250
|
+
all_keys.zip(files) do |missing_keys, lfile|
|
251
|
+
next if missing_keys.size.zero?
|
252
|
+
diferences_repot << "* #{lfile.lang} - #{missing_keys.size} key(s):\n"
|
253
|
+
missing_keys.each { |k| diferences_repot << "#{k}\n" }
|
252
254
|
end
|
253
255
|
diferences_repot << "\n"
|
254
256
|
end
|
255
257
|
|
256
258
|
if diferences_repot.empty?
|
257
|
-
puts "Localization files are full."
|
259
|
+
puts "Localization files are full.".green
|
258
260
|
puts
|
259
261
|
else
|
260
|
-
puts "Localization files are not full."
|
261
|
-
puts
|
262
|
+
puts "Localization files are not full.".red
|
262
263
|
puts diferences_repot
|
263
264
|
puts
|
264
265
|
end
|
data/lokale.gemspec
CHANGED
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.1
|
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-20 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Write a longer description or delete this line.
|
14
14
|
email:
|
@@ -27,6 +27,9 @@ files:
|
|
27
27
|
- bin/lokale
|
28
28
|
- bin/setup
|
29
29
|
- lib/lokale.rb
|
30
|
+
- lib/lokale/colorize.rb
|
31
|
+
- lib/lokale/find_dir.rb
|
32
|
+
- lib/lokale/options.rb
|
30
33
|
- lib/lokale/version.rb
|
31
34
|
- lokale.gemspec
|
32
35
|
homepage:
|