tidy_i18n 0.0.5 → 0.1.0
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 +9 -9
- data/lib/tidy_i18n/dictionary_converter.rb +1 -1
- data/lib/tidy_i18n/translation_keys.rb +33 -23
- metadata +9 -8
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NjNlNjVjMjQ4ZjE2ZGM4NTZjYzFmODBlOWFhMGYyMTM1YmFkN2JhOA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
7
|
-
|
6
|
+
ZTI0MjJjMjA4YjJlYmUzMDk0NGMyYmQxOWZiM2NhMmMyNzlhMjQ2ZA==
|
7
|
+
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ODNiZjQyMWIwZjNiN2E1ZTBiMjkxZjhhNDRhYWUwMjVjODU4YjVmYWU0Mjdk
|
10
|
+
YjY3MzIxY2E4MjZkZmI2YjMxMjNkZDYyZjczM2Q5NTE2ZjQ2YzUyN2NkYTBm
|
11
|
+
NWJjYTg3YzljNDNlYzdjYTA0ZjgwZDBjM2JiNmQ2Y2QyNjY5YjU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZjM0OTZhZDMwNzY1ODNiMTg5ZTljZjRlOWI4NzJlNTNmNTRkYTY4MmZmNjgy
|
14
|
+
MTU1MzZiNTQ1OWZlOTExZGM0ZGY1OTZjNjNjNDNjYmRmM2VjZTk0MGZjNjk4
|
15
|
+
N2M0M2U1ZDA1Mzc1MGE3NDc3ZWZkMTA4MjBlYjkzNzgwZmRlMTQ=
|
@@ -32,7 +32,7 @@ module TidyI18n
|
|
32
32
|
convert_dictionary(value, path)
|
33
33
|
when "Array"
|
34
34
|
value.collect { |v| convert_value(v, path) }
|
35
|
-
when "Fixnum", "FalseClass", "TrueClass", "NilClass", "Symbol"
|
35
|
+
when "Fixnum", "FalseClass", "TrueClass", "NilClass", "Symbol", "Integer"
|
36
36
|
value
|
37
37
|
else
|
38
38
|
raise InvalidTranslationValue.new("#{path.join('.')} #{value.class.name} #{value.inspect}")
|
@@ -1,4 +1,7 @@
|
|
1
|
+
require "psych"
|
2
|
+
|
1
3
|
module TidyI18n
|
4
|
+
TranslationKey = Struct.new(:name, :value)
|
2
5
|
class TranslationKeys
|
3
6
|
|
4
7
|
def self.parse(yaml)
|
@@ -7,34 +10,32 @@ module TidyI18n
|
|
7
10
|
|
8
11
|
class RepeatKeyBuilder
|
9
12
|
|
10
|
-
TranslationKey = Struct.new(:name, :value)
|
11
13
|
attr_reader :parsed_keys
|
12
14
|
|
13
15
|
def initialize
|
14
16
|
self.key_parts = []
|
15
17
|
self.parsed_keys = []
|
18
|
+
self.current_sequence_values = []
|
16
19
|
end
|
17
20
|
|
18
|
-
def start_stream(*row)
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
def start_document(*row)
|
23
|
-
# puts "start_document: #{row.inspect}"
|
21
|
+
def start_stream(*row); end
|
22
|
+
def start_document(*row); end
|
23
|
+
def start_sequence(*row)
|
24
|
+
self.building_sequence = true
|
24
25
|
end
|
25
26
|
|
26
27
|
def start_mapping(*row)
|
27
|
-
@
|
28
|
+
@most_recent_scalar = nil
|
28
29
|
end
|
29
30
|
|
30
31
|
def scalar(*row)
|
31
|
-
if
|
32
|
-
|
33
|
-
|
34
|
-
|
32
|
+
if second_half_of_pair?
|
33
|
+
append_parsed_key(row.first)
|
34
|
+
elsif building_sequence?
|
35
|
+
current_sequence_values << row.first
|
35
36
|
else
|
36
37
|
key_parts << row.first
|
37
|
-
@
|
38
|
+
@most_recent_scalar = row
|
38
39
|
end
|
39
40
|
end
|
40
41
|
|
@@ -42,22 +43,31 @@ module TidyI18n
|
|
42
43
|
@key_parts.pop
|
43
44
|
end
|
44
45
|
|
45
|
-
def end_document(*row)
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
46
|
+
def end_document(*row); end
|
47
|
+
def end_stream(*row); end
|
48
|
+
def end_sequence
|
49
|
+
append_parsed_key(current_sequence_values)
|
50
|
+
self.building_sequence = false
|
51
|
+
self.current_sequence_values = []
|
51
52
|
end
|
52
53
|
|
53
54
|
private
|
54
55
|
|
55
|
-
def
|
56
|
-
|
56
|
+
def append_parsed_key(value)
|
57
|
+
parsed_keys << TranslationKey.new(key_parts.join("."), value)
|
58
|
+
key_parts.pop
|
59
|
+
@most_recent_scalar = nil
|
60
|
+
end
|
61
|
+
|
62
|
+
def building_sequence?
|
63
|
+
building_sequence
|
57
64
|
end
|
58
65
|
|
59
|
-
|
66
|
+
def second_half_of_pair?
|
67
|
+
@most_recent_scalar && !building_sequence?
|
68
|
+
end
|
60
69
|
|
70
|
+
attr_accessor :key_parts, :building_sequence, :current_sequence_values
|
61
71
|
attr_writer :parsed_keys
|
62
72
|
|
63
73
|
end
|
@@ -74,7 +84,7 @@ module TidyI18n
|
|
74
84
|
|
75
85
|
def build_keys
|
76
86
|
builder = RepeatKeyBuilder.new
|
77
|
-
parser = Psych::Parser.new
|
87
|
+
parser = Psych::Parser.new(builder)
|
78
88
|
parser.parse(yaml)
|
79
89
|
builder.parsed_keys
|
80
90
|
end
|
metadata
CHANGED
@@ -1,27 +1,27 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tidy_i18n
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Meyer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-02-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: i18n
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
description: Helpers for I18n. Add ways to encourage clean locale organization.
|
@@ -31,17 +31,18 @@ executables: []
|
|
31
31
|
extensions: []
|
32
32
|
extra_rdoc_files: []
|
33
33
|
files:
|
34
|
+
- lib/tidy_i18n.rb
|
34
35
|
- lib/tidy_i18n/dictionary_converter.rb
|
35
36
|
- lib/tidy_i18n/duplicate_keys.rb
|
37
|
+
- lib/tidy_i18n/locales.rb
|
36
38
|
- lib/tidy_i18n/locales/reverse.rb
|
37
39
|
- lib/tidy_i18n/locales/tilde.rb
|
38
|
-
- lib/tidy_i18n/locales.rb
|
39
40
|
- lib/tidy_i18n/missing_keys.rb
|
40
41
|
- lib/tidy_i18n/translation_keys.rb
|
41
42
|
- lib/tidy_i18n/translations.rb
|
42
|
-
- lib/tidy_i18n.rb
|
43
43
|
homepage: https://github.com/ericmeyer/tidy_i18n
|
44
|
-
licenses:
|
44
|
+
licenses:
|
45
|
+
- MIT
|
45
46
|
metadata: {}
|
46
47
|
post_install_message:
|
47
48
|
rdoc_options: []
|
@@ -59,7 +60,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
59
60
|
version: '0'
|
60
61
|
requirements: []
|
61
62
|
rubyforge_project:
|
62
|
-
rubygems_version: 2.
|
63
|
+
rubygems_version: 2.4.3
|
63
64
|
signing_key:
|
64
65
|
specification_version: 4
|
65
66
|
summary: Helpers for I18n
|