PLUG IN : Multi Language

Ludo / 2009-07-21 19:45:35   

Hi.
Due to my personal needs, i created a Multi Language plugin.
You can find the demo and the source code here :

http://www.ludovicpages.com/portfolio/index.php?/projects/multi-language-indexhibit-plugin/

It's my first plug in so ... it may have some errors.
You can report bugs here.

Thanks.

Ludo

Ludo / 2009-07-21 19:46:22   

Better with the link ;)

Demo

Vaska A / 2009-07-21 20:20:25   

So, what it does is toggle between to languages on the page?

You should call this a Multi Language Toggle Plugin.

Ludo / 2009-07-22 00:07:55   

You'r right. I didn't paid any attention to the name.

drizzle / 2009-08-08 12:30:51   

Hello

This plugin looks neat!
Well on your website : )
On mine it doesn't work and I don't know why.

here is what I got: test

I followed the instructions. But I think I miss something.
Littles flags doesn't load. It seems that the plugin is not called or something.

  1. Could you help me? 
  2. Here is what I type in the exhibit window:
  3.  plug:multi_language default="us", lg="us-fr" 
  4. div id="us" class="lg"
  5. Content in English
  6. /div
  7. div id="fr" class="lg"
  8. Content in French
  9. /div
  10. with the < >

Thanks

Vaska A / 2009-08-08 15:45:23   

For whatever reason the javascript is not firing up - causing an error.

drizzle / 2009-08-09 10:12:30   

when I look at the source code of this test page in Firefox, it seems that the multi language script is at the very first line. Before the type declaration and before the head tag...

It does not do that with the simple news for instance.
Is it the problem?

drizzle / 2009-08-09 10:16:05   

hu nevermind, i checked the Ludo page and it is the same...

arsondpi / 2009-08-09 10:37:51   

Hello...

That's because the code asks for the flags in these addresses:
http://eyewash.be/about/test/ndxz-studio/site/img/multi_language/us.gif
http://eyewash.be/about/test/ndxz-studio/site/img/multi_language/fr.gif

And the flags don't exist there... Either fix your code or move the flags to the appropriate directory....

And last but not least, I see a... copy of your template in html, instead of the multi_language.js!!!
Fix this! The script isn't loading! Validate your html and your css for a head-start...

drizzle / 2009-08-09 12:01:17   

Hi thanks for your input.

With my FTP application, i put the flags in:
eyewash.be/ndxz-studio/site/img/multi_language/
as specified in the Readme file.
But the plugin seek those pics from the exhibition where he is written, and not from the root of the website.

I see this in the php file of the plugin:
$pathToSiteFolder = 'ndxz-studio/site'; // You may need to edit this line

How can I determine the exact path? Because as you said, the plugin seems to use the address of the exhibition, and not the "website address".
I had some tries yesterday but it does not work. And infos about "$pathToSiteFolder" on google are stingy.

I tried to put the address of the website and other combination like a "www/" or ".../" before the /ndzx-studio but none works.

And for the last, I don't understand how a copy of my html template can be there. Once again in my FTP I see the multi_language.js, when I open it, I see it as I downloaded it. I tried to re-upload all and it is still the same.

My html is valid when I erase the plugin files from my server.
For the CSS, I correct some mistakes but I cannot find the .thumb .thumb-it etc. They are not is my style.css...

Thanks for the help

arsondpi / 2009-08-09 15:11:19   

you just uploaded the correct js file and and it should work now...
The images aren't in the correct spot... recheck and try a reuyload if they are in the right directory...

drizzle / 2009-08-09 18:17:53   

I re-uploaded the js file which was the same as the previous one. I opened it from the ftp and compared it. All the same. I re-uploaded all.

When i put the plugin files into my server, my html is not valid, it become valid when i delete all the files.

For the image folder, i have to put it in: "ndxz-studio/site/img"

