Multilingual contents

Multilingual contents

by Robert Hetzel -
Number of replies: 21

I'm working at a bilingual - even trilingual - school (German school in Puebla, Mexico; http://www.logo-humboldt.com ) and I'd like to have the contents - not just titles, comments, help files etc. - change when the language is changed (I've seen it done in PostNuke on http://www.colegio-humboldt.com, but I wasn't involved in the development of that site).

Since I've programmed computers for more than 30 years (php only since march, when I discovered moodle) I'm going to try to do it myself if nobody else has done anything similar. My basic idea is to write a simple function to analyze the text and return only the part that fits the current language. Then all we need to do is pipe every piece of user text through this function. Other methods might be more professional, but many user interfaces would have to be redesigned and I don't know if the demand great enough for such an "expensive" solution.

Input might look like this (e.g. using [lang] as a language tag, empty tag is default, * could be a wild card): []Introduction[es*]Introducción[de]Einleitung. There should be a site option to choose for multilingual sites. Then the first two characters of text would be the delimiters if chosen sensibly (e.g. non-char, non-numeral, non-space and with an ascii-code less than 128).

Since I only work with German, Spanish, and English (and maybe French), I won't look into problems with different alphabets. Also, I teach 20 lessons per week, so it will take some time for this child to be born (I'll try to get a hackers version out soon for further discussion).

Please report any information or design idea on this subject. Thanks

Average of ratings: -
In reply to Robert Hetzel

Re: Multilingual contents

by Thomas Robb -
I seriously doubt that the PostNuke site that you mention is translating content "on the fly." Most likely, it has been pre-translated. Writing a language translation program is a tremendous undertaking, and even the for-fee programs available are not 100% accurate. Considering the fact that you will have language learners reading the site, it does not make sense to go with anything that would yield imperfect text. (To the best of my knowledge the only programs which approach 100% accuracy are those dealing with a restricted lexical and semantic domains such as those translating weather reports.)

I wouldn't make sense for a translation feature to translate content "on the fly" each time a user clicked on it. A better algorithm would involve pre-translating the text, perhaps with a language translation tool, and then tweeking the results by hand to perfect the syntax and style.

Since the site you quote appears to also be at Puebla, it should be a relatively easy proposition to track down the site managers to find out how they do it.

Even if there was a language translation facility available in PostNuke, the answer would not be to imitate it, but rather to take their code and USE it!
In reply to Thomas Robb

Re: Multilingual contents

by Robert Hetzel -
Sorry if I didn't express myself clearly enough: I'm not talking about translating "on the fly". Many of us here know two or three languages well enough to translate manually, the program only has to "choose" the right text.
In reply to Robert Hetzel

Re: Multilingual contents

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
I'd love to see this!

A good way to implement this would be to implement another format type called Multilingual (to sit alongside Moodle auto-format, HTML format, Plain text format and Wiki format).  All the infrastructure is there for that already, and parses texts for display.  All the code is in lib/weblib.php - you could make a new function called multitext_to_html

Someday, a multilingual editor could be used, but for now people could specify different languages using XML like:

<span lang="en" class="multilang">
Introduction
</span><span lang="es" class="multilang">
Introducción
</span><span lang="de" class="multilang">
Einleitung
</span>

The "lang" codes should be the same as the ones currently used for languages in Moodle.  The "format" codes specify the actual text format (auto, html, plain, wiki) with "auto" as default.

The logic of the Multilingual parser could be:
- look for lang sections in the code.
- if there exists texts in the currently active language, print them.
- else, if there exists texts in the current parent language, print them.
- else, if there are English texts, print them
- else, print everything.

The advantage of this is that it would work everywhere without needing to put the site into multilingual mode or anything.
In reply to Martin Dougiamas

Re: Multilingual contents

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
In fact, Robert, if you can write this parser function I'll happily do the rest.
In reply to Martin Dougiamas

Re: Multilingual contents

by Les Kopari -

Here's more:

Dynamic XML conversion using the SAX parser and a stack:

http://www.phpbuilder.com/columns/scheffler20030325.php3

In reply to Les Kopari

