i18n-cocoa 0.0.3 → 0.0.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5fb89f4fc53709c2d624e976a3284b20e6946387
4
- data.tar.gz: 4dc100da833def9078cc5f3ff16bd166dfcf1ec1
3
+ metadata.gz: ebbf5b1991105d808fe06a8aee71c4f192146ad6
4
+ data.tar.gz: 2f6d1da8e9936f5dfdb35f1344da1708a7e1656b
5
5
  SHA512:
6
- metadata.gz: 5d5a4582799d1018027ca73f2c0807cebf7c80c76803109d2ecd9f3efbfe6172e4a51651650e5a0e008c2ba49fb46399934595e2188e0b2537d7bc462f362230
7
- data.tar.gz: 3520e52f7973b64a405ae2780de1eff0737d728828bd803aa8294d7e980f863dfb6a8dea1fcf5fa55aace35cf69f9df0f444e95f27f6f0e5b2ef5d6393b94b45
6
+ metadata.gz: c4d709cb57f9ed0e10513938e1da168155d49a7f1a91828fafae6661e9af0aaadcee3c8acef9e749f320c9aeb4f6a2d4412aaddd3a58565579b9154b6815a39d
7
+ data.tar.gz: 7c5e76c1162e9b565121db522fe6d8baa6e3b9c92c8259e9ac72bc25927f6b01cc8de7d3c93b2e9b64c3c6074d07ce0daea72e6bf7aae4b2cd1303dd7aeada15
data/README.md CHANGED
@@ -1,8 +1,10 @@
1
- # I18n::Cocoa
1
+ I18n::Cocoa
2
+ ===========
2
3
 
3
4
  Manage translation and localization with static analysis, for iOS, OSX
4
5
 
5
- ## Installation
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
- ## Usage
23
+ Usage
24
+ ----------
22
25
 
23
- TODO: Write usage instructions here
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
- ## Contributing
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`)
@@ -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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module I18n
4
4
  module Cocoa
5
- VERSION = "0.0.3"
5
+ VERSION = "0.0.4"
6
6
  end
7
7
  end
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: i18n-cocoa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hirohisa Kawasaki