localio 0.0.5 → 0.0.6
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 +4 -4
- data/README.md +16 -0
- data/lib/localio/filter.rb +43 -0
- data/lib/localio/locfile.rb +7 -1
- data/lib/localio/version.rb +1 -1
- data/lib/localio.rb +8 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 39d9b5aadd69284bfc028292593d32542d7a2e4c
|
4
|
+
data.tar.gz: 774644985e41203021c6fa0ae3ac75bb3055cdda
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1cc01458194b6dccd78b82f5f7bf90fdc7d232bf1144428b3ee03af269749dcb49c3107b6705d41c0307dde794b70391423de4595dab41b895aff759ac406e7b
|
7
|
+
data.tar.gz: 964ad35325bac5a19a5a866d46b37692a354db3a833dad346068cd435daf096253181712111b5603908a60ce14df34945ea5e40a19e241dad5b8a0f3aba0cb52
|
data/README.md
CHANGED
@@ -151,6 +151,22 @@ formatting :camel_case
|
|
151
151
|
|
152
152
|
Normally you would want a smart formatter, because it is adjusted (or tries to) to the usual code conventions of each platform for localizable strings.
|
153
153
|
|
154
|
+
### Filtering content
|
155
|
+
|
156
|
+
We can establish filters to the keys by using regular expressions.
|
157
|
+
|
158
|
+
The exclusions are managed with the `except` command. For example, if we don't want to include the translations where the key has the "[a]" string, we could include this in the Locfile.
|
159
|
+
|
160
|
+
````ruby
|
161
|
+
except :keys => '[\[][a][\]]'
|
162
|
+
````
|
163
|
+
|
164
|
+
We can filter inversely too, with the command `only`. For example, if we only want the translations that contain the '[a]' token, we should use:
|
165
|
+
|
166
|
+
````ruby
|
167
|
+
only :keys => '[\[][a][\]]'
|
168
|
+
````
|
169
|
+
|
154
170
|
## Contributing
|
155
171
|
|
156
172
|
Please read the [contributing guide](https://github.com/mrmans0n/localio/blob/master/CONTRIBUTING.md).
|
@@ -0,0 +1,43 @@
|
|
1
|
+
class Filter
|
2
|
+
def self.apply_filter(segments, only, except)
|
3
|
+
|
4
|
+
segments = only segments, only[:keys] unless only.nil?
|
5
|
+
segments = except segments, except[:keys] unless except.nil?
|
6
|
+
|
7
|
+
segments
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def self.only segments, keys_filter
|
13
|
+
|
14
|
+
filtered_segments = []
|
15
|
+
segments.each do |segment|
|
16
|
+
is_okay = true
|
17
|
+
unless keys_filter.nil?
|
18
|
+
result = /#{keys_filter}/ =~ segment.keyword
|
19
|
+
is_okay = false if result.nil?
|
20
|
+
end
|
21
|
+
|
22
|
+
filtered_segments << segment if is_okay
|
23
|
+
end
|
24
|
+
|
25
|
+
filtered_segments
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.except segments, keys_filter
|
29
|
+
filtered_segments = []
|
30
|
+
segments.each do |segment|
|
31
|
+
is_okay = true
|
32
|
+
unless keys_filter.nil?
|
33
|
+
result = /#{keys_filter}/ =~ segment.keyword
|
34
|
+
is_okay = false unless result.nil?
|
35
|
+
end
|
36
|
+
|
37
|
+
filtered_segments << segment if is_okay
|
38
|
+
end
|
39
|
+
|
40
|
+
filtered_segments
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
data/lib/localio/locfile.rb
CHANGED
@@ -5,7 +5,7 @@ class Locfile
|
|
5
5
|
# Specify the target platform for the localizables
|
6
6
|
#
|
7
7
|
# possible values
|
8
|
-
# :android, :ios, :
|
8
|
+
# :android, :ios, :rails, :json
|
9
9
|
dsl_accessor :platform
|
10
10
|
|
11
11
|
# Specifies the filesystem path where the generated files will be
|
@@ -19,6 +19,12 @@ class Locfile
|
|
19
19
|
# :none - no formatting done, the keys will be used as
|
20
20
|
dsl_accessor :formatting
|
21
21
|
|
22
|
+
# Specify a filter that we can use for keys. It would work as "put everything except what matches with this key"
|
23
|
+
dsl_accessor :except
|
24
|
+
|
25
|
+
# Specify a filter that we can use for keys. It would work as "put only what matches with this key"
|
26
|
+
dsl_accessor :only
|
27
|
+
|
22
28
|
# Defined using 'source' ideally
|
23
29
|
dsl_accessor :source_service, :source_options
|
24
30
|
|
data/lib/localio/version.rb
CHANGED
data/lib/localio.rb
CHANGED
@@ -2,6 +2,7 @@ require 'localio/version'
|
|
2
2
|
require 'localio/locfile'
|
3
3
|
require 'localio/processor'
|
4
4
|
require 'localio/localizable_writer'
|
5
|
+
require 'localio/filter'
|
5
6
|
|
6
7
|
module Localio
|
7
8
|
|
@@ -31,6 +32,7 @@ module Localio
|
|
31
32
|
|
32
33
|
def self.generate_localizables
|
33
34
|
process_to_memory
|
35
|
+
apply_filters
|
34
36
|
build_localizables
|
35
37
|
end
|
36
38
|
|
@@ -39,6 +41,12 @@ module Localio
|
|
39
41
|
@configuration.source_options
|
40
42
|
end
|
41
43
|
|
44
|
+
def self.apply_filters
|
45
|
+
@localizables[:segments] = Filter.apply_filter @localizables[:segments],
|
46
|
+
@configuration.only,
|
47
|
+
@configuration.except
|
48
|
+
end
|
49
|
+
|
42
50
|
def self.build_localizables
|
43
51
|
LocalizableWriter.write @configuration.platform,
|
44
52
|
@localizables[:languages],
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: localio
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nacho Lopez
|
@@ -111,6 +111,7 @@ files:
|
|
111
111
|
- Rakefile
|
112
112
|
- bin/localize
|
113
113
|
- lib/localio.rb
|
114
|
+
- lib/localio/filter.rb
|
114
115
|
- lib/localio/formatter.rb
|
115
116
|
- lib/localio/localizable_writer.rb
|
116
117
|
- lib/localio/locfile.rb
|