Re: Multilingual contents

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
Very much overkill, I think ... bit like building a bulldozer to move a brick. smile
In reply to Martin Dougiamas

Re: Multilingual contents

by Robert Hetzel -
Martin

Thanks for the tips. I'd like to do something which will fit "smoothely" into the existing work.

One question remains: Would your method also work for titles of all kind, like course titles, resource titles, news titles etc. It would tidy up out site if we could do that ...

Thanks for your always fast response and support.
In reply to Robert Hetzel

Re: Multilingual contents

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
No, it wouldn't work on titles or forum subjects and other things like that.

That would require major changes to many pages .... I think it might also slow down Moodle quite a bit ... so a site-wide switch to enable it would be necessary. Implementing it should be a little easier when we move to templates so perhaps this could wait until then.
In reply to Martin Dougiamas

Re: Multilingual contents

by Arcadi Santamaria -
This is an important aspect.
We also have courses in catalan, spanish and english and some of the courses use material in different languages. It would be nice to have the information in the main page selected according the selected language. The mechanism used for the docs is nice, the information is not in the database but in files, so using the lang one can select information according to the languages. It seems this cannot work for the main page, categories of courses, and the material for the different courses. However, since the information in the main page is a global information for the site (like the docs or help) perhaps it can be cast in this form. As long as I understand the mechanism for switching language in the docs consists in putting a directory in the lang/es directory (for instance) with the name docs and with the docs in spanish. One can imagine in the same way a subdirectory mainpage in lang/es with
the relevant translated information...
Of course this cannot work for the material in the courses.... Also it seems that in the present version the main page is just like a course in category 0, thus since there is no option for the
language of the courses (then this weird question about your name for professor, or student when you register a course) one cannot change the language of the main page...

One obvious solution for all these problems is to
have several installations of moodle, one for each of the main languages... but it looks like that, with all the nice multilingual infrastructure of moodle, there must be a better solution.
In reply to Arcadi Santamaria

Re: Multilingual contents

by Ger Tielemans -

If you can program: Why not do it the simple way:

1. make for every language parallel entries in the flat MySQLdatabase:

2. put content boxes side by side on the screen (do two languages parallel)

3. user can choose the language interface for each row of boxes

4. You fill the boxes for one language,

End then:

5a  use google for translating and make then corrections

5b OR ask others to create the translations (others?? ...students!)

In reply to Arcadi Santamaria

Re: Multilingual contents

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
The solution I outlined above will be a good one for all resources, forum posts, journals, assignments, section introductions, etc ... it just needs that parsing function.
In reply to Martin Dougiamas

Re: Multilingual contents

by Ger Tielemans -

Yes, I agree, I only suggest not to try to build a languange parser, but instead of that to do during VIEW:

  • IF the language setting is Spanish THEN show the Spanish contentbox
  • DEFAULT: show the English box

And during EDITING:

  • IF the settings is multilingual THEN show the choosen languageboxes site by site
  • fill the English box and do the translation by hand (or make student exercise of it: interfcae should allow that..)

If people want to play with language parsers: a very limited parser for interactive fiction stories (IF: you are standing in a room etc...) can be found on the website from Nelson (including translations of the parser function in other languages: combination with Titanic-example would be great!.)

http://www.inform-fiction.org/

Maybe someone can change it in a educational modul for playing with language?

In reply to Martin Dougiamas

Re: Multilingual contents

by Gaëtan Frenoy -

Hello,

As suggested, I made a quick patch of "lib/weblib.php" to handle this kind of syntax.
Pretty easy but it is not enough to have a fully multilingual website.  Anyway, I attached the patched files to this text.

It is certainly bullet-proof, just a proof-of-concept so far.

Feedbacks are warmly welcome.

Thanks.

Average of ratings:Useful (1)
In reply to Gaëtan Frenoy

Re: Multilingual contents

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
Excellent start, thanks Gaëtan!

Since the earlier posts we now have a text filter system, and the best way to implement this is as a filter rather than hardcoding it in weblib.php. The advantage of this method is that it is modular and so multilang text can be disabled unless needed. When enabled it will automatically be used EVERYWHERE in moodle.