this address: "http://eyewash.be/about/test/ndxz-studio/site/img/multi_language/"
It does not exist on the server. we can see it in the browser but not in the ftp application.

I don't know if you checked the readme file from the plugin package? It says:

Copy the "multi_language" folder into SITE -> IMG
Copy the "multi_language.js" filw into SITE -> JS
Copy the "plugin.multi_language.php" file into SITE -> PLUGIN

Once you'v done this, for each new post, you have to include the plugin with the following code :

>plug:multi_language default="us", lg="us-fr" />

As you can see, there is two parameters.

THOSES PARAMETERS ARE REQUIRED TO MAKE THE PLUG IN WORK

"default" is the default language
"lg" is the list of the others languages you want to display. It's important to separate them with a "-".
You must use the same name as the images name(in the img/multi_language folder) corresponding to the language. (for exemple, fr.gif is the name of the french flag, so you have to use "fr" into the lg parameters.

Then you just have to put each new language in a div, using this code :

>div id="us" class="lg">
Content in English
>/div>

>div id="fr" class="lg">
Content in French
>/div>


It seems quite simple.
But it doesn't work...
Do you tried it?

I don't know, maybe I'm missing something, something easy.
And it is fully possible that I miss something...

drizzle / 2009-08-11 07:13:06   

any clue on this please?

Vaska A / 2009-08-11 07:36:59   

Have some patience...please read the forum rules.

lemathieu A / 2009-08-11 09:38:39   

Or simply drop a mail to the first poster…
And be gentle with him!

drizzle / 2009-08-11 10:40:43   

haha yeah I'll try... but you know, i'm a beast...
I really thought I was polite, well I don't know, english is not my mother language, maybe I speak like the hero in some action movie... : )
Maybe upping a post in this forum is rude?

Vaska A / 2009-08-11 10:52:07   

Indexhibit is much smaller than people think - there are maybe three people who help out here regularly (on our own spare time) and we can't support every piece of code people post to our forum.

If he comes back in the next month to look in on this thread that would be nice.

Ludo / 2009-08-11 11:42:09   

Hi
I didn't check this post for a while.
Just an idea : i saw that you (drizzle ) turned the MODREWRITE to true.
Maybe this can be the problem. I'm at work now and i cannot check more, but just try to turn it off and see if it works.
If this is the problem, ill try to fix it soon.

Tell me.

Ludo

Vaska A / 2009-08-11 11:44:43   

I think I'll look into adding a forum thread notification system...not today though.

Thanks Ludo for checking back.

;)

drizzle / 2009-08-11 12:19:44   

Hi again!

It was the problem, I turned the MODREWRITE to false and it works perfectly now!

So much thanks Ludo for the support

Ludo / 2009-08-11 12:36:15   

Great ! I'm gonna try to fix it this week, and update the plug in.

Ludo

Ludo / 2009-08-12 09:58:02   

Ok.
I fixed some bugs
You can download the updated version HERE:

REVISIONS
12-08-2009 The plugin works with REWRITE MODE set to true or false.
The plugin works with IE6 and IE7.

Ludo

Vaska A / 2009-08-12 10:00:06   

Hey...what's this?

IndexHibit? Indexhibit?

;)

Nice little update...should make folks happy.

lemathieu A / 2009-08-12 10:09:34   

Sure it will do.
Good job!

drizzle / 2009-08-12 10:16:51   

Hey thanks Ludo!
Works like a charm!
And I tested it on IE8, works fine too.

superatic / 2009-08-15 18:32:06   

Thank Ludo!!!
simple is possible!!

superatic / 2009-08-15 18:45:35   

Hey!!

I have any problem in the installation fase!!!
I don't know if change or don't change the path on the line 16 in !

I tried to put the path of my webpage.. and does not work!

legnaleama / 2009-08-15 19:36:32   

aweson Ludo ! A couple of your models in ur portfolio are my classmates !! hahahaha

Ludo / 2009-08-16 21:14:53   

