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 CHANGED
@@ -1,3 +1,6 @@
1
+ 2011-03-25 v.0.2.4
2
+ * Action translatons:remove added
3
+
1
4
  2011-03-22 v. 0.2.3
2
5
  * translatons:move does not keep the last key of KEY parameter. This gives the ability to rename the last key.
3
6
 
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
@@ -6,7 +6,7 @@ require 'rubygems/specification'
6
6
  require 'date'
7
7
 
8
8
  GEM = "translations_sync"
9
- GEM_VERSION = "0.2.3"
9
+ GEM_VERSION = "0.2.4"
10
10
  AUTHOR = "Dmitri Koulikoff"
11
11
  EMAIL = "koulikoff@gmail.com"
12
12
  HOMEPAGE = "http://github.com/dima4p/translations_sync/"
@@ -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
- source = ENV['SOURCE'] || ENV['IN']
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 = TranslationsSync.new ENV['LIST'], ENV['EXCLUDE']
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 = TranslationsSync.new ENV['LIST'], ENV['EXCLUDE'], source
68
+ ts = get_ts
50
69
  if ts.move key, ENV['TO']
51
- ts.moved.keys.sort.each do |lang|
52
- filename = File.join Rails.root, 'config', 'locales', "#{name}_#{lang}.yml"
53
- print filename + ' ... '
54
- if File.exist? filename
55
- status = 'updated'
56
- else
57
- status = 'created'
58
- end
59
- File.open(filename, "w") do |file|
60
- file.write(TranslationsSync.to_yaml(ts.moved.slice lang))
61
- end
62
- puts status
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
@@ -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: 17
4
+ hash: 31
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 3
10
- version: 0.2.3
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-22 00:00:00 +03:00
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