i18n-cocoa 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a1eb0526aedea5961090b2d46dd620bf93c8ecab
4
- data.tar.gz: 4b7051aece56792387f818b966d5db3a67979438
3
+ metadata.gz: 6f1db96f338cb21a8c6508b5dfd2fafd5c361c45
4
+ data.tar.gz: 9b2796a5325d819a1ab4c6a81fd2e7bbcb6fe35e
5
5
  SHA512:
6
- metadata.gz: cd10d236fa6d9fe5f6a66ce8887fa5052bfa0a40dda202e923466b92b783d346580f6734eef308663b69d7b689141018d3ad18f440a1631e3cac1a4f28e8ae7e
7
- data.tar.gz: 8f995eb12b31fb268ab60d7d27cda0816de7778f0e7ab45af513e18046b78e139140177c89b291271a751da7617c5398c46f56f5c942e34b70f6f17709f3f9dc
6
+ metadata.gz: 3797e915cc12f784c986eaff184a44bfa356c1933bca3bf5e58f610033d4fdf331a9aaf6ed1c11c79dadb1466252cd5da7ec07124fd103488a72cdc0be70cb86
7
+ data.tar.gz: 63bc6068a590970076a1af00ab7eb5c4d0ad6137715e514debdc798fbe305d5fb11c631491c1e300ca5048e683ec19b38fbdde04be973f59facbdce64f6d0f81
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2015 Hirohisa Kawasaki, Shiya Keita
1
+ Copyright (c) 2015 Hirohisa Kawasaki, Keita Shiya
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- i18n::Cocoa
1
+ i18n::Cocoa [![Gem-version](https://img.shields.io/gem/v/i18n-cocoa.svg)](https://rubygems.org/gems/i18n-cocoa) [![Gem-downloads](https://img.shields.io/gem/dt/i18n-cocoa.svg)](https://rubygems.org/gems/i18n-cocoa) [![LICENSE](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/hirohisa/i18n-cocoa/blob/master/LICENSE)
2
2
  ===========
3
3
 
4
4
  i18n-cocoa manages translation and localization with analysis, for iOS, OSX.
@@ -60,8 +60,9 @@ Features
60
60
  ----------
61
61
 
62
62
  - [x] Ensure to not forget to add localized string literal with key in `.strings` files
63
- - [x] Find to unused localizaed key in files and strip them from these files
64
- - [ ] Output documentation
63
+ - [x] Find to unused localized keys in files and strip them from these files
64
+ - [x] Documentation
65
+ - [ ] Find unused localized keys in files per language
65
66
  - [ ] Comprehensive Unit Test Coverage
66
67
 
67
68
  Contributing
@@ -5,8 +5,13 @@ module I18n
5
5
 
6
6
  class Finder
7
7
 
8
+ # search files and scan code class
9
+ #
10
+ # default setting, it scan macro format is 'NSLocalizedString' in current directory.
11
+ #
12
+ # @param [hash] attributes are settings data about file path, marco ...more.
8
13
  def initialize attributes
9
- config = default_config.update attributes
14
+ config = _default_config.update attributes
10
15
  @localized_macro_string = config[:localized_macro_string]
11
16
  @method_file_paths = []
12
17
  @localized_file_paths = []
@@ -14,13 +19,10 @@ module I18n
14
19
  _search_file_paths File.absolute_path(config[:search_path])
15
20
  end
16
21
 
17
- def default_config
18
- {
19
- :localized_macro_string => 'NSLocalizedString',
20
- :search_path => '.'
21
- }
22
- end
23
-
22
+ # validate localization
23
+ #
24
+ # @return [bool] result for validation, success is true, failure is false
25
+ # @return [array] failure issues for localization
24
26
  def ensure_localization
25
27
  failure_issues = []
26
28
 
@@ -38,8 +40,10 @@ module I18n
38
40
  [failure_issues.count == 0, failure_issues]
39
41
  end
40
42
 
43
+ # use localized key but key doesnt exist in strings file
44
+ #
45
+ # @return [array] unused keys that are not include code in project, exist in localized strings file
41
46
  def find_unused_localization
42
- # use localized key but key doesnt exist in strings file
43
47
  used_keys = _get_used_localized_keys_from_method_files
44
48
  localized_keys = _get_localized_keys_from_strings_files
45
49
 
@@ -48,13 +52,26 @@ module I18n
48
52
  unused_keys
49
53
  end
50
54
 
55
+ # remove localized keys from localized strings file
56
+ #
57
+ # @param [array] keys are localized keys for removing from strings file
58
+ # @return [bool] true when finish to run
51
59
  def delete_localization_keys keys
52
60
  for file_path in @localized_file_paths do
53
61
  _rewrite_strings_file file_path, keys
54
62
  end
63
+
64
+ true
55
65
  end
56
66
 
57
67
  private
68
+ def _default_config
69
+ {
70
+ :localized_macro_string => 'NSLocalizedString',
71
+ :search_path => '.'
72
+ }
73
+ end
74
+
58
75
  def _search_file_paths directory_path
59
76
  Dir::foreach(directory_path) do |f|
60
77
  current_file_path = "#{directory_path}/#{f}"
@@ -2,7 +2,11 @@ module I18n
2
2
  module Cocoa
3
3
 
4
4
  class Issue
5
- attr_reader :description, :values
5
+ # @return [string] set information
6
+ attr_reader :description
7
+
8
+ # @return [array] set problem's data
9
+ attr_reader :values
6
10
 
7
11
  def initialize description, values
8
12
  @description = description
@@ -2,6 +2,6 @@
2
2
 
3
3
  module I18n
4
4
  module Cocoa
5
- VERSION = "0.0.6"
5
+ VERSION = "0.0.7"
6
6
  end
7
7
  end
data/lib/i18n/cocoa.rb CHANGED
@@ -7,23 +7,46 @@ require "i18n/cocoa/finder"
7
7
  module I18n
8
8
  module Cocoa
9
9
 
10
+ # validate localization and strip unused keys
11
+ #
12
+ # @param [hash] attributes if you want to change from default attributes
13
+ # default attributes
14
+ # :localized_macro_string => 'NSLocalizedString',
15
+ # :search_path => '.'
16
+ #
17
+ # @return [bool] true when finish to run with success
10
18
  def self.health attributes = {}
11
19
  finder = Finder.new(attributes)
12
- finder.ensure_localization
20
+ result, issues = finder.ensure_localization
21
+ return false unless result
13
22
 
14
23
  unused_keys = finder.find_unused_localization
15
24
  finder.delete_localization_keys unless unused_keys.empty?
25
+
26
+ true
16
27
  end
17
28
 
29
+ # find unused keys from localized strings files
30
+ #
31
+ # @param [hash] attributes if you want to change from default attributes
32
+ # @return [array] unused keys that are not include code in project, exist in localized strings file
18
33
  def self.unused attributes = {}
19
34
  finder = Finder.new(attributes)
20
- finder.find_unused_localization
35
+ unused_keys = finder.find_unused_localization
36
+
37
+ unused_keys
21
38
  end
22
39
 
40
+ # find unused keys and strip them from localized strings files
41
+ #
42
+ # @param [hash] attributes if you want to change from default attributes
43
+ # @return [bool] true when finish to run with success
23
44
  def self.remove_unused attributes = {}
24
45
  finder = Finder.new(attributes)
25
46
  unused_keys = finder.find_unused_localization
26
47
  finder.delete_localization_keys unless unused_keys.empty?
48
+
49
+ true
27
50
  end
28
51
 
29
52
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: i18n-cocoa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hirohisa Kawasaki
8
- - Shiya Keita
8
+ - Keita Shiya
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-01-30 00:00:00.000000000 Z
12
+ date: 2015-02-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -96,3 +96,4 @@ summary: Manage translation and localization
96
96
  test_files:
97
97
  - spec/i18n/cocoa_spec.rb
98
98
  - spec/spec_helper.rb
99
+ has_rdoc: