# Globalize: Collection Messages

**URL:** <https://www.ruby-forum.com/t/globalize-collection-messages/64835>\
**Category:** Rails I18n\
**Created:** [August 15, 2006, 2:19pm UTC](https://www.ruby-forum.com/t/globalize-collection-messages/64835 "2006-08-15T14:19:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tbaustert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ecae2f/32.png) [@tbaustert](https://www.ruby-forum.com/u/tbaustert)\
**Post date:** [August 15, 2006, 2:19pm UTC](https://www.ruby-forum.com/t/globalize-collection-messages/64835/1 "2006-08-15T14:19:43Z")

</div>

Hi,

as far as I understand is Globalize adding every not translated  
message to the database  
during _runtime_ of the application? (if method translate() is called)

That means one need run the application and visit every page in any  
constellation  
to get every message to the database to then afterwards translating  
them. And  
this for each language to be supported except the default one?

Is there any tool or way right now to collect every message without  
running the  
application? Like with Gettext?

Or do I misunderstand the function of Globalize in this case?

Thanx in advance.  
Thomas

* * *

Thomas B. - Freiberuflicher Softwarecoach  
fon: +49(40)411 622 35 mobil: +49(173)23 911 43  
fax: +49(40)411 622 36  
thomas.baustert(at)[b-simple.de](http://b-simple.de)

---

<div class="post-metadata">

**Author:** ![tbaustert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ecae2f/32.png) [@tbaustert](https://www.ruby-forum.com/u/tbaustert)\
**Post date:** [August 23, 2006, 5:02pm UTC](https://www.ruby-forum.com/t/globalize-collection-messages/64835/2 "2006-08-23T17:02:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![tbaustert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ecae2f/32.png) [@tbaustert](https://www.ruby-forum.com/u/tbaustert)\
**Post date:** [July 4, 2007, 5:32pm UTC](https://www.ruby-forum.com/t/globalize-collection-messages/64835/3 "2007-07-04T17:32:35Z")

</div>

Thank you for your contribution Eduard.  
I am saving myself pretty some work using it.

Still, I have (tried to have) improve your code a little, mainly the  
regexp:  
def harvest  
@strs = []  
allowed = ’ \w0-9%:;@&#\<\>/\?!+)(-=\*’  
regexp =  
Regexp.new(’"["].t|’[’].t’)  
Dir.glob("#{RAILS\_ROOT}/app/views/**/\*.rhtml").collect do |f|  
 @strs \<\< File.read(f).scan(regexp)  
end  
@new\_strs=Array.new  
@strs=@strs.flatten.uniq  
0.upto @strs.size-1 do |i|  
if @strs[i] then  
 @strs[i].each do |str|  
 @new\_strs \<\< str  
end  
end  
end  
 @strs = []  
Dir.glob("#{RAILS\_ROOT}/app/controllers/**/\*.rb").collect do |f|  
@strs \<\< File.read(f).scan(regexp)  
end  
@strs=@strs.flatten.uniq  
0.upto @strs.size-1 do |i|  
if @strs[i] then  
@strs[i].each do |str|  
@new\_strs \<\< str  
end  
end  
end  
@new\_strs=@new\_strs.uniq.sort  
LOCALES.each do |key,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

---

<div class="post-metadata">

**Author:** ![tbaustert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ecae2f/32.png) [@tbaustert](https://www.ruby-forum.com/u/tbaustert)\
**Post date:** [November 22, 2007, 12:34pm UTC](https://www.ruby-forum.com/t/globalize-collection-messages/64835/4 "2007-11-22T12:34:49Z")

</div>

I’m getting the following error , I have added the above method in  
method in application helper file and called from one of the view but  
got the follwoing error

uninitialized constant ApplicationHelper::LOCALES

Could u give me more information about it (i.e how to use it)?
