[3.8.1] i18n String Substitutions

Hello

Following the docs it isn’t looking hard to replace a placeholder from a resource string, but i was not able to do it.

// my resource:
blog.category.entries_in=News in der Kategorie {Category}

Code:

Simple:
#getResource(resource=“blog.category.entries_in”, values=“pizza”)#

Or via Array:

#getResource(resource=“blog.category.entries_in”, values=[“pizza”])#

Or via Struct:
#getResource(resource=“blog.category.entries_in”, values={Category=“pizza”})#

None of these variants does replace {Category} with pizza. The string will be returned as it is in the resource file.

Docs: http://wiki.coldbox.org/wiki/i18n.cfm

What did i wrong? Can’ see a reason so far.

Many thanks

Martin

I may be wrong, but I think you need to use numeric index placeholders in i18n resources, this is what I have always done:

blog.category.entries_in=News in der Kategorie {1}

The logic for this is in the formatRBString() method in the ResourceBundle plugin. Read through that to familiarize yourself and feel free to put in some dumps to debug it to see exactly what it’s doing.

It looks like if you pass a string, it will replace {1}
If you pass an array, the respective elements will replace {1}, {2}, {3}…
And if you pass a struct, the LOWERCASE struct key will be replaced. {keyname1}, {keyname2}, {keyname3}…

Thanks!

~Brad

ColdBox Platform Evangelist
Ortus Solutions, Corp

E-mail: brad@coldbox.org
ColdBox Platform: http://www.coldbox.org
Blog: http://www.codersrevolution.com

Many thanks, i got it :wink:

I didn’t see, that the e.g. {1} was for real, i pointed it out as a normal placeholder.

It works now.

Cheers