Internationalisation: Parameters in dictionary Options
Adz
Posted: Tuesday, August 05, 2008 12:43:41 PM

Rank: Aficionado

Joined: 6/5/2008
Posts: 147
Location: United Kingdom
Is there any way currently to use the dictionary with parameters?

I think it's fairly common practice to have something like this (contrived example I know):

"Please call {0} to find out more about {1}!"

- Where {0} would be replaced by a phone number and {1} could be a subject (Gardening)?

In French, for example, the sentence could be structured quite differently;

- "To find out more about {1}, call {0} please"



Can this type of translation be handled in Umbraco, or do you have to resort to Macros to do this?



Thanks


Adam

Adam Perry (blog, twitter), developing Umbraco based websites and applications for ConnectDigital.
tim
Posted: Tuesday, August 05, 2008 12:48:36 PM

Rank: Addict

Joined: 2/19/2007
Posts: 766
Location: Belgium
you'll have to write custom code to do this ...

Umbraco tips and tricks: http://www.nibble.be - umbraco mvp 08/09 - certified level 1 & 2 professional
hartvig
Posted: Tuesday, August 05, 2008 1:34:27 PM

Rank: Addict

Joined: 3/17/2008
Posts: 957
Location: Nyborg, Denmark
Great idea though - how could this be implemented?
<Umbraco:Item field="#myDictItem" dictionaryParameters="Gardening|phonenumber"/>
<xsl:value-of select="umbraco.library:GetDictionary('myDictItem', 'Gardening|phonenumber')"/>

Jeeeez, did I really start this :-)
daniel_l
Posted: Tuesday, August 05, 2008 1:49:45 PM
Rank: Aficionado

Joined: 6/25/2007
Posts: 139
Location: Malmo, Sweden
hartvig wrote:
Great idea though - how could this be implemented?
<Umbraco:Item field="#myDictItem" dictionaryParameters="Gardening|phonenumber"/>
<xsl:value-of select="umbraco.library:GetDictionary('myDictItem', 'Gardening|phonenumber')"/>


Yeah, as long as the parameters can be dictionary items.

Maybe allow for dictionary items within dictionary items, like this:

"Please call #phonenumber to find out more about #gardening!"



Is it me or umbraco? Umbraco Certified Professional Level 2.
drobar
Posted: Tuesday, August 05, 2008 2:29:34 PM

Rank: Umbracoholic

Joined: 9/8/2006
Posts: 1,758
Location: KY, USA
Maybe I'm missing something here, but it isn't simply that the phone number and subject's positions are reversed for some languages but that the text is as well.

Wouldn't the two dictionary items need to be the complete sentences, not just the phone and gardening text?
#GardeningPhoneMessage-EN = "Please call 12345 to find out more about Gardening!"
#GardeningPhoneMessage-FR = "To find out more about Gardening, call 01234 please"

At least at the moment with v3 that's how it would need to be handled.

But perhaps allowing nested dictionary keys would be helpful. Then a phone number could be changed in one location in the dictionary...
#GardeningPhoneMessage-EN = "Please call #GardeningPhone to find out more about #Gardening!"
#GardeningPhoneMessage-FR = "To find out more about #Gardening, call #GardeningPhone please"

cheers,
doug.

MVP 2007-2009 - Official Umbraco Trainer for North America - Percipient Studios
Adz
Posted: Tuesday, August 05, 2008 2:34:38 PM

Rank: Aficionado

Joined: 6/5/2008
Posts: 147
Location: United Kingdom
hartvig wrote:
Great idea though - how could this be implemented?
<Umbraco:Item field="#myDictItem" dictionaryParameters="Gardening|phonenumber"/>
<xsl:value-of select="umbraco.library:GetDictionary('myDictItem', 'Gardening|phonenumber')"/>



Thats pretty much how it would work, or alternatively something like

Code:

<Umbraco:Item field="#myDictItem" arg1="Gardening" arg2="phonenumber"/>

<Umbraco:Item field="#myDictItem" arg1="#Gardening" arg2="#phonenumber"/>


(This is how it's done in Java tag libraries. Disadvantage being, there is a hardcoded limit to the number of arguments)

Also bearing in mind that "#field" will grab a document property, or a translation - its important that you can insert a document property into the string (thats probably where the phone number would be!).

Lastly the library functions would then be something like this:


Code:

umbraco.library:GetDictionary(string key, string arg1)
{
    GetDictionary(key, new string[] {arg1});
}

umbraco.library:GetDictionary(string key, string arg1, string arg2)
{
    GetDictionary(key, new string[] {arg1, arg2});
}

umbraco.library:GetDictionary(string key, string arg1, string arg2, string arg3)
{
    GetDictionary(key, new string[] {arg1, arg2, arg3});
}

umbraco.library:GetDictionary(string key, string arg1, string arg2, string arg3, string arg4)
{
    GetDictionary(key, new string[] {arg1, arg2, arg3, arg4});
}

umbraco.library:GetDictionary(string key, string arg1, string arg2, string arg3, string arg4, string arg5)
{
    GetDictionary(key, new string[] {arg1, arg2, arg3, arg4, arg5});
}

umbraco.library:GetDictionary(string key, string[] args) {
    // Do your thang
}


Adam Perry (blog, twitter), developing Umbraco based websites and applications for ConnectDigital.
daniel_l
Posted: Tuesday, August 05, 2008 2:49:53 PM
Rank: Aficionado

Joined: 6/25/2007
Posts: 139
Location: Malmo, Sweden
drobar wrote:
Wouldn't the two dictionary items need to be the complete sentences, not just the phone and gardening text?


Ahh you are just looking for an easy way out... ;)

Seriously; if the phrase in the dictionary contains a phone number, which may be used in several contexts throughout the application. Also the phone number may change with language.

In this case I think nested dictionary items would be great.

And dictionary parameters could be useful if you would want to inject words dynamically in your dictionary phrase.

But I am not sure if the need for this is real... But at first glance it seemed like an excellent idea to me as well. There are certainly much more important things on the agenda for upcoming umbraco releases.

Is it me or umbraco? Umbraco Certified Professional Level 2.
tim
Posted: Tuesday, August 05, 2008 3:02:06 PM

Rank: Addict

Joined: 2/19/2007
Posts: 766
Location: Belgium
daniel_l wrote:

But I am not sure if the need for this is real... But at first glance it seemed like an excellent idea to me as well. There are certainly much more important things on the agenda for upcoming umbraco releases.


I would use it !

Umbraco tips and tricks: http://www.nibble.be - umbraco mvp 08/09 - certified level 1 & 2 professional
Adz
Posted: Tuesday, August 05, 2008 4:42:51 PM

Rank: Aficionado

Joined: 6/5/2008
Posts: 147
Location: United Kingdom
Its fairly important functionality for multi-lingual sites.
Not so much defining the phone number in the dictionary - although that could be useful - but passing parameters in generally.

I guess right now it would have to be done with a custom control / macro?

Adam Perry (blog, twitter), developing Umbraco based websites and applications for ConnectDigital.
Users browsing this topic
Guest


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.