Dotclear  2.29
 All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
L10n Class Reference

Static Public Member Functions

static bootstrap ()
 
static init (?string $code= 'en')
 
static lang (?string $code=null)
 
static trans (string $singular,?string $plural=null,?int $count=null)
 
static index (int $count)
 
static set (string $file)
 
static getFilePath (string $dir, string $file, string $lang)
 
Languages definitions methods
static isCode (string $code)
 
static getCode (string $code)
 
static getISOcodes (bool $flip=false, bool $name_with_code=false)
 
static getLanguageName (string $code)
 
static getLanguagesName ()
 
static getLanguageTextDirection (string $code)
 
static getLanguagesTextDirection ()
 
static getLanguagePluralsNumber (string $code)
 
static getLanguagesPluralsNumber ()
 
static getLanguagePluralExpression (string $code)
 
static getLanguagesPluralExpression ()
 

Static Public Attributes

static array $files = []
 
static array $locales = []
 

Static Protected Attributes

Languages properties
static array $languages_definitions = []
 
static array $languages_name
 
static array $languages_textdirection
 
static array $languages_pluralsnumber
 
static array $languages_pluralexpression
 
Current language properties
static string $language_code = null
 
static string $language_name
 
static string $language_textdirection
 
static int $language_pluralsnumber
 
static string $language_pluralexpression
 
static $language_pluralfunction
 

Gettext PO methods

static getPoFile (string $file)
 
static generatePhpFileFromPo (string $file, string $license_block= '')
 
static parsePluralExpression (string $expression)
 
static createPluralFunction (int $nplurals, string $expression)
 
static cleanPoLine (string $type, $_)
 
static cleanPoString ($_)
 
static cleanPluralExpression (string $_)
 

Detailed Description

Localization utilities

Member Function Documentation

static bootstrap ( )
static
static init ( ?string  $code = 'en')
static

L10N initialization

Create global arrays for L10N stuff. Should be called before any work with other methods. For plural-forms, __l10n values can now be array.

Parameters
string | null$codeLanguage code to work with

Referenced by Wizard\init(), Install\init(), and Task\run().

Here is the caller graph for this function:

static lang ( ?string  $code = null)
static

Set a language to work on or return current working language code

This set up language properties to manage plurals form. Change of language code not reset global array of L10N stuff.

Parameters
string$codeLanguage code
Returns
string Current language code

Referenced by Lang\setLang().

Here is the caller graph for this function:

static trans ( string  $singular,
?string  $plural = null,
?int  $count = null 
)
static

Translate a string

Returns a translated string of $singular or $plural according to a number if it is set. If translation is not found, returns the string.

Parameters
string$singularSingular form of the string
string$pluralPlural form of the string (optionnal)
integer$countContext number for plural form (optionnal)
Returns
string Translated string
static index ( int  $count)
static

Retrieve plural index from input number

Parameters
integer$countNumber to take account
Returns
integer Index of plural form
static set ( string  $file)
static

Add a file

Adds a l10n file in translation strings. $file should be given without extension. This method will look for $file.lang.php and $file.po (in this order) and retrieve the first one found. We don't care about language (and plurals forms) of the file.

Parameters
string$fileFilename (without extension)
Returns
boolean True on success

Referenced by Wizard\init(), Install\init(), MyModule\l10n(), Helper\loadLocales(), Utility\loadLocales(), Modules\loadModuleL10N(), and Utility\process().

Here is the caller graph for this function:

static getFilePath ( string  $dir,
string  $file,
string  $lang 
)
static

L10N file

Returns a file path for a file, a directory and a language. If $dir/$lang/$file is not found, it will check if $dir/en/$file exists and returns the result. Returns false if no file were found.

Parameters
string$dirDirectory
string$fileFile
string$langLanguage
Returns
string|false File path or false

Referenced by Modules\loadModuleL10Nresources(), Digests\process(), and Utility\process().

Here is the caller graph for this function:

static getPoFile ( string  $file)
static

Load gettext file

Returns an array of strings found in a given gettext (.po) file

Parameters
string$fileFilename
Returns
array<mixed>|false
static generatePhpFileFromPo ( string  $file,
string  $license_block = '' 
)
static

Generates a PHP file from a po file

Return a boolean depending on success or failure

Parameters
string$fileFile
string$license_blockOptional license block to add at the beginning
Returns
bool true on success

References L10n\$locales.

static cleanPoLine ( string  $type,
  $_ 
)
staticprotected

Clean line from .po

Parameters
string$typeThe type
mixed$_the line
Returns
false|array<string>
static cleanPoString (   $_)
staticprotected

Clean string from .po

Parameters
mixed$_The string
Returns
string
static parsePluralExpression ( string  $expression)
static

Extract nplurals and plural from po expression

Parameters
string$expressionPlural form as of gettext Plural-form param
Returns
array<int, int|string> Number of plurals and cleaned plural expression
static createPluralFunction ( int  $nplurals,
string  $expression 
)
static

Create function to find plural msgstr index from gettext expression

Parameters
integer$npluralsPlurals number
string$expressionPlural expression
Returns
callable Function to extract right plural index
static cleanPluralExpression ( string  $_)
staticprotected
static isCode ( string  $code)
static

Check if a language code exists

Parameters
string$codeLanguage code
Returns
bool True if code exists
static getCode ( string  $code)
static

Get a language code according to a language name

Parameters
string$codeLanguage name
Returns
string Language code
static getISOcodes ( bool  $flip = false,
bool  $name_with_code = false 
)
static

ISO Codes

Parameters
bool$flipFlip resulting array
bool$name_with_codePrefix (code) to names
Returns
array<string, string>

Referenced by ActionsPostsDefault\doChangePostLang(), Combos\getAdminLangsCombo(), and Widgets\langs().

Here is the caller graph for this function:

static getLanguageName ( string  $code)
static

Get a language name according to a lang code

Parameters
string$codeLanguage code
Returns
string Language name

Referenced by ActionsPostsDefault\doChangePostLang().

Here is the caller graph for this function:

static getLanguagesName ( )
static

Get languages names

Returns
array<string, string> List of languages names by languages codes
static getLanguageTextDirection ( string  $code)
static

Get a text direction according to a language code

Parameters
string$codeLanguage code
Returns
string Text direction (rtl or ltr)

Referenced by Page\openPopup().

Here is the caller graph for this function:

static getLanguagesTextDirection ( )
static

Get languages text directions

Returns
array<string, string> List of text directions by languages codes
static getLanguagePluralsNumber ( string  $code)
static

Get a number of plurals according to a language code

Parameters
string$codeLanguage code
Returns
int Number of plurals
static getLanguagesPluralsNumber ( )
static

Get languages numbers of plurals

Returns
array<string, int|null> List of numbers of plurals by languages codes
static getLanguagePluralExpression ( string  $code)
static

Get a plural expression according to a language code

Parameters
string$codeLanguage code
Returns
string Plural expression
static getLanguagesPluralExpression ( )
static

Get languages plural expressions

Returns
array<string, string|null> List of plural expressions by languages codes

Field Documentation

array $files = []
static
array $locales = []
static
array $languages_definitions = []
staticprotected
array $languages_name
staticprotected
array $languages_textdirection
staticprotected
array $languages_pluralsnumber
staticprotected
array $languages_pluralexpression
staticprotected
string $language_code = null
staticprotected
string $language_name
staticprotected
string $language_textdirection
staticprotected
int $language_pluralsnumber
staticprotected
string $language_pluralexpression
staticprotected
$language_pluralfunction
staticprotected

The documentation for this class was generated from the following file: