Detect current language in a custom PHP template

Posted by: RandomPHPDev

Detect current language in a custom PHP template - 09/20/10 04:07 PM

I am creating a bunch of custom template pages for an installation of PrintShop Mail Web 7. The target audience for this site is large mix of English and French users.

Problem: How do you render different language content from a custom PHP template page?

For example, if a user switches to French language, all of the native Printshop Mail Web menus and content will appear as French, same with the welcome message on the homepage… BUT obviously any custom template content would still appear as English because our custom PHP isn't going through any pre-rendering.

Is there a global language variable that can be checked in PHP?

-OR-

Is there a way to create custom PHP templates PER LANGUAGE, for example something like this: template-french-storefront_overview.php ?

-OR-

Is there a way to pipe our custom PHP through the native PrintShop Mail Web language module before it goes to final rendering?

There is one workable option so far, but it's risky and unfavoured. Basically using Javascript to detect what the current selected language is in the language drop-down. But this means a dependency on the client browser to run the Javascript without issues, and also it means every user will be downloading English and French content for every page. As well there's potential issues where a French user may accidentally see English content.
Posted by: cosimo

Re: Detect current language in a custom PHP template - 09/22/10 07:55 AM

Hi,

The solution to this consists of the following:
1) Add your custom string to the desired languages
- Settings->Languages->Select Language, add your string to the end of the User Interface strings. Example strings are:
- English: cHelloWorld=Hello World
- French: cHelloWorld=Bonjour le monde


2) Add the following php code to your template to retrieve the string:
<?php generateString('cHelloWorld'); ?>

Hope this helps!
Cosimo
Posted by: RandomPHPDev

Re: Detect current language in a custom PHP template - 09/27/10 02:00 PM

Hey nice stuff! Works great.

Now some other cool stuff comes to mind!