IMPORTANT ANNOUNCEMENT

These forums will be permanently set to read-only mode on July 18, 2022. From that day on, no new posting or comment will be allowed on the site, but the historical content will remain intact and searchable.

A new location for posting questions about PlanetPress Suite is now available:

OL Learn - PlanetPress Classic (opens in new tab)

Topic Options
#33360 - 09/20/10 04:07 PM Detect current language in a custom PHP template
RandomPHPDev Offline
OL Newbie

Registered: 09/20/10
Posts: 17
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.

Top
#33375 - 09/22/10 07:55 AM Re: Detect current language in a custom PHP template [Re: RandomPHPDev]
cosimo Offline
OL Expert

Registered: 10/31/01
Posts: 1286
Loc: montreal
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

Top
#33432 - 09/27/10 02:00 PM Re: Detect current language in a custom PHP template [Re: cosimo]
RandomPHPDev Offline
OL Newbie

Registered: 09/20/10
Posts: 17
Hey nice stuff! Works great.

Now some other cool stuff comes to mind!

Top