Announcement

#1 2010-03-04 20:17:12

nicolas
Former Piwigo Team
2004-12-30
1232

Gettext for plugins

Hi all,

after improving localization and afterwards translations for piwigo core and template, I want to  improve it with the same tools for plugins.

My idea is to allow people who make plugins to use messages.po files from piwigo core for words they want and to add other ones in a language tree with gettext files.
To do that I will add a new modifier in smarty to allow local translation and I will change l10n function prototype to allow messages.po files in other places.

The new l10n prototype will be :

Code:

function l10n($key, $textdomain='messages', $path='./language')

And the modifier for smarty will be :

Code:

  public function mod_local_translate($text)
  {
    return l10n($text, $this->plugin['textdomain'], $this->plugin['path']);
  }

I will also add a method to set values for theses two variables textdomain and path :

Code:

  public function setPluginConf($textdomain, $path) 
  {
    $this->plugin['textdomain'] = $textdomain;
    $this->plugin['path'] = $path;
  }

So in a plugin the way to add a translated string will be in php :

Code:

   echo l10n('My string to be translated', 'messages', 'path_to_plugin_language_directory');

And in a plugin template we can do :

Code:

<p>{'A string to translate from Piwigo core'|@translate}</p>
<p>{'A string to translate from my plugin'|@local_translate}</p>

The first string will be translated form piwigo core language directory and the other one from the language directory of the plugin.

After that all translations strings will be managed with gettext.

What's your opinion about that ?

Offline

 

#2 2010-03-04 20:33:59

plg
Piwigo Team
Nantes, France, Europe
2002-04-05
13848

Re: Gettext for plugins

As far as I understand, you're introducing a new feature here : the ability to have a another domain. A place where overloading is not possible. Right?

I admit I don't clearly see the advantage :-/ Can you give an example?

Offline

 

#3 2010-03-04 20:45:09

nicolas
Former Piwigo Team
2004-12-30
1232

Re: Gettext for plugins

plg wrote:

As far as I understand, you're introducing a new feature here : the ability to have a another domain. A place where overloading is not possible. Right?

Exactly  I introduce a new domain. I didn't find a clean way to allow language in plugin.

plg wrote:

I admit I don't clearly see the advantage :-/ Can you give an example?

If you have another idea you're welcome.

Offline

 

#4 2010-03-04 20:48:02

plg
Piwigo Team
Nantes, France, Europe
2002-04-05
13848

Re: Gettext for plugins

nicolas wrote:

plg wrote:

I admit I don't clearly see the advantage :-/ Can you give an example?

If you have another idea you're welcome.

I have absolutely no idea about this. I just wonder if 1) we can't overload strings in gettext system or 2) adding the namespace feature is necessary. I just don't know.

Offline

 

#5 2010-03-04 21:30:10

VDigital
Former Piwigo Team
Paris (FR)
2005-05-04
17680

Re: Gettext for plugins

Many plugins in WordPress are designed to use a domain for local translation.
As I understand it will be fine for Plugins and any .tpl (templates or template-extensions or templates file embeded in a plugin).


Piwigo.com: Start and run your own photo gallery. Signup and get 30 days to try for free, no commitment.
8-)

Offline

 

#6 2010-03-04 22:16:43

nicolas
Former Piwigo Team
2004-12-30
1232

Re: Gettext for plugins

VDigital wrote:

Many plugins in WordPress are designed to use a domain for local translation.
As I understand it will be fine for Plugins and any .tpl (templates or template-extensions or templates file embeded in a plugin).

My proposition solve problem of local gettext files in plugins and also for template even if I think it's not the right place (template) to put local language files. But you can do it. Happy ?

Offline

 

#7 2010-03-04 22:17:51

rvelices
Former Piwigo Team
2005-12-29
1960

Re: Gettext for plugins

Nicolas,
I think you need to pass the domain from the .tpl in plugins .... ( A template can include another, a plugin can change the template from the core so I think there is no way to find the domain just from <p>{'A string to translate from my plugin'|@local_translate}</p> ... because the execution of the rendering is delayed ... )

I would rather see something like
mod_translate(($key, $domain = "piwigo" )

and from my plugin rv_gmaps I would say
{'Maps'|@translate:'rv_gmaps'}

Last edited by rvelices (2010-03-04 22:19:56)

Offline

 

#8 2010-03-04 22:42:38

nicolas
Former Piwigo Team
2004-12-30
1232

Re: Gettext for plugins

rvelices wrote:

Nicolas,
I think you need to pass the domain from the .tpl in plugins .... ( A template can include another, a plugin can change the template from the core so I think there is no way to find the domain just from <p>{'A string to translate from my plugin'|@local_translate}</p> ... because the execution of the rendering is delayed ... )

I would rather see something like
mod_translate(($key, $domain = "piwigo" )

and from my plugin rv_gmaps I would say
{'Maps'|@translate:'rv_gmaps'}

Thanks, I'll appreciate your advices. I know there's no way to find the correct domain, so I have proposed a new method for plugins (and what else ?) to give theses informations

Code:

  public function setPluginConf($textdomain, $path) 
  {
    $this->plugin['textdomain'] = $textdomain;
    $this->plugin['path'] = $path;
  }

In my plugin, I can do somethink like that :

Code:

$template->set_filenames(array('plugin_admin_content' => MY_PLUGIN_TEMPLATE . '/admin.tpl'));
$template->setPluginConf('messages', 'path/to/plugin/language/directory');
$template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');

And in my plugin template, I can use my local strings with local_translate and strings for piwigo core with translate.


I didn't understand how do you find the right piwigo.po file with your proposition.

Offline

 

#9 2010-03-04 22:58:52

nicolas
Former Piwigo Team
2004-12-30
1232

Re: Gettext for plugins

My beautifull new method already exists and is called bindtextdomain and so rvelices is right.
The correct way is to use piwigo for gettext files from the core and plugin name for others.
Thanks.

Offline

 

#10 2010-03-05 00:13:24

P@t
Piwigo Team
Nice
2007-06-13
4098

Re: Gettext for plugins

rvelices wrote:

I would rather see something like
mod_translate(($key, $domain = "piwigo" )

and from my plugin rv_gmaps I would say
{'Maps'|@translate:'rv_gmaps'}

I like this idea... but... in {'Maps'|@translate:'rv_gmaps'}, what is 'rv_gmaps'? Is it directory name of the plugin?
Be careful with that.. if a plugin developper add plugin's files in the root of the archive (in PEM) without plugin subdirectory, the automatic installationof plugin manager will create arbitrary directory like extension-250.


P@t

Offline

 

#11 2010-03-05 00:23:47

mathiasm
Former Piwigo Team
2006-02-06
2650

Re: Gettext for plugins

nicolas wrote:

My beautifull new method already exists and is called bindtextdomain and so rvelices is right.
The correct way is to use piwigo for gettext files from the core and plugin name for others.
Thanks.

And how do we manage text for templates? Can we put language mo files in templates/yoga/yummy/language and define a new domain, maybe in themeconf.inc.php ?

Offline

 

Board footer

Powered by FluxBB

github twitter newsletter Donate Piwigo.org © 2002-2024 · Contact