translation_manager 0.1.1

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.
data/README.rdoc ADDED
@@ -0,0 +1,11 @@
1
+ = Translation Manager for Rails 2
2
+
3
+ Translation magener helps you keep updated yml files. Just upgrade to a locale and automatically changes to the local rest will be added
4
+
5
+ == Instalation
6
+
7
+ gem install translation_manager
8
+
9
+ == Usage
10
+
11
+ rake rake update_translations
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'echoe'
4
+
5
+ Echoe.new('translation_manager', '0.1.0') do |p|
6
+ p.description = "helps you manage the locale yml files"
7
+ p.url = "http://github.com/XXXXXXXXXXXXXXXXXXXXXXX"
8
+ p.author = "Jorge Garcia"
9
+ p.email = "xurdedix@gmail.com"
10
+ p.ignore_pattern = ["tmp/*", "script/*"]
11
+ p.development_dependencies = []
12
+ end
13
+
14
+ Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
@@ -0,0 +1,31 @@
1
+ require 'translation_manager'
2
+
3
+ desc 'Actualiza'
4
+ task :update_translations do
5
+ locales={}
6
+ master_locale= TranslationManager::Config::PREFERENCES[:master_locale]
7
+ TranslationManager::Config::PREFERENCES[:locales].each do |locale|
8
+ locales.merge! locale => TranslationManager::OrderedHash.load_from_yml_file(RAILS_ROOT+ "/config/locales/#{locale}.yml")
9
+ end
10
+ locales.each do |locale, yml|
11
+ yml.save_to_yml_file(RAILS_ROOT+ "/config/locales/#{locale}.yml.old")
12
+ end
13
+ locales.select{|l| l!= master_locale}.each do |locale, yml|
14
+ yml = yml.complete_with(locales[master_locale])
15
+ yml.save_to_yml_file(RAILS_ROOT+ "/config/locales/#{locale}.yml")
16
+ end
17
+ # es = TranslationManager::OrderedHash.load_from_yml_file(RAILS_ROOT+ "/config/locales/es.yml")
18
+ # en = TranslationManager::OrderedHash.load_from_yml_file(RAILS_ROOT+ "/config/locales/en.yml")
19
+ # it = TranslationManager::OrderedHash.load_from_yml_file(RAILS_ROOT+ "/config/locales/it.yml")
20
+ #
21
+ # en_copy = en.complete_with(es)
22
+ # en_copy.save_to_yml_file(RAILS_ROOT+ "/config/locales/copia_en.yml")
23
+ # it_copy = it.complete_with(es)
24
+ # it_copy.save_to_yml_file(RAILS_ROOT+ "/config/locales/copia_it.yml")
25
+
26
+ end
27
+
28
+ desc 'Di Hola'
29
+ task :hola do
30
+ puts "Hola", "\n"*5,"Hola"
31
+ end
@@ -0,0 +1,177 @@
1
+
2
+
3
+ module TranslationManager
4
+ # def self.included(base)
5
+ # base.extend ClassMethods
6
+ # end
7
+ class Config
8
+ PREFERENCES={
9
+ :locales => [:es,:en,:it],
10
+ :master_locale => :es,
11
+ :translate_alert => " <<TRADUCIR>>"
12
+ }
13
+ end
14
+ class OrderedHash < ActiveSupport::OrderedHash
15
+ def self.load_from_yml_file(file)
16
+ orderdes_hash= self.new
17
+ lines=[]
18
+ File.open(file, 'r') do |f1|
19
+ while line = f1.gets
20
+ lines << line
21
+ end
22
+ end
23
+ # puts lines
24
+ orderdes_hash.parse_yml_array(lines)[:hash]
25
+ end
26
+ def save_to_yml_file(file)
27
+ File.open(file, 'w') do |f1|
28
+ f1.write self.unparse_yml_array(2)
29
+ end
30
+ end
31
+
32
+ # crea una copia del OrderedHash master respetando los Valores de las Keys que existan en el OrderedHash
33
+ def complete_with(master, params={})
34
+ params[:locales] ||= Config::PREFERENCES[:locales]
35
+ params[:master_locale] ||= Config::PREFERENCES[:master_locale]
36
+ params[:translate_alert] ||= Config::PREFERENCES[:translate_alert]
37
+ params[:internal_call] ||=false
38
+
39
+ copy = OrderedHash.new
40
+ master.each do |key,value|
41
+ if self.has_key? key or ( !params[:internal_call] and params[:master_locale]==key )
42
+ if value.class == OrderedHash
43
+ if self.has_key? key
44
+ copy.merge! key=>self[key].complete_with(value, :internal_call=>true)
45
+ else
46
+ self_key= self.keys.select{|k| params[:locales].include? k}[0]
47
+ copy.merge! self_key => self[self_key].complete_with(value, :internal_call=>true)
48
+ end
49
+ else
50
+ copy.merge!key=>self[key]
51
+ end
52
+ else
53
+ if value.class == OrderedHash
54
+ copy.merge! key=>OrderedHash.new.complete_with(value, :internal_call=>true)
55
+ else
56
+ copy.merge! key=>"#{value}#{params[:translate_alert]}"
57
+ end
58
+ end
59
+
60
+
61
+ # if key.class==Symbol
62
+ # if value.class == OrderedHash
63
+ #
64
+ # unless value==other[key]
65
+ # value.complete_with(other[key])
66
+ # end
67
+ # else
68
+ #
69
+ # end
70
+ # end
71
+ end
72
+ copy
73
+ end
74
+
75
+ def unparse_yml_array(spaces_per_tab=1, tabs=nil)
76
+ array ||= []
77
+ position ||=0
78
+ tabs ||= 0
79
+ self.each do |key,value|
80
+ if key.class==Symbol
81
+ # puts value.class
82
+ # puts key
83
+ if value.class == OrderedHash
84
+ array << "#{' '* tabs * spaces_per_tab}#{key}:\n"
85
+ array += value.unparse_yml_array(spaces_per_tab,tabs+1)
86
+ else
87
+ array << %(#{' '* tabs * spaces_per_tab}#{key}: "#{value}"\n)
88
+ end
89
+ elsif key=='blank_line'
90
+ array << "\n"
91
+ # puts 'blank_line'
92
+ elsif key.match /^comemnt_line_(\d*)\z/
93
+ array << value
94
+ # puts "coment #{$1} #{value}"
95
+ else
96
+
97
+ end
98
+
99
+ end
100
+ array
101
+ end
102
+ def parse_yml_array(array,position=nil,tabs=nil)
103
+ position ||=-1
104
+ tabs ||= 0
105
+ # puts "position=#{position} tabs=#{tabs}"
106
+ # puts array.class, array[1..20]
107
+ # puts array[11],array[11][0],array[11][0].to_int
108
+ c= position
109
+ while c<array.size do
110
+ c+=1
111
+ # puts array[c]
112
+ if array[c].blank?
113
+ self.merge! 'blank_line'=>""
114
+ # puts "linea en blanco"
115
+ next
116
+ end
117
+ if array[c].match /#.*/
118
+ self.merge! "comemnt_line_#{c}"=>array[c]
119
+ # puts "linea #{c} coment"
120
+ next
121
+ end
122
+ if array[c].match /^(\t|\s*)(\w+):\s*"(.*)"\s*\z/
123
+ # puts "*",array[c],$1,$2,$3
124
+ if $1 and $1.size< tabs
125
+ return :line=>c,:hash=>self
126
+ else
127
+ self.merge! $2.to_sym=>$3
128
+ # puts "linea #{c} #{$2.to_sym} =>#{$3}"
129
+ # puts "key"
130
+ next
131
+ end
132
+ end
133
+ if array[c].match /^(\t|\s*)(\w+):\s*\z/
134
+ if $1 and $1.size< tabs
135
+ # ## self.merge! "B#{$1.size} c=#{c}"=>tabs
136
+ return :line=>c,:hash=>self
137
+ else
138
+ # puts "linea #{c} #{$2.to_sym} entra"
139
+ answer = OrderedHash.new.parse_yml_array(array,c,$1.size+1)
140
+ self.merge! $2.to_sym =>answer[:hash]
141
+ c = answer[:line]-1 if answer[:line]
142
+ # puts "linea #{c} #{$2.to_sym} sale #{hash.size} #{Array(hash).flatten.size}"
143
+ next
144
+ end
145
+ end
146
+
147
+ # puts "no mactch"
148
+ end
149
+ return :line=>c,:hash=>self
150
+ end
151
+
152
+ end
153
+ # hash = TranslationManager::OrderedHash.load_from_yml_file(RAILS_ROOT+ "/config/locales/es_test.yml")
154
+ # hash.save_to_yml_file(RAILS_ROOT+ "/config/locales/copia_es_test.yml")
155
+
156
+ end
157
+
158
+
159
+
160
+ #class ActiveRecord::Base
161
+ # include TranslationManager
162
+ #end
163
+
164
+
165
+
166
+
167
+
168
+
169
+
170
+
171
+
172
+
173
+
174
+
175
+
176
+
177
+
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: translation_manager
3
+ version: !ruby/object:Gem::Version
4
+ hash: 25
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 1
10
+ version: 0.1.1
11
+ platform: ruby
12
+ authors:
13
+ - Jorge Garcia
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-04-08 00:00:00 Z
19
+ dependencies: []
20
+
21
+ description: Translation magener helps you keep updated yml files. Just upgrade to a locale and automatically changes to the local rest will be added
22
+ email:
23
+ - xurdedix@gmail.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - README.rdoc
32
+ - Rakefile
33
+ - lib/tasks/translation_task.rake
34
+ - lib/translation_manager.rb
35
+ homepage: https://github.com/xurdedix/Translation-Manager-for-rails-2
36
+ licenses: []
37
+
38
+ post_install_message:
39
+ rdoc_options: []
40
+
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ none: false
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ hash: 3
49
+ segments:
50
+ - 0
51
+ version: "0"
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ hash: 3
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ requirements: []
62
+
63
+ rubyforge_project:
64
+ rubygems_version: 1.8.21
65
+ signing_key:
66
+ specification_version: 3
67
+ summary: helps you keep updated yml files
68
+ test_files: []
69
+