Developer forum

Forum » Development » Translation via webservice call

Translation via webservice call

Ola Eriksson
Reply

Hi,

We have a web service that we want to return translated text from, we used to call 

Dynamicweb.Backend.Translate.SetLanguage(culture.LCID);
return Dynamicweb.Backend.Translate.Translate(key);

We tried to use 

var messageTemplate = new Dynamicweb.Rendering.Template("Message.html");
messageTemplate.SetTag("Message", key);
var translatedMessage =  messageTemplate.Output().Trim();

Message.html contains the translation tags. Example,  <!--@If(Softgear:Message='fel_uppstod')--><!--@Translate(fel_uppstod, global)--><!--@EndIf-->

translatedMessage does not give us the translated version of the key

Regards

Ola

 


Replies

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply

Hi Ola,

The reason you can't get this to work is because you are dealing with two different, unrelated translation concepts in your code. The class Dynamicweb.Backend.Translate deals with localizing the Backend (Administration) of Dynamicweb.

The Translate tag uses a different translate system, Dynamicweb.Rendering.Translation. I believe this is the API you're looking for. You can probably use one of the Dynamicweb.Rendering.Translation.Translation.GetTranslation overloads to get a translation for your key.

Bear in mind that the translation system was not designed to work outside of a template scenario, so you might experience some unexpected behavior by invoking it in a web service.

- Jeppe

 
Ola Eriksson
Reply

Thanks Jeppe, but this API seems to be missing in version 8.4.0.10, it is newer?

//Ola

 

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply

Yes, it was introduced in 8.5.0.0.

Any reason you're still using a version from spring 2014?

 

You must be logged in to post in the forum