Translating the Sloodle module

From SLIS Second Life Wiki

Jump to: navigation, search

Contents

Introduction

According to the Moodle coding guidelines, the Sloodle module should be developed to allow different language translations to be included easily. For text that appears in the usual Sloodle web-pages, this means keeping all of the module text (e.g. headings, instructions, forms etc.) in separate files (called localization files), with one file for each language. Each block of text, such as a sentence or a paragraph, will be identified by a short English name, and all of our source code will reference those text blocks. For the module documentation (help files which popup when you click a help button), this means storing the help files in a special way.

You may want to read the Moodle translation documentation for a deeper background.


But Why?

It is certainly a lot easier for us programmers just to throw text around wherever we feel like doing it. However, we have already received requests for Sloodle in other languages, and translation is *much* easier if we use Moodle's own localization formats. In fact, it's so easy, we can get translators to do it without any significant programming ability whatsoever.


Where are the language files?

In the Sloodle folder, you will see a "lang" folder. Inside that, there is a sub-folder for each language, e.g. "en_utf8" for English.

Within each of those folders is a localization file called "sloodle.php" which contains all the localization strings (it is crucial that each language file is named and stored this way, otherwise Moodle will not find it). There is also a "help" folder, with another "sloodle" folder inside it. All of the help files are stored in there, as small HTML files.

For example, for Sloodle.org, the English localization file for Sloodle would be stored here:

http://www.sloodle.org/mod/sloodle/lang/en_utf8/sloodle.php

An English help file about "object authorization" would be stored here:

http://www.sloodle.org/mod/sloodle/lang/en_utf8/help/sloodle/object_authorization.html


How does it affect me?

If you are contributing code to Sloodle, and your code produces text output which the user may see (e.g. instructions, error messages, information etc.), then you need to use localization strings. This is not too hard, but requires you to change the way you add strings into your code. If you need use popup help files, then you will have to add the files to the correct folder, and use the Moodle helpbutton() function to create a link to it.

Localization Strings

Creating strings

Instead of simply adding the strings directly into your code, plan out what strings you need, and give each one a concise English name (you may categorise several together if you wish). Please follow the Localization String Guidelines when doing this... they are simple to use!


Adding strings to the language file

Before you can use the strings in your code, you must add them to your local language file(s). Open the English language file (see above for how to find that) and you will see the format. Each line defines a single string, in this way:

$string['stringname'] = 'string text';

As you can see, the file is simply populating an associative array, which associates string names with their content. Simply copy the format, and add in your own string names and content, then save the file, and Moodle will be able to find them. Please try to keep the file neat and tidy, by putting each string in alphabetical order, according to its name.


Using strings in your code

Moodle will take care of fetching the correct set of strings according to the current language. All you need to do is request each string (by name) at the appropriate points in your code. There are two ways of doing this:

get_string( "stringname", "modulename" );
print_string( "stringname", "modulename" );

The first function returns the string as an item of data, while the second outputs it directly to the HTML body. (Note that in our case, the module name is always "sloodle".)

And that's it! You will quickly become familiar with the process.


Help Files

Adding the file

Let's say you want to create an English help file about the name "Sloodle" and what it means. You would create a file called "sloodle_name.html", and place it in "sloodle/lang/en_utf8/help/sloodle". You do not add any header or body information to file. Just creating a heading, such as:

  • <h3>Sloodle name</h3>

Then add the body information, e.g.:

  • <p>Sloodle is a combination of "Second Life" and "Moodle".</p>


Adding the help button

The usual appearance of a popup helpfile in Moodle in a yellow circle with a question mark. You can use Moodle to generate this for you, using the helpbutton() function, like this:

  • helpbutton('sloodle_name', , 'sloodle', true, false);

If you change the last "false" to a "true", then the second argument becomes a title string displayed beside the button. However, you will probably need to create a separate localization string for this, so that it gets translated appropriately.


Translation

All you need to do is repeat the "Adding the file" process for each language, putting the appropriate translation of the file into each place. Moodle will automatically detect the user's preferred language, and display the help file (if available). It will revert to the site default (usually English) if the user's preferred language is not available.


Affected Files

Source Code

Any source code file (typically *.php) which outputs any text to the browser is likely to be affected. This even includes labels on buttons, and "alt" or "title" attributes of images and links. Variables, commands, and error/debug messages will typically still be in English, although these can be translated as well if needed.


Current Language Files

  • sloodle.php
  • help/sloodle/object_authorization.html
  • help/sloodle/object_distributor.html
  • help/sloodle/prim_password.html
  • help/sloodle/user_authentication.html
  • help/sloodle/version_numbers.html


Requested Languages

These are the languages we know there is a need for:

  • Spanish (es_utf8)


Get Involved!

Are you able to translate the Sloodle module into the other languages? If so, we want to hear from you! Let us know of your interest on the Sloodle forums, and see if there's a need for the language(s) you can translate.

Once you have found a language you can translate to, obtain the latest Sloodle source code. If needed, created the folders and files for your translation (best to copy them from the English files), and begin editing them to use your language.

When translating, it would be best if everybody translates from the English version, to help prevent mistranslations! We are hoping to have a translation module setup on Sloodle.org, which will make the process even simpler. An announcement will be made on the Sloodle News forums when that is available.


This page is part of the Sloodle documentation
SloodleDocs Home | User Documentation | Administrator Documentation | Developer Documentation | Sloodle Wiki Home