MailingList


A suggestion to multiple variabels in a string

View: New views
3 Messages — Rating Filter:   Alert me  

A suggestion to multiple variabels in a string

by Kristian Hellquist-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello users

I have an idea about multiple variables in a string that will be translated.

It uses context-variables so it's both easy for the translator to
understand what he is translating and it gives you the opportunity to
have more than one string-replacement in each strings.

"[username]'s blog posts tagged as [tag]").insert_copy(
@attachable.screen_name, @tag.value)

I have read thru the tutorials but haven't found anything similar. I
am also a new user of globalize rails so I might lacking some basic
knowledge about this.  Please come with some feedback!


More info in http://trac.globalize-rails.org/trac/globalize/ticket/195

Cheers,
Kristian

Re: A suggestion to multiple variabels in a string

by Luca Guidi :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I haven't understood very well, try with:

"[%s]'s blog posts tagged as [%s]".t % [@attachable.screen_name, @tag.value]

Luca
--
blog: www.lucaguidi.com
Pro-Netics: www.pro-netics.com
Sourcesense - making sense of Open Source: www.sourcesense.com

Re: A suggestion to multiple variabels in a string

by Kristian Hellquist-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Ah sorry

Variables with brackets in a string is variables that is gonna be replaced.

"A [animal] ate a banana".insert_copy("monkey") => "A monkey ate a banana"

By using the brackets syntax you have the chance to change order of
how words will be translated.

Locale.set_translation("[user] fed the [animal]", "[animal] foo bar [user]")

I do think that the bracket syntax also increases readability.

Examples above might not  be the best, but I hope you get the idea. I
really would like to get some feedback of it. I currently using it in
my code and seems like a good idea ... but I might ran in to problems
later that I dont see yet

Thanks again,
Kristian



2008/6/26 Luca Guidi <guidi.luca@...>:

> I haven't understood very well, try with:
>
> "[%s]'s blog posts tagged as [%s]".t % [@attachable.screen_name, @tag.value]
>
> Luca
> --
> blog: www.lucaguidi.com
> Pro-Netics: www.pro-netics.com
> Sourcesense - making sense of Open Source: www.sourcesense.com
>