Hi All.
superatic, try to replace the line 16 of the plugin by this one :
$pathToSiteFolder =BASENAME.'/site/';

This should work.

Any way, i updated the plug in cause using BASENAME looks to be the right way to get the right folder.
Did anyone know if there is an easy way (variable) to have the "site" folder ?

legnaleama : Really ??? witch ones :)

lemathieu A / 2009-09-15 17:58:32   

Hello everybody,

I was trying to use this plug in but realize that it was not validated…
So I took my little hands, dive into the code and correct some…

Here is the semi-corrected php, but I can't manage to correct the lasts errors.

I sent a mail to Ludo, expecting a hand.

If somebody wants to give a eye on…

Thanks in advance.

lemathieu A / 2009-09-16 16:58:43   

Sh#+…

I can't do better than 11 errors when I try to validate…
Eleven !

:(

minimarc / 2009-10-08 16:09:45   

This helps a lot... but what about choosing only once, and then having the whole site in the chosen language. Is that impossible? has anyone dared to tackle this issue already?

Thx!

lemathieu A / 2009-10-08 16:16:17   

Next version I think.

For now… 2 indexhibit ?
:P

airmonkeynr / 2010-02-27 12:45:29   

Hey guys -

This post is a bit old but i found a way to have a validate xhtml strict page with this plugin.

At least, it worked for me.

http://www.sendspace.com/file/btxscd

let me know if this works!

airmonkeynr / 2010-02-27 12:46:18   

LINK

http://www.sendspace.com/file/btxscd

zardok / 2010-03-05 11:37:20   

Hello.

   Here is a modification of Ludovic Pag√®s multi_language plugin i made for my own need.
The goal of this modification is to select language only one time for the all site and not for each post.
(Be tolerant, it's a first quick&dirty modification using a cookie.)

All you have to do is :

Follow Ludovic Pagès multi_language plugin install
(at least copy the "multi_language" folder into SITE/IMG ).

Install the modified files:
copy the "mb_multi_language.js" file into SITE -> JS
copy the "plugin.mb_multi_language.php" file into SITE -> PLUGIN

As for original plugin, you may have to modify the following line in 'plugin.mb_multi_language.php' and replace the value by your own SITE path
$pathToSiteFolder ='ndxz-studio/site/'

Then include the plugin once in the Post-Nav (or wherever you want in your theme index)
with the following code (same parameters as original plugin) :
<plug:mb_multi_language default="fr", lg="fr-us" />

Once this is done, for each new post, you just have to put each new language in a div, using this code :

<div id="us" class="lg">
Content in English
</div><div id="fr" class="lg">
Content in French
</div>

Modified files here
Sample here

Michaël Bruyère (mb-idxibit@zardok.org)

lemathieu A / 2010-03-05 13:13:24   

thanks to share man

puppiepoppy / 2010-03-06 04:01:40   

I wonder if it's possible to switch to other languages (chinese, japanese, etc) and anyone knows how accurate is the translation?

arsondpi / 2010-03-06 09:27:25   

You set the text - ...and you have to do a translation.
This is a switch (as in a switch on a wall).

puppiepoppy / 2010-03-06 13:33:41   

Ohh I see...then it's even better! Manually type them in instead of those inaccurate automatic Google Translation. Awesomeee! Thanks.

jspr / 2010-03-30 00:47:30   

Ludovic, Michaël, great work on this plugin.
I managed to get it working too, so I can start making the translations now. As soon as that's done I'll activate the plugin an have a bilingual website.
I was wondering if it's possible to give the country flags a link like behaviour upon rollover. I've been playing with the code itself for a while bit didn't succeed yet. Any suggestions?
I would also like to use textlinks instead of the flag images. I think that could be easily achieved but my knowledge of code is rather limited.

ivo_valadares / 2010-03-30 08:47:54   

Hello. Is this only french - english or it acepts other languages?

Thanks

jspr / 2010-03-30 22:48:56   

Ivo, the plugin accepts any language, it's you that will have to do the actual translation.
In every new post for each language the text has to be entered in it's own div. The div's id signifies the language and is picked up by the plugin, that will decide which text to show according to the selected language. This is explained in the readme.txt that's in the zipfile. Nice mule by the way.

ivo_valadares / 2010-03-31 07:43:46   

Isn't it? It's me, I'm a mule. Mule have needs too :-)

Kind naiive, I though with this plugin the translation would be sort of automatic.

Nevertheless I'll save it just in case in a near future I need it.

Thank

jspr / 2010-04-05 02:55:06   
  1. I've managed to give the country flags a link like rollover behaviour and change them into text by editing this line in the plugin .php file:
  2. $menu .=  '< a onclick="showHide(''.$lg_array[$i].'');setDefault(''.$lg_array[$i].'');">< img src='.$pathToSiteFolder.'img/multi_language/'.$lg_array[$i].'.gif></a> ';*/
  1. I changed it into:
  2. $menu .=  '< a href onclick="showHide(''.$lg_array[$i].'');setDefault(''.$lg_array[$i].'');">'.$lg_array[$i].'< /a> '; 
  1. I have a new problem though: the function can't be called more than once on a single page. When it's called more than once the second and following instances show the text in both languages simultaneously. I take it this could be fixed, by editing the php code some more. My best guess is that it has something to do with this ($id=0) piece of code, that I noticed in the archives plugin, but I'm still a php novice:
  2. function ndxz_archives($id=0)

does anyone on have a suggestion?

jspr / 2010-04-05 02:56:15   

posting code is a new thing for me too...

MBE / 2010-04-13 08:51:51   

Hello,

   Here is a correction of my modification to use default language when cookies are not enabled.

in the mb_multi_language.js file, change the first function:

$(function()
    {
       getDefaultId = getCookie('currentLgId');
       if (getDefaultId != 0) defaultId = getDefaultId ;
       hideAll();
       showDefault();
    }
)

   I'm working on a new modification that use some local session storage instead of cookies when they are disabled so a user can change the language settings for the time of his session even without cookies.

Michaël Bruyère (mb-idxibit@zardok.org)

MBE / 2010-04-13 10:33:10   

Hello,

    Here is a new version of the javascript file modified to enable multiple div with the same language.
I hope it should solve your problem JSPR.

This script now use the div name property instead of the id property.

  1. Sample:
  2. <div id="us-1" name="us" class="lg">First text in English</div><div id="fr-1" name="fr" class="lg">Premier texte en Fran√ßais</div>
  3. image or other include<div id="us-2" name="us" class="lg">Second text in English</div><div id="fr-2" name="fr" class="lg">second texte en Fran√ßais</div>

You can find the file here

Michaël Bruyère (mb-idxibit@zardok.org)

PierreLucF / 2010-06-16 11:38:58   

Hi,

I am using the multi-language plugin last update by MBE
so I can make multiple div with the same language.

It works perfectly on firefox and its really nice !

But , if im right, on IE 6,7,8, the div name propoerty is not supported. So the text wont't appear for both of the language. When validating I get only one error :

Error Line 76, Column 21: there is no attribute "name"

Do you guys have any clue how to solve this, and have multiple div of the same language that work on IE ?
(if im correct that mean to use an alternative to the div name property, but since im a dummie to writing plugins or js, I dont know where to start from.)

Thx a lot for help and this amazing plugin !

adlai / 2010-06-20 15:11:42   

Hi,

Can the plug-in support 3 languages, or is it just 2? I'm trying to toggle between 3 languages on my site using the below code. However, it's only showing the first 2 flags.

Any ideas? I really appreciate. And thanks for the great plug-in!

  1. <plug:multi_language default="au", lg="au-cn", lg="au-jp"/>

Here's the site: http://www.centralstudios.cn/space/studio-layout/

This thread has been closed, thank you.