Jump to content

Using translateable strings in external file always shows the default language


Recommended Posts

Hello @ all

I am struggeling with this problem now for hours and I could not find a working solution.?

Problem description:

I have a HTML file, which is a HTML template for an email - so it includes Markup, static texts and translateable strings. Lets assume that it would look like this:


<p>My mail template</p>
<?php echo _('Hello user');?>

On another file, which should send the mail, I want to include this file to be the mail->body.


$body = ob_get_contents();

As you can see, the variable $body contains now my rendered HTML file - this works, but it does not take account of the user language. It always outputs the translateable strings in the default language.

I have not found a way to output it fe in German.

The goal:

I want to put the rendered content of the mail-template.html (including the correct translations of the text!) to PHP variable, so I can use it as the mail->body text.


The problem is, that ob_get_contents does not take account of the user language, even if I set it explicitely.

I have also tried it with file_get_contents, but in this case, I cannot get the rendered text.

Does anyone have an idea, how this could be done??



Link to comment
Share on other sites

  • Juergen changed the title to Using translateable strings in external file always shows the default language

This is a good idea @gebeer

but unfortunately, I got the same result as using ob_get_contents. The translateable strings are not translated.?

If I check the user language with Tracy bd() function, I always get that the user language is set to German. This is the correct language, but the strings are still in English.

Link to comment
Share on other sites

OK, it seems to be another problem that I thought it would be:

The translateable strings were not found by PW. I have so much translations done, that I did not notice that the strings are not translated in the backend.?

In other words: All translateable strings inside this template HTML file do not appear in the backend to be translateable, so they are not translated.

Now I have to find out, why these files were not fetched by ProcessWire.

Link to comment
Share on other sites

Yes, you are right - PHP files will be fetched.

Anyway, the strings are still in the default language. No difference to before! ?

I guess I have to overthink my template system for sending HTML emails, because the template files are always HTML files. 

Thank you for your help @gebeer

  • Like 1
Link to comment
Share on other sites

No, my email templates are made the old fashioned way (HTML tables) and hand-written. And there is no namespace used inside those email files. The template files are part of a module and the module has its own namespace (not Processwire). So the module can send out various emails. It works fine until multi-language is used. I dont think that there is a namespace problem.

I also use some placeholders inside the templates, which will be filled with variable data from outside and this works in multi-language, because the translations are not set inside the template file, they are set inside the PHP file for sending the emails.

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...