A Template for Multilingual Tags/Plugins

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
Russ
Power Poster
Power Poster
Posts: 813
Joined: Fri Nov 25, 2005 5:02 pm
Location: North West England

A Template for Multilingual Tags/Plugins

Post by Russ »

This is now in the Forge:
http://dev.cmsmadesimple.org/projects/multilingualtag

I've also added a sort of demo of a multilingual tag, called 'Random Guest Book Entry (Multilingual)' to the forge
http://dev.cmsmadesimple.org/projects/randgbtag


At GeekMoot 2009 there were quite a few requesting multilingual tag/plugins and UDT's (User Defined Tags)
Here is my first effort at a multilingual tag template (a multilingual UDT template may follow.)

This is a working tag which is really a template to be used as a base for developing your own multilingual tags!
It does not really do anything! I do have a rather more useful multilingual tag on the way if this one goes well ;-)

1. The display language is controlled by setting the 'lang' parameter of the Tag described below.
If you do not set this then the Tag will use the language set in Admin:
'Site Admin / Global Settings / Default language'
If no language is set there, then the Tag uses the default (en_US)

2. The admin language (for Help and About text) is controlled by the setting in Admin (so it is per user):
'My Preferences / User Preferences / Language'
If no language is set there, then the Tag uses the default (en_US)

3. To add to your page or template use:
{sfi_multilingual_tag_template lang='en_US'}

Currently for this test template, these are the languages available. For display on the page, (as output of the tag), for which you set the following 'lang' parameters.
* English (en_US)
* German (de_DE)
* Spanish (es_ES)
* French (fr_FR)
* Dutch (nl_NL)

If you use a language which isn't available in the Tag, you get the default en_US...

These languages are also available as Tag 'Help' and 'About' text and these are set automatically as stated above.

I've not tried this with the MLE version of CMSMS, I will if I get time, but you should be OK if you specify a language.
(I'm not sure if MLE relies on the same database fields.)


Please check out the multilingual help and about text and also check out the code - there are extensive comments in the code.
Let me know if I can improve things!
Also let me know what you think and could you / would you use it?

To use it save the attachment to your plugin directory and rename from:
function.sfi_multilingual_tag_template.txt
to
function.sfi_multilingual_tag_template.php

Also I'd like to apologise in advance about the tag translations, I used Google Translation for it so it could be absolute rubbish! Sorry.

There is now also a sister post: A Template for Multilingual UDT's (User Defined Tags)
http://forum.cmsmadesimple.org/index.php/topic,37816.0.html
Last edited by Russ on Tue Oct 20, 2009 1:26 pm, edited 1 time in total.
alby

Re: A Template for Multilingual Tags/Plugins

Post by alby »

Have you look to Translation Manager?

Alby
Russ
Power Poster
Power Poster
Posts: 813
Joined: Fri Nov 25, 2005 5:02 pm
Location: North West England

Re: A Template for Multilingual Tags/Plugins

Post by Russ »

Thanks Alby, I think this is maybe more use for Module translations or when you have a small number of text to translate. Or am I missing something? I'm not sure how it applies to this template idea, other than for translating the individual strings?

To be honest, I just pasted the whole code section into Google Translate, fixed the few errors and then pasted the translated language into the appropriate place in the Tag code.

Code: Select all

                //Help - Tag Description
		$helpTagDescription="<h3>What does this Tag do?</h3>";
		$helpTagDescription.="<p>This is a template for a multilingual Tag.</p>";

Code: Select all

 
		// Hilfe - Tag Beschreibung
		$helpTagDescription = "<h3>Was bedeutet das Tag zu tun? </h3>";
		$helpTagDescription .= "<p>Dies ist ein für eine mehrsprachige Tag Vorlage. </p>";
So the tip here is, get all you language sections strings (Display, Help and About) working in your default language first, check them out by viewing the tag Help and Admin text and also, of course, the text it produces on the page. When you are happy begin the translation process, however you like.

If you go with the route above, copy the code sections individually into Google and then translate them to the desired language. I'd paste that translation into a good text editor for fixing.

Somethings to watch for would be any CSS code and curly '{' or "}' brackets sometimes get converted to '(' and ') . CSS classes e.g. '.myClass' may get moved around. Any language marks often get translated (en_US). Also watch for spacing of comments marks '//' sometimes become '/ / ', separating of '$' from the variable, extra space in closing XHTML tags '' rather than ''.

There maybe other problems depending on your strings, but they are usually easy to spot when comparing to the original. I'd then check each language section, display, Help and About in your test site/Admin. A good text editor with good search and replace is your friend here. Of course I'm not saying the translation will be any good, a real human will do much better, but then the community could help out here?

I'm also not saying it is easy doing it this way, but it does mean you can have multilingual Tags in a single file with much less pain ;-)

If you have a requirement for more, or less, or indeed different languages in your tag, it is pretty easy to change.

Russ

p.s.
(I'd of course liked to have had separate languages files for each language, but that would defeat the idea of a simple single Tag file?)
Last edited by Russ on Wed Sep 30, 2009 8:02 am, edited 1 time in total.
Russ
Power Poster
Power Poster
Posts: 813
Joined: Fri Nov 25, 2005 5:02 pm
Location: North West England

Re: A Template for Multilingual Tags/Plugins

Post by Russ »

Bug Fixes for version 0.1
change lines 85-88 with

Code: Select all

$returnString='<p class="myClass">'.$returnString."</p>";
if ((isset ($TagDebug))) {
$returnString.=$TagDebug;
}
Otherwise the debug code for display always shows, sorry.
Last edited by Russ on Wed Sep 30, 2009 1:34 pm, edited 1 time in total.
cyberman

Re: A Template for Multilingual Tags/Plugins

Post by cyberman »

Russ wrote:

Code: Select all

 
		// Hilfe - Tag Beschreibung
		$helpTagDescription = "<h3>Was bedeutet das Tag zu tun? </h3>";
		$helpTagDescription .= "<p>Dies ist ein für eine mehrsprachige Tag Vorlage. </p>";
OK, here some corrections for german language :)

Code: Select all

 
		// Hilfe - Tag Beschreibung
		$helpTagDescription = "<h3>Was macht dieser Tag?</h3>";
		$helpTagDescription .= "<p>Das ist ein Template für einen mehrsprachigen Tag.</p>";
Yes, I know - template means "Vorlage" in german but as "chief" of german translations I think it should named Template in german too.
Russ
Power Poster
Power Poster
Posts: 813
Joined: Fri Nov 25, 2005 5:02 pm
Location: North West England

Re: A Template for Multilingual Tags/Plugins

Post by Russ »

Thanks cyberman, Google can never be as good as real people!
I've logged a bug for your changes and closed it.

It is fixed in svn and I will release another version when I've had some more language fixes ;-)

As it is only a template for others to build multilingual tags, I think they can make the corrections themselves in the mean time.
cyberman

Re: A Template for Multilingual Tags/Plugins

Post by cyberman »

Russ wrote: Google can never be as good as real people!
Yeah, if I want to laugh at times I take an english text and go to Google translator :). It's so funny ;D!
alby

Re: A Template for Multilingual Tags/Plugins

Post by alby »

Russ wrote: Thanks Alby, I think this is maybe more use for Module translations or when you have a small number of text to translate. Or am I missing something? I'm not sure how it applies to this template idea, other than for translating the individual strings?
No, you can use for content text too (look for {tr}.... content text ...{/tr}) if match all content OR use babelfish or Google for automatic translating {tr method=google}.... content text ...{/tr}

Alby
Post Reply

Return to “Developers Discussion”