Developer forum

Forum » Templates » Razor:@Translate in 8.4.1.15

Razor:@Translate in 8.4.1.15

Sten Hougaard
Reply

Hi,

I have issues with @Translate tag when used inside a Razor block of code.

Consider this:

In translations.xml in root of "Templates" i have defined a key:
mykey = 1
@{
    // Using old fashion translate
    int anInt = <!--@Translate(mykey, "mykeyNotTranslated", global)-->;
    // Using real razor version
    // Where an overloaded method taking three parameter does not exist (!)
    int aSecondInt = Translate("mykey", "myKeyNotTranslated") 
}
        
It seems that the translation only is done on 2nd request!

Please try your self and explain to me this behaviour.

 

 


Replies

 
Mikkel Ricky
Reply

We have an issue with global translations with the real Razor Translate function, but we're working on a fix.

for now you have to use <!--@Translate(…, …, global)--> in Razor templates to use global translations. These translations are inserted before the Razor Engine processes the template.

Best regards,
Mikkel

 
Sten Hougaard
Reply

But Mikkel, the Razor `Translate("a", "b")` has been activated in 8.4.1.15 which means that you may or may not run into issues even when using `@Translate` - Razor/Dynamicweb can mix up which version to use as Razor uses `@` to say: "Here comes some Razor code".

We have spend 2 hours trying to figure out what went wrong after a pre 8.4.1.15 solution running an otherwise working template was upgraded. That is a serious issue which could break any running Razor template running 8.4.1.15. Please try to learn from that mistake.


Med venlig hilsen/Best regards,

Sten Hougaard
Webudvikler

E: sho@1stweb.dk
M: 29850818
A: København/Aarhus . W: www.1stweb.dk
@: netsi1964

 
Mikkel Ricky
Reply
This post has been marked as an answer

In Dynamicweb 8.4.1.16 we have added an optional third parameter to Translate in Razor. To use a global translation, this third parameter must be either true (boolean) or "global" (string), i.e.

@Translate("Show cart", "Show cart", true)
@Translate("Show cart", "Show cart", "global")

Sorry about missing that in the previous release.

We strongly recommend that you do not use global translations, and in Dynamicweb 8.5 we have a cool new translations system (http://developer.dynamicweb.com/releases/dynamicweb-8-5.aspx#14610) that you should try. This new translation system does not support creating and editing global translations, but global translations can still be used it they already exist.

Best regards,
Mikkel

Votes for this answer: 2

 

You must be logged in to post in the forum