Developer forum

Forum » Templates » Translate tags are not processed

Translate tags are not processed

Marco Santos
Reply

Hello.

I am using a template to create the body for an email, but unfortunately the translate tags are not being processed, so the email looks a bit rubish. This is what is being done:

            Area currentArea = Area.GetAreaById(areaId);

            var bodyTemplate = new Template(currentSettings.Where(s => s.Key == Setting.REGISTRATION_TEMPLATE).First().Value.Replace("/Templates/", ""), currentArea.Culture);

And then further down there is this

            mail.Body = bodyTemplate.Output();

            return EmailHandler.Send(mail);

This is being used in an Ajax call, not sure wheter that is relevant or not. It is getting the right template, but the contents are not right. The Dinamycweb version is 8.5.1.17.

Any ideias on what might be missing?

Thanks.


Replies

 
Nicolai Høeg Pedersen
Reply

Hi Marco

Template translations run in the context of a pageview. So if you do not have a pageview, you will not get any translations. So before loading the template you could load a Pageview in the right area id - that holds the regional information that the template instance uses to do translations.

You can also upgrade to 8.6.1 and use a Razor template. In that you can call @Translate(key, defaultValue, cultureName) and get the translation.

BR Nicolai

 
Marco Santos
Reply

Hello.

I understand what you mean but not exactly how to achieve it. I have changed it to this:

Area currentArea = Area.GetAreaById(areaId);
 
PageView pageView = PageView.GetPageview();
pageView.AreaID = areaId;
pageView.Area = currentArea;
 
var bodyTemplate = new Template(currentSettings.Where(s => s.Key == Setting.REGISTRATION_TEMPLATE).First().Value.Replace("/Templates/"""));

This does improve things, as the translate tags are now being replaced, but it always uses the default specified. I have tried using a culture in the template constructor, but the results are the same. Is there an additional step that is required?

Thanks.

 
Nicolai Høeg Pedersen
Reply

Use pageview.GetPageViewById(PageID) instead.

 
Marco Santos
Reply

Same result, unfortunately.

Do I need to do anything with the PageViewContext ?

Marco

 
Nicolai Høeg Pedersen
Reply

Hm... It can be anything. It is not meant for doing that.

You can get translation keys directly from Dynamicweb.Rendering.Translation.Translation.GetTranslation(key As String, culture As CultureInfo, design As Design) As String

 

 

You must be logged in to post in the forum