Jump to content

Setting the language of a page to be rendered


Dani
 Share

Recommended Posts

Hi there

I want to render a page in a particular language, somehow like $page->render('de'). How can I achieve that?

Some background information to my problem: I wrote a module that generates HTML newsletter emails. From the PW backend I use that module to send emails, which are represented by pages that are rendered and sent off. Now I want to control the email language. The email shouldn't be just rendered in the language of my backend user account, of course.

Any help is much appreciated.

Best, Daniel

Link to comment
Share on other sites

Some information before more advanced users help you.

For better researches, in Google you can use, for example : site:processwire.com/api "keyword(s)"
You can do the same with /talk, /blog... instead of /api. With quotes of without them, with AND, OR, -... also of course.

https://processwire.com/api/ref/page/url/ (there is a language option)

https://processwire.com/api/ref/page/#pw-methods-languages

If I understood correctly (also from forum(s) posts), wire must or should be used from inside a module:
https://processwire.com/api/ref/wire/
You can normally use wire('page')->something, wire('languages')->something...
There is an API helper for languages.

Edited by Christophe
Link to comment
Share on other sites

// save user default language
$savedLanguage = wire("user")->language;
$emailLangauge = wire("languages")->get("german");
wire("user")->language = $emailLangauge;

$mail = $yourpage->render();

// restore the original language setting
wire("user")->language = $savedLanguage;

Not tested

  • Like 4
Link to comment
Share on other sites

On 4/8/2017 at 5:18 PM, Zeka said:

// save user default language
$savedLanguage = wire("user")->language;
$emailLangauge = wire("languages")->get("german");
wire("user")->language = $emailLangauge;

$mail = $yourpage->render();

// restore the original language setting
wire("user")->language = $savedLanguage;

Not tested

Hi Zeka

Thanks for your answer, which was not only fast but also precisely what I needed.

-Daniel

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...