Developer forum

Forum » Templates » Products in different colours and with translated names...

Products in different colours and with translated names...

Lise T. Pedersen
Reply

I have a number of products, created with items. Each product is available in some different colours - the colours is created as a checkbox list in the item. But now the problem starts, because the template should be used for three different languages, and I was not very experienced in items when I started, and had not seen this problem from the start. And when I loop the selected colours in the template, I can only show the colours' label, not translate it.

Any suggestions for a way (another kind of item perhaps?) which can solve this problem? 

/Lise


Replies

 
Nicolai Høeg Pedersen
Reply

Hi Lise

You should be able to loop both labels and values:

http://templates.dynamicweb.com/TemplateTags/Dynamicweb-template-tags/Module-tags/Item-publisher/Details/Loops/ItemPublisherItem-Field-Options.aspx

If you use a Razor template, you can run the labels or values through @Translate() function and use the translation module for that.

Maybe post your template here so I can have a look.

NP

 
Lise T. Pedersen
Reply

Hi Nicolai

Here is the template - at first I only looped the selected colours, and had of course both labels and values - but not the label in tree languages ;-)

Now while I was waiting for answer, I have coded a "test" in the bottom of the template, where the color is outputted, if it is selected. But I have about 20 possible colours and has to output each this way, so your solution might be a lot better.

I can also send you a link to the actual solution.

/Lise

 
Nicolai Høeg Pedersen
Reply

Ok, got it.

What you need is a conversion to Razor - and call the Translate on the label - the only option if you do not want to do conditionals...

In Razor you can do like this: @Translate(GetValue("Item.Farvemuligheder.Option.Value")) and have the translate system handle it.

BR Nicolai

 
Lise T. Pedersen
Reply

I have now converted the template to razor - which I really haven't worked very much with. And the editor tells me to handle some of the translation manually - and I really don't now where to start. Looked in the "how to work with Razor" but as I am not familiar to the syntax, I don't know what to change first? Any hints?

(I guess it is the if-sentences, that is not converted - but an example of how to change them - or a good way to see where the errors are located in the template, would be nice...)

Thanks in advance.

/Lise

 
Bogdan Ciocsan
Reply

Hi Lise.

You can take a look at this following link: https://github.com/dynamicweb/razor/wiki/From-Dynamicweb-HTML-to-Razor and it should help you understand how you can change your old html tags to Razor.

Best regards,

Bogdan

 
Lise T. Pedersen
Reply

Now I've come a little step further - my template is converted to razor, and it worked until I started the translation-part :-/

I have this loop: 

                      <ul>
                        @foreach (var item in GetLoop("Item.Farvemuligheder.Options")) {
                         
                          if(item.GetBoolean("Item.Farvemuligheder.Option.IsSelected")) {
                        <li style="text-align: left; width: 99px; height: 61px;"><img src="/Files/Billeder/Primolister/Farver/@item.GetValue("Item.Farvemuligheder.Option.Value")" /><br /> @Translate(GetValue("Item.Farvemuligheder.Option.Value"))</li>
                          }

                        }
                      </ul>

And get this errors (line 51 is the yellow part...)
 

Line 51: The best overloaded method match for 'Dynamicweb.Rendering.RazorTemplateBase.Translate(string)' has some invalid arguments
Line 51: Argument 1: cannot convert from 'object' to 'string'

And from here I'm not quite sure where to go...

 
Thomas Schroll
Reply

Hi Lise

Perhaps you need to use GetString instead of GetValue.

Regards Thomas

 

 
Lise T. Pedersen
Reply

@item.GetString solved it - thank you!

 

You must be logged in to post in the forum