traduction 0.0.2 → 0.0.3
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 +8 -3
- data/lib/tasks/traduction.rake +16 -0
- data/lib/traduction/hash_methods.rb +19 -0
- data/lib/traduction/i18n.rb +24 -16
- data/lib/traduction/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7896ef7c18bc6753af115c08c21d08853872306f
|
4
|
+
data.tar.gz: 16a30f34948b80f751b9f99fd270fef7fbe1c0ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 84101da38daa7cf6f464d9358e114ba1d53c6a5f0565e63082d2c13dca4ae23c5df365ed6b09e832c5e2f30a5307f85d5444d0cd05d4df823f199aab8c846411
|
7
|
+
data.tar.gz: a52079aaff217cd3e19432757122c76cb8bee75e39618b1912f682621019a92a9466e91c895f6ade2189030a3be8e5d3247129b510b426b8fce65a0fa53d896e
|
data/README.md
CHANGED
@@ -24,14 +24,19 @@ Using Rake tasks, you may list :
|
|
24
24
|
- obsolete changes in a specific locale, compared to default locale
|
25
25
|
- untranslated changes in a specific locale, still compared to default locale
|
26
26
|
- added keys since an old git commit
|
27
|
+
- all keys including modifications from a file (the file you might get back from translators)
|
28
|
+
|
29
|
+
Format used for import/output is CSV having ';' as field separator and '"' as text quote char.
|
27
30
|
|
28
31
|
Rake tasks are prefixed by 'traduction' namespace :
|
29
32
|
|
30
33
|
```
|
31
34
|
$ rake -T | grep 'traduction'
|
32
|
-
rake traduction:added[locale,revision]
|
33
|
-
rake traduction:
|
34
|
-
rake traduction:
|
35
|
+
rake traduction:added[locale,revision] # Show added keys for locale LOCALE since git revision
|
36
|
+
rake traduction:all[locale] # Show all keys for locale LOCALE
|
37
|
+
rake traduction:import[locale,filename] # List keys from csv file returned by translators
|
38
|
+
rake traduction:obsolete[locale] # Show obsolete keys for locale LOCALE
|
39
|
+
rake traduction:untranslated[locale] # Show untranslated keys for locale LOCALE
|
35
40
|
```
|
36
41
|
|
37
42
|
If you do not specify locale, Traduction will use `I18n.default_locale`.
|
data/lib/tasks/traduction.rake
CHANGED
@@ -8,6 +8,22 @@ end
|
|
8
8
|
|
9
9
|
namespace :traduction do
|
10
10
|
|
11
|
+
desc "Show all keys for locale LOCALE"
|
12
|
+
task :all, [:locale] do |t, args|
|
13
|
+
args.with_defaults(:locale => 'es')
|
14
|
+
locale_to_check = args.locale
|
15
|
+
default_locale = Traduction::I18n.load_default_locale
|
16
|
+
|
17
|
+
puts Traduction::I18n.diff_all(
|
18
|
+
from: [default_locale[:key], File.open(default_locale[:file])],
|
19
|
+
to: [locale_to_check, File.open(Traduction::I18n.locale_file(locale_to_check))],
|
20
|
+
prefix: locale_to_check,
|
21
|
+
header: ['All keys', 'original value', 'translated value'],
|
22
|
+
dont_ignore_values: true
|
23
|
+
)
|
24
|
+
end
|
25
|
+
task :all => :environment
|
26
|
+
|
11
27
|
desc "Show untranslated keys for locale LOCALE"
|
12
28
|
task :untranslated, [:locale] do |t, args|
|
13
29
|
args.with_defaults(:locale => 'es')
|
@@ -20,6 +20,25 @@ module Traduction
|
|
20
20
|
ret
|
21
21
|
end
|
22
22
|
|
23
|
+
def merge_hash(hash, options = {})
|
24
|
+
ret = {}
|
25
|
+
skip_remaining_hash = options[:skip_remaining_hash] || false
|
26
|
+
|
27
|
+
remaining_hash = hash
|
28
|
+
self.each do |k,v|
|
29
|
+
ret[k] = [v, hash[k]]
|
30
|
+
remaining_hash.delete(k) unless skip_remaining_hash
|
31
|
+
end
|
32
|
+
|
33
|
+
unless skip_remaining_hash
|
34
|
+
remaining_hash.each do |k,v|
|
35
|
+
ret[k] = [self[k], v]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
ret
|
40
|
+
end
|
41
|
+
|
23
42
|
def diff_more(other_hash, options = {})
|
24
43
|
ignore_values = options[:ignore_values] || false
|
25
44
|
|
data/lib/traduction/i18n.rb
CHANGED
@@ -3,23 +3,39 @@ require 'yaml'
|
|
3
3
|
module Traduction
|
4
4
|
module I18n
|
5
5
|
module I18nMethods
|
6
|
-
def
|
6
|
+
def diff_method(options = {}, &block)
|
7
7
|
from_prefix, from_content = options[:from].to_a
|
8
8
|
to_prefix, to_content = options[:to].to_a
|
9
|
-
prefix = options[:prefix]
|
10
9
|
header = options[:header]
|
11
10
|
format = options[:format] || :csv
|
11
|
+
flatten = options[:flatten] || false
|
12
12
|
|
13
13
|
from = YAML::load(from_content)[from_prefix]
|
14
14
|
to = YAML::load(to_content)[to_prefix]
|
15
15
|
|
16
|
-
data =
|
16
|
+
data = yield from, to
|
17
|
+
|
18
|
+
generate_csv(data, header: header, flatten: flatten)
|
19
|
+
end
|
17
20
|
|
18
|
-
|
21
|
+
def diff_all(options = {})
|
22
|
+
diff_method(options.merge(flatten: true)) do |from, to|
|
23
|
+
from.flatten_keys.merge_hash(to.flatten_keys)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def diff_locales(options = {})
|
28
|
+
prefix = options[:prefix]
|
29
|
+
dont_ignore_values = options[:dont_ignore_values] || false
|
30
|
+
|
31
|
+
diff_method(options) do |from, to|
|
32
|
+
diff_yaml(from, to, prefix: prefix, dont_ignore_values: dont_ignore_values)
|
33
|
+
end
|
19
34
|
end
|
20
35
|
|
21
36
|
def generate_csv(data, options = {})
|
22
37
|
header = options[:header] || nil
|
38
|
+
flatten = options[:flatten] || false
|
23
39
|
|
24
40
|
CSV.generate(Traduction::CSV_FORMAT) do |csv|
|
25
41
|
unless header.nil?
|
@@ -30,7 +46,8 @@ module Traduction
|
|
30
46
|
csv << header
|
31
47
|
end
|
32
48
|
end
|
33
|
-
|
49
|
+
#binding.pry
|
50
|
+
data.each { |m| csv << (flatten ? m.flatten : m) } if data.present?
|
34
51
|
end
|
35
52
|
end
|
36
53
|
|
@@ -48,9 +65,10 @@ module Traduction
|
|
48
65
|
|
49
66
|
def diff_yaml(from, to, options = {}, &block)
|
50
67
|
prefix = options[:prefix] || nil
|
68
|
+
ignore_values = !(options[:dont_ignore_values] || false)
|
51
69
|
data = []
|
52
70
|
|
53
|
-
from.diff_more(to, :ignore_values =>
|
71
|
+
from.diff_more(to, :ignore_values => ignore_values).flatten_keys(prefix).each do |k,v|
|
54
72
|
data << [k,v]
|
55
73
|
end
|
56
74
|
|
@@ -61,13 +79,3 @@ module Traduction
|
|
61
79
|
extend I18nMethods
|
62
80
|
end
|
63
81
|
end
|
64
|
-
#
|
65
|
-
#
|
66
|
-
#text: (CSV.generate do |csv|
|
67
|
-
# 63 csv << @header
|
68
|
-
# 64 @ragreements.each do |o|
|
69
|
-
# 65 csv << o.values.map { |l| l.is_a?(Array) ? l.join("\n") : l }
|
70
|
-
# 66 end
|
71
|
-
# 67 end)
|
72
|
-
#
|
73
|
-
#
|
data/lib/traduction/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: traduction
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas Kienlen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-07-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -132,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
132
132
|
version: '0'
|
133
133
|
requirements: []
|
134
134
|
rubyforge_project:
|
135
|
-
rubygems_version: 2.0.
|
135
|
+
rubygems_version: 2.0.3
|
136
136
|
signing_key:
|
137
137
|
specification_version: 4
|
138
138
|
summary: Help maintaining Rails translation files
|