All you need to do is make a folder such as moodle/filter/multilang that contains a single file that contains a single function (see cvs:/moodle/filter/censor/censor.php for an example). The function accepts a text and the courseid. The filter can be enabled by adding a line to config.php.

I'm a bit short of time right now otherwise I'd do it myself, but if you're willing to re-work your code in this form please post it here! smile
In reply to Martin Dougiamas

Re: Multilingual contents

by Gaëtan Frenoy -

Good morning,

Filters look indeed a better way to go.  I re-arranged the code to implement multilingual patch as a filter (code is attached to this message).

However, I needed to change so other "core" files since all displayed strings are not yet using that "filter_text" extension (the site summary on the right of the main page, as an example).

Now, I am facing the following problems/questions:
 - a lot of "filter_text" call are missing.
 - How to display specific resource for each language?
 - XML syntax does not help readiness so it would be great to implement a UI that would read/write <lang> tags, display a combobox with available languages and only display the string in the selected language.
 - What if the XML is not valid (user input error?)

I will continue this way, let me know if you have any remark/suggestion.

Thanks.

Average of ratings:Useful (1)
In reply to Gaëtan Frenoy

Re: Multilingual contents

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
Fantastic, Gaëtan! Very nicely done! approve

I've checked this in with one small change (an initial scan for "<lang" to allow a quick exit if possible).  If you want to maintain your filter, please email me your Sourceforge username so I can give you CVS access.

I'll work on adding filter_text calls in the places they are missing.  Yes, a mod for the HTML editor would be beautiful one day (let's ask Janne!  wink).  Invalid XML, hmm.. a problem for another day.  smile

I'd love to show this off on the front page - can people start mailing me translations for the site info box in different languages? big grin
In reply to Martin Dougiamas

Re: Multilingual contents

by koen roggemans -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Translators

Mailed you this one a few days ago, maybe lost making his tour around the globe glimlach. Anyway, here it can be checked by other dutch-speeking community members.

Martin, I suggest you move your question to the language-forum.

In reply to koen roggemans

Re: Multilingual contents

by Hans de Zwart -
Hey Koen,

I made some small changes to the text you wrote (and lost all the HTML in the process!). The changes are in italics. I hope you can use it:

Moodle is een elektronische leeromgeving (ELO) - een softwarepakket, ontwikkeld om leraren te helpen bij het maken van goede online cursussen. Leeromgevingen als deze worden ook wel virtuele leeromgevingen genoemd. Eén van de belangrijkste voordelen van Moodle in vergelijking met andere systemen is de sterke band met de pedagogie van het Sociaal Constructivisme.

Moodle is Open Source software, wat betekent dat je het mag downloaden, wijzigen en zelfs distribueren (onder de voorwaarden van de GNU General Public License). Moodle draait zonder aanpassingen op Unix, Linux, Windows, Mac OS X, Netware en elk ander besturingssysteem dat PHP ondersteund, evenals bij de meeste webhostingbedrijven. De gegevens worden opgeslagen in één database: MySQL en PostgreSQL worden het beste ondersteund, maar het kan ook gebruikt worden met Oracle, Access, Interbase, ODBC en anderen.

Moodle is in 34 talen vertaald, waaronder Arabisch, Catalaans, Chinees (vereenvoudigd en traditioneel), Tsjechisch, Deens, Duits, Engels (VK en VS-versies), Fins, Frans (Franse en Canadadese versie), Grieks, Hongaars, Indonesisch, Italiaans, Japans, Nederlands, Noors, Pools, Portugees (Portugese en Brasiliaanse versie), Roemeens, Russisch, Slovaaks, Spaans (Spanje, Mexico, Argentinië en Caribische versies), Zweeds, Thais en Turks.

Je kunt meer te weten komen over Moodle via de lijst met mogelijkheden, je kunt een democursus bekijken op deze site, of kijken naar het groeiende aantal Moodlesites wereldwijd. Als je andere Moodlegebruikers wilt ontmoeten, ben je welkom in de cursus Moodle gebruiken.