Member
Member
vincent3569   01-08-2017, 12:44
#1

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.

Administrator
Administrator
acrylian   01-08-2017, 13:35
#2

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.)example.com is one language, in your case probably French and for all other language you use subdomains for example en.example.com. 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).

Member
Member
vincent3569   01-08-2017, 15:16
#3

my piwik JS code is generated on server side via my plugin (you cas see older one in https://github.com/zenphoto/Unsupported/tree/master/plugins/piwik).

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

tks

Administrator
Administrator
acrylian   01-08-2017, 16:48
#4

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')
http://www.zenphoto.org/documentation/core/_functions-i18n.php.html#functionget_language_string

Member
Member
vincent3569   02-08-2017, 09:27
#5

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');
and
$_zp_current_album->getTitle($piwik_lang));

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 ?

Administrator
Administrator
acrylian   02-08-2017, 09:34
#6

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)

  
Powered By MyBB, © 2002-2026 MyBB Group.
Made with by Curves UI.