# Globalize and more than one dynamic value

**URL:** <https://www.ruby-forum.com/t/globalize-and-more-than-one-dynamic-value/101732>\
**Category:** Rails I18n\
**Created:** [August 7, 2006, 6:12pm UTC](https://www.ruby-forum.com/t/globalize-and-more-than-one-dynamic-value/101732 "2006-08-07T18:12:49Z")\
**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 7, 2006, 6:12pm UTC](https://www.ruby-forum.com/t/globalize-and-more-than-one-dynamic-value/101732/1 "2006-08-07T18:12:49Z")

</div>

Hi all,

consider the case you have more than one dynamic value for a text.  
You can write:

\<%= There are %d horses / 3 %\>

but, what if:

\<%= There are %d horses on the %s / [3, “moon”] %\>

The following idea won’t work:

\<%= (There are %d horses on the %s / 3) / “moon” %\>

since Globalize would insert the two strings

“There are %d horses on the %s”  
“There are 3 horses on the %s”

in the database and one more for each new value :).

My idea is to patch Globalize to accept an array of value.

Does anyone had the same problem?  
Just wanna know what you think.

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, 11:23am UTC](https://www.ruby-forum.com/t/globalize-and-more-than-one-dynamic-value/101732/2 "2006-08-23T11:23:18Z")

</div>

Hi, I have also same problem.  
\<%="%s has %d apples and %s has more".t / “Goran” /5 /“Mihai”%\>  
generates 3 strings into the DB and, if you replace Goran with Sven,  
another 2 strings are inserted into DB.  
And also if you add a translation for %s has %d apples and %s has more  
for a specific language, then load the in to that language, the string  
is added again.

Did you solve the problem?

---

<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, 11:59am UTC](https://www.ruby-forum.com/t/globalize-and-more-than-one-dynamic-value/101732/3 "2006-08-23T11:59:04Z")

</div>

Hi Eduard,

no, sorry. So far I’m not using globalize and didn’t patched anything.

I guess, you have to redefined the method fetch() inside …/lib/  
globalize/localization/db\_view\_translator.rb

def fetch(key, language, default = nil, arg = nil)  
…  
if num  
return result.sub(‘%d’, num.to\_s)  
else  
return arg.nil? ? result : result.sub(‘%s’, arg.to\_s)  
end

end

Maybe that’s all.

Thomas

Am 23.08.2006 um 11:23 schrieb Eduard:

> –  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> * * *
> 
> Railsi18n-discussion mailing list  
> removed\_email\_address@domain.invalid  
> [http://rubyforge.org/mailman/listinfo/railsi18n-discussion](http://rubyforge.org/mailman/listinfo/railsi18n-discussion)

* * *

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 25, 2006, 2:24pm UTC](https://www.ruby-forum.com/t/globalize-and-more-than-one-dynamic-value/101732/4 "2006-08-25T14:24:15Z")

</div>

I solved that problem by adding a new method t\_p to the String class.  
So, we have “%s is tall but %s is %d inchs taller”.t\_p([“Jim”, “Brian”,  
2])  
Just tell me if you still need it

Eduard
