WPML and NextGen Gallery Translation

September 29, 2010 § 6 Comments

I was searching on the net to see if anyone did some script to integrate both. At the end, nothing seems to work, I finally figure out a quick method to translate a dynamic string.

From here you can see the official site document about the string register
icl_register_string($context, $name, $value)
so basically you put

$content as The plugin name (name it the way you want, coz we are going to use it in front end later ) , in this case ,we  use ‘NextGen’

$name as the Hook that we link to the string.

$value as the value of the string.

After we understand the usage of this function, it comes clear to us that we only need to put it to the place where the string appear.

From the first sense, I can think about the NextGen Admin Panel.

Backend

So go to the file in NextGen plugin called Manage.php in line about 364

if (isset ($_POST['updatepictures'])) {
// Update pictures

……
if ( nggGallery::current_user_can( ‘NextGEN Edit gallery options’ )) {
……

Following the line, put icl_register_string function on.

For example,
icl_register_string('NextGen', $_POST['title'], $_POST['title']);
In this way, we can capture the title value among the gallery if we ever update them.
Then we can go to WPML >String Translation to do the translation.

For sure, you could put the capture code to anyway in almost anywhere in the plugin

Front End

We can put icl_t($context, $name, $value) to call the string translation.

The function will find the string with combination of context and name, and if not the value given will be return.
in our example, icl_t(‘NextGen’, $gallery->title, $gallery->title) .

Please make sure you understand the usage of NextGen Gallery and WPML , it does help to peek at the coding as well.

Advertisements

Tagged: , , , , , ,

§ 6 Responses to WPML and NextGen Gallery Translation

  • dana says:

    Hi,
    thanks for this, but where does the icl_t($context, $name, $value) part go, and in what file?
    Also if you happen to understand the mechanism, can you show an example using a field in the gallery itself (e.g. image title or description)?

    • nickwanhere says:

      Hi Danna,
      We can use the icl_t function almost everywhere in the wordpress theme as it is already loaded in the beginning.

      For example, Inside the Looping of the galleries,
      we can simply call icl_t(“NextGen”,$gallery->name,$gallery->name);

      It will use the combination of “NextGen” and the gallery name to find the translated string. so it is like pretty much echo __(“Gallery Name”), but in a dynamic way.

      If you mean the example of how to make use of specific field of the gallery, I think the default NextGen function library does not provide such way. However, you can always make use of its built-in function codes.

      Basically, there are two levels in NextGen Library.
      One is public method (nggfunctions.php),
      and the other one is such of model layer (dealing with database)(lib/*).

      NextGen default functions will markup everything for you, which is great, but sometimes we might want to customize in our own way. So maybe you could create a simple function inside NextGen and calling the written codes, return the gallery object before doing any markup.

      Regarding to Gallery/Album/Image Information, you could look at lib/ngg-db.php
      Using nggfunctions.php as a bridge to call function located in ngg-db.php
      After that, call the public method you created in the theme, then it should function as the loop.

      Dunno if I answered, but do hope it help you in some way.

  • dana says:

    Hi, yes I realize now that this is not the method for enabling/adding fields in different languages, only the translation of labels. I’ll look into what you said… thanks for answering.

  • Argonaut says:

    Hi!!!

    Where does the icl_register_string($context, $name, $value) go? 😦

    in the functions.php?

    For example after you input the text in the admin area… the index.php page is calling it like that:

    $site_desc = stripslashes(get_option(‘CT_site_desc’));

    HOW DO I get this to appear in the translation list? 😦

    THANK YOu in any case!

    Argonaut

    • nickwanhere says:

      Hi there Argonaut!

      Once you activate the WPML plugin, you can use the function everywhere!

      For the most simple case, theme
      You do not need this function as you could simply use
      echo __("Hello World",'MyCustomString')
      and then you go to WPML for scanning the theme, you will catch that string

      For another case, such as you want to capture dynamic string , which should be generated from the database. In your case.
      Put
      $site_desc=icl_register_string('MyCustomAdmin', 'Site Description', stripslashes(get_option(‘CT_site_desc’))) ;

      Hope I can answer your question!

      • Argonaut says:

        Thanks so much for this!!

        Finally I made it work with the xml file but I believe what you suggest above is more straightforward 🙂 So I ll try this as well ASAP.

        🙂 I ve seen a few posts of similar content – question (about admin screen strings) so I think I ll create a post with your answer and the xml “HOW to” as well

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

What’s this?

You are currently reading WPML and NextGen Gallery Translation at Nick Wan L.K..

meta

%d bloggers like this: