how to : force a language for translated string

I am writing a piwik plugin (I use the unsupported existing one).

I want to log pages title, but only in one language (french).
Basically, it allows to avoid multiple titles to be tracked for the same page.

I found the way to force zenphoto items titles (`$_zp_current_album->getTitle('fr_FR')` as example).

But I didn't find the way to force translation of translated strings (as `gettext('Home')` or `gettext('Gallery')` as examples).

I tried the function `string dgettext ( string $domain , string $message )` used like that `dgettext('fr_FR', 'Home')`, but It does not not work.

Have you a solution to force translation? Or to well configure the function above?

thanks in advance for your help.


  • acrylian Administrator, Developer
    On class level you can actually request a translation string for each field that is multilingual capable using `get_language_string()`. Gettext is generated server side before loading so you cannot request. When trackers like Piwik track their data using JS it is all already done.

    If you really have a multilingual site and what it tracked correctly I suggest to use the subdomain way suggested. That can be set via the seo_locale plugin.

    So your main domain (www.) is one language, in your case probably French and for all other language you use subdomains for example That way you have separate urls for each language which naturally is recommended for SEO anyway. Piwik should be able to see these as separate site (may depend on its settings, can't say right now).
  • my piwik JS code is generated on server side via my plugin (you cas see older one in

    I don't want to have subdommain, only track my multi-language site with one language (as every visitor was french for example).

    Can you point me in the right direction to use `get_language_string()` function?

    For example, to force display french title of the album stored in `$_zp_current_album`?
    - `getBareAlbumTitle()` returns only title in the visitor language
    - `$_zp_current_album->getTitle('fr_FR')` works

  • acrylian Administrator, Developer
    Okay, but I really recommend to use subdomains if you really need multilingual sites for SEO reasons alone. And I assume you care a bit about that as a site owner.

    Multilingual is really only recommend when you actually have your content texts in those languages and not jus the default strings covered via gettext translations.

    You have to get the raw fields so you get the full array with all languages. You can do that via for example
    $title = $_zp_current_album->get('title');
    $yourlocale_title = get_language_string($itle, 'fr_FR')
  • hi

    can you confirm this 2 syntaxes have the same behavior and give the same result :

    $title = $_zp_current_album->get('title');
    $title = get_language_string($title, 'fr_FR');

    behavior: give the fr_FR string, or the en_US string if fr_FR doesn't exist, or the first string which ever is present, if first ones don't exist ?
  • acrylian Administrator, Developer
    Yes, all multilingual capable functions use this function internally (the method `getTitle()` is defined within the parent main class `PersistentObject` in `classes.php` where you can directly see this)
Sign In or Register to comment.