i18n-cocoa 0.0.1
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 +7 -0
- data/LICENSE +22 -0
- data/README.md +31 -0
- data/lib/i18n/cocoa/finder.rb +143 -0
- data/lib/i18n/cocoa/utils.rb +17 -0
- data/lib/i18n/cocoa/version.rb +7 -0
- data/lib/i18n/cocoa.rb +16 -0
- data/spec/i18n/cocoa_spec.rb +11 -0
- data/spec/spec_helper.rb +2 -0
- metadata +98 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f66d36a153926975436d4239f13ccf052ca05164
|
4
|
+
data.tar.gz: 7550e2a670addbc6bb7b23588dd6b9ed2e36e045
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 98aaec479882ec958d9609d8a2bc5c898bfe94c3c68523d860ec75f43982045ac074de0036a3554396df0c3f6725cfe018acd1ad70c07b41cd31f3ae1b37b88e
|
7
|
+
data.tar.gz: 1ef90d411f124ce5b0c72f615875ed3a847870b98f67e2acc561cb3d1768b130b3c7550763d68c04777314d00b95d0f671e3770c6f50f996c389ddbe1aa01d2e
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Hirohisa Kawasaki, Shiya Keita
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# I18n::Cocoa
|
2
|
+
|
3
|
+
Manage translation and localization with static analysis, for iOS, OSX
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'i18n-cocoa'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install i18n-cocoa
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it ( https://github.com/hirohisa/i18n-cocoa/fork )
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create a new Pull Request
|
@@ -0,0 +1,143 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'pp'
|
3
|
+
|
4
|
+
module I18n
|
5
|
+
module Cocoa
|
6
|
+
|
7
|
+
class Finder
|
8
|
+
|
9
|
+
def initialize localized_macro_string='NSLocalizedString'
|
10
|
+
@localized_macro_string = localized_macro_string
|
11
|
+
@method_file_paths = []
|
12
|
+
@lozalized_file_paths = []
|
13
|
+
|
14
|
+
_search_file_paths File.absolute_path(".")
|
15
|
+
end
|
16
|
+
|
17
|
+
def ensure_localization
|
18
|
+
failure_issues = []
|
19
|
+
|
20
|
+
# use variable key for localization
|
21
|
+
lines_with_variable_and_logic = _find_lines_using_variable_key_in_method_files
|
22
|
+
lines_with_variable_and_logic.each do |l|
|
23
|
+
failure_issues << Utils.create_issue("found to set varible keys with logic", l)
|
24
|
+
end
|
25
|
+
|
26
|
+
# use localized key but key doesnt exist in strings file
|
27
|
+
used_keys = _get_used_localized_keys_from_method_files
|
28
|
+
localized_keys = _get_localized_keys_from_strings_files
|
29
|
+
|
30
|
+
forgot_keys = _contain_keys_in_localized_keys used_keys, localized_keys
|
31
|
+
failure_issues << Utils.create_issue("found to forget keys", forgot_keys.join(", ")) if forgot_keys.count > 0
|
32
|
+
|
33
|
+
[failure_issues.count == 0, failure_issues]
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
def _search_file_paths directory_path
|
38
|
+
Dir::foreach(directory_path) do |f|
|
39
|
+
current_file_path = "#{directory_path}/#{f}"
|
40
|
+
|
41
|
+
assort_with_extension current_file_path unless File.directory?current_file_path
|
42
|
+
|
43
|
+
_search_file_paths current_file_path if _need_to_search_in_directory? current_file_path
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def assort_with_extension file_path
|
48
|
+
return if File.directory?file_path
|
49
|
+
|
50
|
+
extension = file_path.split('.').last
|
51
|
+
case extension
|
52
|
+
when 'm', 'mm', 'swift'
|
53
|
+
@method_file_paths << file_path
|
54
|
+
when 'strings'
|
55
|
+
@localized_file_paths << file_path
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def _need_to_search_in_directory? file_path
|
60
|
+
return false unless File.directory? file_path
|
61
|
+
|
62
|
+
file_name = file_path.split('/').last
|
63
|
+
return false if file_name.start_with?"." # '.', '..', '.git'
|
64
|
+
|
65
|
+
extension = file_name.split('.').last
|
66
|
+
xcode_extensions = ['xcodeproj', 'xcassets', 'xcworkspace']
|
67
|
+
return false if xcode_extensions.include?extension # directory for xcode
|
68
|
+
|
69
|
+
# TODO: support Pods, Carthage
|
70
|
+
|
71
|
+
true
|
72
|
+
end
|
73
|
+
|
74
|
+
def _find_lines_using_variable_key_in_method_files
|
75
|
+
lines = []
|
76
|
+
|
77
|
+
@method_file_paths.each do |file_path|
|
78
|
+
f = File.new(file_path, "r")
|
79
|
+
f.readlines.each do |l|
|
80
|
+
line = Utils.encode l
|
81
|
+
|
82
|
+
m = /#{@localized_macro_string}\([^@\"]+\)/.match(line)
|
83
|
+
next if m.nil?
|
84
|
+
|
85
|
+
lines << line.strip
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
lines
|
90
|
+
end
|
91
|
+
|
92
|
+
def _get_used_localized_keys_from_method_files
|
93
|
+
keys = []
|
94
|
+
|
95
|
+
@method_file_paths.each do |file_path|
|
96
|
+
f = File.new(file_path, "r")
|
97
|
+
f.readlines.each do |l|
|
98
|
+
l = Utils.encode l
|
99
|
+
next if l.strip.empty?
|
100
|
+
|
101
|
+
found_keys = _find_localized_macro_from_line l.strip
|
102
|
+
found_keys.each {|k| keys << k } unless found_keys.empty?
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
keys.uniq
|
107
|
+
end
|
108
|
+
|
109
|
+
def _find_localized_macro_from_line line
|
110
|
+
pattern = @localized_macro_string + '\(@"([^"]*)"[^\)]*\)'
|
111
|
+
result = line.scan /#{pattern}/
|
112
|
+
|
113
|
+
return result.flatten unless result.empty?
|
114
|
+
|
115
|
+
[]
|
116
|
+
end
|
117
|
+
|
118
|
+
def _get_localized_keys_from_strings_files
|
119
|
+
keys = []
|
120
|
+
|
121
|
+
@lozalized_file_paths.each do |file_path|
|
122
|
+
f = File.new(path, "r")
|
123
|
+
f.readlines.each do |l|
|
124
|
+
next if l.start_with?("//")
|
125
|
+
|
126
|
+
match = /^"([^"]+)"[ ]*=[ ]*"([^"]+)";[\r\n]*$/.match(l)
|
127
|
+
next if match.nil?
|
128
|
+
|
129
|
+
keys << match[1] if match.size == 3
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
keys
|
134
|
+
end
|
135
|
+
|
136
|
+
def _contain_keys_in_localized_keys used_keys, localized_keys
|
137
|
+
diff = used_keys - localized_keys
|
138
|
+
|
139
|
+
diff
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module I18n
|
2
|
+
module Cocoa
|
3
|
+
|
4
|
+
module Utils
|
5
|
+
|
6
|
+
def self.encode string
|
7
|
+
# invalid byte sequence in US-ASCII (ArgumentError)
|
8
|
+
string.force_encoding('UTF-8')
|
9
|
+
string.encode("UTF-8", "UTF-8")
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.create_issue title, description
|
13
|
+
"#{title}: #{description}"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/i18n/cocoa.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require "i18n/cocoa/version"
|
4
|
+
require "i18n/cocoa/utils"
|
5
|
+
require "i18n/cocoa/finder"
|
6
|
+
|
7
|
+
module I18n
|
8
|
+
module Cocoa
|
9
|
+
|
10
|
+
def self.health localized_macro_string='NSLocalizedString'
|
11
|
+
finder = Finder.new localized_macro_string
|
12
|
+
finder.ensure_localization
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: i18n-cocoa
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Hirohisa Kawasaki
|
8
|
+
- Shiya Keita
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2015-01-30 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ~>
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '1.7'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ~>
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '1.7'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rake
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ~>
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '10.0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ~>
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '10.0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rspec
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
description: Manage translation and localization with static analysis, for iOS
|
57
|
+
email:
|
58
|
+
- hirohisa.kawasaki@gmail.com
|
59
|
+
- keita.shiya@gmail.com
|
60
|
+
executables: []
|
61
|
+
extensions: []
|
62
|
+
extra_rdoc_files: []
|
63
|
+
files:
|
64
|
+
- lib/i18n/cocoa/finder.rb
|
65
|
+
- lib/i18n/cocoa/utils.rb
|
66
|
+
- lib/i18n/cocoa/version.rb
|
67
|
+
- lib/i18n/cocoa.rb
|
68
|
+
- spec/i18n/cocoa_spec.rb
|
69
|
+
- spec/spec_helper.rb
|
70
|
+
- README.md
|
71
|
+
- LICENSE
|
72
|
+
homepage: ''
|
73
|
+
licenses:
|
74
|
+
- MIT
|
75
|
+
metadata: {}
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
requirements: []
|
91
|
+
rubyforge_project:
|
92
|
+
rubygems_version: 2.0.14
|
93
|
+
signing_key:
|
94
|
+
specification_version: 4
|
95
|
+
summary: Manage translation and localization
|
96
|
+
test_files:
|
97
|
+
- spec/i18n/cocoa_spec.rb
|
98
|
+
- spec/spec_helper.rb
|