56.3. Internationalization

Webmin versions 0.75 and above provide module writers with functions for generating different text and messages, depending on the language selected by the user. Each module that wishes to use this feature should have a subdirectory called lang that contains a translation file for each supported language. Each line of a translation file defines a message in that language in the format message_code=Message in this language.

Table 56.1. Keys in the Hash Passed to the Usermin_update.pl Functions
userThe login name of the new or modified user
uidThe UNIX UID of the user
gidThe UNIX GID for the user's primary group
passThe user's password, encrypted with the crypt function
plainpassThe user's password in plain text. This is only available when the passmode key is equal to 3.
passmodeThis number depends on the choice made for the Password field in the create user or edit user form.

0 - No password is set for this user, typically meaning that no password is required to log in

1 - This user is not allowed to log in at all

2 - Only the encrypted password for this user is available

3 - A new or initial plain-text password is available in the plainpass key

4 - The user's password is unchanged. Only possible when useradmin_modify_user is called.

realThe user's real name
homeThe user's home directory
shellThe user's login shell

The default language for Webmin is English (code en), so every module should have at least a file called lang/en. If any other language is missing a message, the English one will be used instead. Check the file lang_list.txt for all the languages currently supported and their codes. To change the current language, go into the Webmin Configuration module and click on the Language icon.

When your module calls the init_config function, all the messages from the appropriate translation file will be read into the %text hash. Therefore, instead of generating hard-coded text like this:

print "Click here to start the server:<p>
";

your module should use the %text hash like so:

print $text{'startmsg'},"<p>
";

Messages from the appropriate file in the top-level lang directory are also included in %text. Several useful messages such as save, delete, and create are therefore available to every module.

In some cases, you may want to include some variable text in a message. Because the position of the variable may differ depending on the language used, message strings can include place markers like $1, $2, or $3. The text function should be used to replace these place markers with actual values like:

print &text('servercount', $count),"<p>
";

Your module's module.info file can also support multiple languages by adding a line like desc_code=module description for each language, where code is the language code. You can also have a separate config.info file for each language—called config.info.code—and separate help files for each language, such as intro.code.html. In all cases, if there is no translation for the user's chosen language then the default (English) will be used instead.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.19.26.186