i18n-cocoa 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +22 -5
- data/lib/i18n/cocoa/finder.rb +38 -0
- data/lib/i18n/cocoa/version.rb +1 -1
- data/lib/i18n/cocoa.rb +3 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ebbf5b1991105d808fe06a8aee71c4f192146ad6
|
4
|
+
data.tar.gz: 2f6d1da8e9936f5dfdb35f1344da1708a7e1656b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c4d709cb57f9ed0e10513938e1da168155d49a7f1a91828fafae6661e9af0aaadcee3c8acef9e749f320c9aeb4f6a2d4412aaddd3a58565579b9154b6815a39d
|
7
|
+
data.tar.gz: 7c5e76c1162e9b565121db522fe6d8baa6e3b9c92c8259e9ac72bc25927f6b01cc8de7d3c93b2e9b64c3c6074d07ce0daea72e6bf7aae4b2cd1303dd7aeada15
|
data/README.md
CHANGED
@@ -1,8 +1,10 @@
|
|
1
|
-
|
1
|
+
I18n::Cocoa
|
2
|
+
===========
|
2
3
|
|
3
4
|
Manage translation and localization with static analysis, for iOS, OSX
|
4
5
|
|
5
|
-
|
6
|
+
Installation
|
7
|
+
----------
|
6
8
|
|
7
9
|
Add this line to your application's Gemfile:
|
8
10
|
|
@@ -18,11 +20,26 @@ Or install it yourself as:
|
|
18
20
|
|
19
21
|
$ gem install i18n-cocoa
|
20
22
|
|
21
|
-
|
23
|
+
Usage
|
24
|
+
----------
|
22
25
|
|
23
|
-
|
26
|
+
**Check health**
|
27
|
+
```ruby
|
28
|
+
|
29
|
+
attributes = {:localized_macro_string => 'LocalizedString', :search_path => 'iOSProject'}
|
30
|
+
success, failure_issues = I18n::Cocoa.health attributes
|
31
|
+
|
32
|
+
```
|
33
|
+
|
34
|
+
Features
|
35
|
+
----------
|
36
|
+
|
37
|
+
- [x] Ensure to not forget to add localized string literal with key in `.strings` files
|
38
|
+
- [x] Find to unused localizaed key in files and strip them from these files
|
39
|
+
- [ ] Comprehensive Unit Test Coverage
|
24
40
|
|
25
|
-
|
41
|
+
Contributing
|
42
|
+
----------
|
26
43
|
|
27
44
|
1. Fork it ( https://github.com/hirohisa/i18n-cocoa/fork )
|
28
45
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
data/lib/i18n/cocoa/finder.rb
CHANGED
@@ -30,6 +30,22 @@ module I18n
|
|
30
30
|
[failure_issues.count == 0, failure_issues]
|
31
31
|
end
|
32
32
|
|
33
|
+
def find_unused_localization
|
34
|
+
# use localized key but key doesnt exist in strings file
|
35
|
+
used_keys = _get_used_localized_keys_from_method_files
|
36
|
+
localized_keys = _get_localized_keys_from_strings_files
|
37
|
+
|
38
|
+
unused_keys = _contain_keys_in_localized_keys localized_keys, used_keys
|
39
|
+
|
40
|
+
unused_keys
|
41
|
+
end
|
42
|
+
|
43
|
+
def delete_localization_keys keys
|
44
|
+
for file_path in @localized_file_paths do
|
45
|
+
_rewrite_strings_file file_path, keys
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
33
49
|
private
|
34
50
|
def _search_file_paths directory_path
|
35
51
|
Dir::foreach(directory_path) do |f|
|
@@ -136,6 +152,28 @@ module I18n
|
|
136
152
|
|
137
153
|
diff
|
138
154
|
end
|
155
|
+
|
156
|
+
def _rewrite_strings_file file_path, exclude_keys
|
157
|
+
temp_path = './tmp'
|
158
|
+
temp_file = File.new(temp_path, "w")
|
159
|
+
|
160
|
+
f = File.new(file_path, "r")
|
161
|
+
f.readlines.each do |l|
|
162
|
+
needs_copy = true
|
163
|
+
|
164
|
+
match = /^"([^"]+)"[ ]*=[ ]*"([^"]+)";[\r\n]*$/.match(l)
|
165
|
+
if !match.nil? && match.size == 3
|
166
|
+
needs_copy = false if exclude_keys.include?match[1]
|
167
|
+
end
|
168
|
+
|
169
|
+
temp_file.puts l if needs_copy
|
170
|
+
end
|
171
|
+
f.close
|
172
|
+
temp_file.close
|
173
|
+
|
174
|
+
FileUtils.move temp_path, file_path
|
175
|
+
end
|
176
|
+
|
139
177
|
end
|
140
178
|
end
|
141
179
|
end
|
data/lib/i18n/cocoa/version.rb
CHANGED
data/lib/i18n/cocoa.rb
CHANGED
@@ -10,6 +10,9 @@ module I18n
|
|
10
10
|
def self.health attributes = {}
|
11
11
|
finder = Finder.new(config.update attributes)
|
12
12
|
finder.ensure_localization
|
13
|
+
|
14
|
+
unused_keys = finder.find_unused_localization
|
15
|
+
finder.delete_localization_keys unless unused_keys.empty?
|
13
16
|
end
|
14
17
|
|
15
18
|
def self.config
|