i18n-cocoa 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/i18n/cocoa/finder.rb +33 -32
- data/lib/i18n/cocoa/utils.rb +7 -2
- data/lib/i18n/cocoa/version.rb +1 -1
- 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: cf33f6d55b0323e9fc5c980f82f3e59515ac2a50
|
4
|
+
data.tar.gz: c00f49d7b1c616a240b2885827389361f238837c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eb33bc5501a7feb7ba5c11d68cdb76fec4d95864bc5a67af5a0eb72d87c828bc524978a77874be78892f23e1f0d04122d01312788585c800ae32284ac6ab430d
|
7
|
+
data.tar.gz: 7c092cad942b9e6825af738ab9c745b3b991ead3e28ab53d6a8b93553035579733a2d7739d2ab33ae4159f6cbcfa7011ae89a296b656297ce9f1152bd5427a15
|
data/lib/i18n/cocoa/finder.rb
CHANGED
@@ -9,7 +9,7 @@ module I18n
|
|
9
9
|
def initialize localized_macro_string='NSLocalizedString'
|
10
10
|
@localized_macro_string = localized_macro_string
|
11
11
|
@method_file_paths = []
|
12
|
-
@
|
12
|
+
@localized_file_paths = []
|
13
13
|
|
14
14
|
_search_file_paths File.absolute_path(".")
|
15
15
|
end
|
@@ -33,43 +33,43 @@ module I18n
|
|
33
33
|
[failure_issues.count == 0, failure_issues]
|
34
34
|
end
|
35
35
|
|
36
|
-
private
|
37
|
-
|
38
|
-
|
39
|
-
|
36
|
+
private
|
37
|
+
def _search_file_paths directory_path
|
38
|
+
Dir::foreach(directory_path) do |f|
|
39
|
+
current_file_path = "#{directory_path}/#{f}"
|
40
40
|
|
41
|
-
|
41
|
+
assort_with_extension current_file_path unless File.directory?current_file_path
|
42
42
|
|
43
|
-
|
43
|
+
_search_file_paths current_file_path if _need_to_search_in_directory? current_file_path
|
44
|
+
end
|
44
45
|
end
|
45
|
-
end
|
46
46
|
|
47
|
-
|
48
|
-
|
47
|
+
def assort_with_extension file_path
|
48
|
+
return if File.directory?file_path
|
49
49
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
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
|
56
57
|
end
|
57
|
-
end
|
58
58
|
|
59
|
-
|
60
|
-
|
59
|
+
def _need_to_search_in_directory? file_path
|
60
|
+
return false unless File.directory? file_path
|
61
61
|
|
62
|
-
|
63
|
-
|
62
|
+
file_name = file_path.split('/').last
|
63
|
+
return false if file_name.start_with?"." # '.', '..', '.git'
|
64
64
|
|
65
|
-
|
66
|
-
|
67
|
-
|
65
|
+
extension = file_name.split('.').last
|
66
|
+
xcode_extensions = ['xcodeproj', 'xcassets', 'xcworkspace']
|
67
|
+
return false if xcode_extensions.include?extension # directory for xcode
|
68
68
|
|
69
|
-
|
69
|
+
# TODO: support Pods, Carthage
|
70
70
|
|
71
|
-
|
72
|
-
|
71
|
+
true
|
72
|
+
end
|
73
73
|
|
74
74
|
def _find_lines_using_variable_key_in_method_files
|
75
75
|
lines = []
|
@@ -118,15 +118,16 @@ private
|
|
118
118
|
def _get_localized_keys_from_strings_files
|
119
119
|
keys = []
|
120
120
|
|
121
|
-
@
|
122
|
-
f = File.new(
|
121
|
+
@localized_file_paths.each do |file_path|
|
122
|
+
f = File.new(file_path, "r")
|
123
123
|
f.readlines.each do |l|
|
124
|
+
l = Utils.encode l
|
124
125
|
next if l.start_with?("//")
|
125
126
|
|
126
|
-
|
127
|
-
next if
|
127
|
+
m = /^"([^"]+)"[ ]*=[ ]*"([^"]+)";[\r\n]*$/.match(l)
|
128
|
+
next if m.nil?
|
128
129
|
|
129
|
-
keys <<
|
130
|
+
keys << m[1] if m.size == 3
|
130
131
|
end
|
131
132
|
end
|
132
133
|
|
data/lib/i18n/cocoa/utils.rb
CHANGED
@@ -5,8 +5,13 @@ module I18n
|
|
5
5
|
|
6
6
|
def self.encode string
|
7
7
|
# invalid byte sequence in US-ASCII (ArgumentError)
|
8
|
-
string
|
9
|
-
|
8
|
+
replace_invalid_byte string
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.replace_invalid_byte string
|
12
|
+
replace_options = { invalid: :replace, undef: :replace, replace: '?' }
|
13
|
+
temporal_encoding = (string.encoding == Encoding::UTF_8 ? Encoding::UTF_16BE : Encoding::UTF_8)
|
14
|
+
string.encode(temporal_encoding, string.encoding, replace_options).encode(string.encoding)
|
10
15
|
end
|
11
16
|
|
12
17
|
def self.create_issue title, description
|
data/lib/i18n/cocoa/version.rb
CHANGED