[Rails I18n] Globalize: Collection Messages
Eduard
eduard.martini at codemart.ro
Wed Aug 23 11:02:13 EDT 2006
THere is no such function.
Anyway I have writen one to sarch in all views and controllers and also
translate the errr messages.
Look here:
#this one will parse all views and contrller from disk to search
strings that need to be translated. It also will add to the DB the error
message as needing translation
def get_translatable_strings
@strs = []
Dir.glob("#{RAILS_ROOT}/app/views/**/*.rhtml").collect do |f|
@strs << File.read(f).scan(/[\"\']([A-Za-z0-9% ]*)[\"\']\.t/)
end.uniq.flatten.uniq
@new_strs=Array.new
@strs=@strs.uniq.sort
0.upto @strs.size-1 do |i|
@strs[i].each do |str|
@new_strs << str
end
end
@strs = []
Dir.glob("#{RAILS_ROOT}/app/controllers/**/*.rb").collect do |f|
@strs << File.read(f).scan(/[\"\']([A-Za-z0-9% ]*)[\"\']\.t/)
end.uniq.flatten.uniq
@strs=@strs.uniq.sort
0.upto @strs.size-1 do |i|
@strs[i].each do |str|
@new_strs << str
end
end
@new_strs=@new_strs.uniq.sort
Locale::LOCALES.values.each do |loc|
Locale.set "#{loc}"
@new_strs.each do |str|
str.to_s.translate
end
ActiveRecord::Errors.default_error_messages.each_value do
|error_msg|
error_msg.translate
end
end
end
--
Posted via http://www.ruby-forum.com/.
More information about the Railsi18n-discussion
mailing list