Benutzer:Elkuku/Proyektz/g11n

Aus Joomla! Dokumentation
Wechseln zu: Navigation, Suche

Inhaltsverzeichnis

[Bearbeiten] History

The g11n project is the daughter of the JALHoO project. You should read about it if you are interested in why it was created in the first place.

[Bearbeiten] Download

The latest release can be found on joomlacode

If you feel brave, try the SVN version

[Bearbeiten] Installation

  • Joomla 1.6 and higher
  1. Install the library with the Joomla! installer.

OR

  1. You may follow the same steps as for J! 1.5
  • Joomla 1.5

There is actually no installation required. It is enough if the library is in it's proper place.

  1. Create the folder Folder blue.png libraries/g11n
    1. If you did a SVN checkout, copy the contents of the checkout into the directory.
    2. If you downloaded the package, unpack it and copy the contents to the directory.

[Bearbeiten] Usage

[Bearbeiten] Include the library

First of all you have to include the library. As this will become an essential part of your extension, it should be required like this:

try
{
    if( ! jimport('g11n.language'))
    {
        throw new Exception('The g11n language library is required to run this extension');
    }
 
    //-- Load the language
    //-- see below...
}
catch((Exception $e)
{
    JError::raiseWarning(0, $e->getMessage());
 
    return;
}//try

[Bearbeiten] Load your language files

Syntax:

static loadLanguage($extension = '', $scope = '', $inputType = 'po', $storageType = 'file_php')

The command for loading your language file depends on the extension type.

If you call the function without any parameters the language files for the actual component in execution are loaded.

    //-- Load the language
    g11n::loadLanguage();

If your extension is any other then a component (module, template, etc), you have to specify the extension.

E.g. for a module:

    //-- Load the language
    g11n::loadLanguage('mod_mymodule');

If your extension uses a language file format other than the default po, write:

E.g. for template with ini files:

    //-- Load the language
    g11n::loadLanguage('tpl_mytemplate', 'site', 'ini');

[Bearbeiten] Language file location

To make the difference, g11n stores the language files in a folder called Folder blue.png g11n. So for example the language files for the german language of com_mycomponent are located in:

  • Folder blue.png components
    • Folder blue.png com_mycomponent
      • Folder blue.png g11n
        • Folder blue.png de-DE
          • File txt.png de-DE.com_mycomponent.EXT

[Bearbeiten] Available functions

[Bearbeiten] jgettext()

To show, that is is derived from gettext() the function is called jgettext(). The syntax is exactly the same for PHP and JavScript:

string jgettext(string $string);

Example PHP

echo jgettext('Hello world !');
echo sprintf(jgettext('Hello %s'), 'world');

Example JavaScript

alert(jgettext('Hello world !'));

[Bearbeiten] jngettext()

This is the pluralization function derived from ngettext(). The first parameter is the singular form, the second the plural and the third specifies the amount of items

string jngettext(string $singular, string $plural, integer $count);

Example PHP

echo sprintf(jngettext('%d item deleted', '%d items deleted', $count), $count);

Example JavaScript

alert(phpjs.sprintf(jngettext('%d item deleted', '%d items deleted', $count), $count);

If you wonder.. the function phpjs.sprintf() comes from the phpjs project. It is used, among other functons, in the g11n library. So it will also be available to your scripts, as a positive side effect ;)

Meine Werkzeuge
Namensräume
Varianten
Aktionen
Navigation
Sonstiges
Team Navigation
Werkzeuge