translations_sync 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Changelog +3 -0
- data/README +3 -2
- data/Rakefile +1 -1
- data/lib/tasks/translations_sync.rake +37 -19
- data/lib/translations_sync.rb +14 -0
- metadata +4 -4
data/Changelog
CHANGED
data/README
CHANGED
@@ -55,9 +55,10 @@ translations occuring only in one locale.
|
|
55
55
|
This task moves the content of given KEY under the TO.
|
56
56
|
You can use all the parameters available for the translations:sync task with the default
|
57
57
|
value for the NAME equal to 'moved'.
|
58
|
-
In order to overwrite the existing file both NAME and SOURCE should be given
|
59
|
-
with the same value. For that there is the parameter IN that sets both values.
|
60
58
|
|
59
|
+
4. rake translations:remove KEY=key.to.remove
|
60
|
+
|
61
|
+
This task removes the key from the translations. NAME defalts to 'removed' here.
|
61
62
|
|
62
63
|
So far it works only for rails applications. Suggestions for others are welcome.
|
63
64
|
|
data/Rakefile
CHANGED
@@ -3,10 +3,31 @@ namespace :translations do
|
|
3
3
|
|
4
4
|
PARAMS = '. LIST=locales,to,use EXCLUDE=locales,to,ignore'
|
5
5
|
|
6
|
+
def get_ts(skip_source = false)
|
7
|
+
source = skip_source ? nil : ENV['SOURCE'] || ENV['IN']
|
8
|
+
TranslationsSync.new ENV['LIST'], ENV['EXCLUDE'], source
|
9
|
+
end
|
10
|
+
|
11
|
+
def save_files(translations, default_name)
|
12
|
+
name = ENV['NAME'] || ENV['IN'] || default_name
|
13
|
+
translations.keys.sort.each do |lang|
|
14
|
+
filename = File.join Rails.root, 'config', 'locales', "#{name}_#{lang}.yml"
|
15
|
+
print filename + ' ... '
|
16
|
+
if File.exist? filename
|
17
|
+
status = 'updated'
|
18
|
+
else
|
19
|
+
status = 'created'
|
20
|
+
end
|
21
|
+
File.open(filename, "w") do |file|
|
22
|
+
file.write(TranslationsSync.to_yaml(translations.slice lang))
|
23
|
+
end
|
24
|
+
puts status
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
6
28
|
desc "Synchronizes the existing translations" + PARAMS + ' NAME=file_name_prefix'
|
7
29
|
task :sync => :environment do
|
8
|
-
|
9
|
-
ts = TranslationsSync.new ENV['LIST'], ENV['EXCLUDE'], source
|
30
|
+
ts = get_ts
|
10
31
|
name = ENV['NAME'] || ENV['IN'] || 'missing'
|
11
32
|
ts.missing.keys.sort.each do |lang|
|
12
33
|
filename = File.join Rails.root, 'config', 'locales', "#{name}_#{lang}.yml"
|
@@ -29,7 +50,7 @@ namespace :translations do
|
|
29
50
|
|
30
51
|
desc "Detects the translations existing only in one locale" + PARAMS
|
31
52
|
task :singles => :environment do
|
32
|
-
ts =
|
53
|
+
ts = get_ts false
|
33
54
|
filename = File.join Rails.root, 'config', 'locales', "singles.yml"
|
34
55
|
if ts.singles.size > 0
|
35
56
|
File.open(filename, "w") do |file|
|
@@ -43,24 +64,21 @@ namespace :translations do
|
|
43
64
|
|
44
65
|
desc "Moves the key in the translations" + PARAMS + " KEY=key.to.move TO=where.to.move IN=filespec"
|
45
66
|
task :move => :environment do
|
46
|
-
source = ENV['SOURCE'] || ENV['IN']
|
47
|
-
name = ENV['NAME'] || ENV['IN'] || 'moved'
|
48
67
|
key = ENV['KEY'] or raise "Parameter KEY must be given"
|
49
|
-
ts =
|
68
|
+
ts = get_ts
|
50
69
|
if ts.move key, ENV['TO']
|
51
|
-
ts.moved
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
end
|
70
|
+
save_files ts.moved, 'moved'
|
71
|
+
else
|
72
|
+
puts "The key \"#{key}\" was not found"
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
desc "Removes the key from the translations" + PARAMS + " KEY=key.to.move IN=filespec"
|
77
|
+
task :remove => :environment do
|
78
|
+
key = ENV['KEY'] or raise "Parameter KEY must be given"
|
79
|
+
ts = get_ts
|
80
|
+
if ts.remove key
|
81
|
+
save_files ts.moved, 'removed'
|
64
82
|
else
|
65
83
|
puts "The key \"#{key}\" was not found"
|
66
84
|
end
|
data/lib/translations_sync.rb
CHANGED
@@ -178,6 +178,20 @@ class TranslationsSync
|
|
178
178
|
@moved
|
179
179
|
end
|
180
180
|
|
181
|
+
def remove(key)
|
182
|
+
key = key.split('.').map(&:to_sym)
|
183
|
+
key_length = key.length
|
184
|
+
result = false
|
185
|
+
puts @flat.keys.select{|array| array[0] == :clients}.map(&:second).inspect
|
186
|
+
@flat.reject! do |array, val|
|
187
|
+
r = array[0, key_length] == key
|
188
|
+
result ||= r
|
189
|
+
r
|
190
|
+
end
|
191
|
+
@moved = nil
|
192
|
+
result
|
193
|
+
end
|
194
|
+
|
181
195
|
private
|
182
196
|
|
183
197
|
def flatten_keys(lang, src, dest = {}, prefix = [])
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: translations_sync
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 4
|
10
|
+
version: 0.2.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Dmitri Koulikoff
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-03-
|
18
|
+
date: 2011-03-25 00:00:00 +03:00
|
19
19
|
default_executable: translations_sync
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|