Dotclear 2.24
Loading...
Searching...
No Matches
l10n Class Reference

Localization tools. More...

Static Public Attributes

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

Static Protected Attributes

Languages properties
static $languages_definitions = []
 
static $languages_name
 
static $languages_textdirection
 
static $languages_pluralsnumber
 
static $languages_pluralexpression
 

Current language properties

static $language_code
 
static $language_name
 
static $language_textdirection
 
static $language_pluralsnumber
 
static $language_pluralexpression
 
static $language_pluralfunction
 
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)
 

Gettext PO methods

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

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 getLanguagesDefinitions (int $type, string $default='')
 

Detailed Description

Localization tools.

Localization utilities

Member Function Documentation

◆ bootstrap()

static bootstrap ( )
static

Referenced by Clearbricks\__construct().

◆ init()

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

References $code, $files, $locales, and lang().

◆ lang()

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

References $code, $language_code, createPluralFunction(), getLanguageName(), getLanguagePluralExpression(), getLanguagePluralsNumber(), and getLanguageTextDirection().

Referenced by adminAuth\init(), init(), dcAdminHelper\loadLocales(), and testChangeNonExistingLangShouldUseDefaultOne().

◆ trans()

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

References index().

◆ index()

static index ( int  $count)
static

Retrieve plural index from input number

Parameters
integer$countNumber to take account
Returns
integer Index of plural form

Referenced by trans().

◆ set()

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

References $locales.

Referenced by adminAuth\init(), adminConfigThemeCustomCSS\init(), adminConfigThemeDuctile\init(), dcAdminHelper\loadLocales(), and dcModules\loadModuleL10N().

◆ getFilePath()

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 dcAdmin\init(), dcModules\loadModuleL10Nresources(), and testGetFilePath().

◆ getPoFile()

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|false

Referenced by generatePhpFileFromPo().

◆ generatePhpFileFromPo()

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 $locales, and getPoFile().

◆ parsePoFile()

static parsePoFile ( string  $file)
static

Parse Po File

Return an array of po headers and translations from a po file

Parameters
string$fileFile path
Returns
array|false Parsed file

◆ cleanPoLine()

static cleanPoLine ( string  $type,
  $_ 
)
staticprotected

◆ cleanPoString()

static cleanPoString (   $_)
staticprotected

◆ parsePluralExpression()

static parsePluralExpression ( string  $expression)
static

Extract nplurals and plural from po expression

Parameters
string$expressionPlural form as of gettext Plural-form param
Returns
array Number of plurals and cleaned plural expression

Referenced by testParsePluralExpression().

◆ createPluralFunction()

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

Referenced by lang().

◆ cleanPluralExpression()

static cleanPluralExpression ( string  $_)
staticprotected

◆ isCode()

static isCode ( string  $code)
static

Check if a language code exists

Parameters
string$codeLanguage code
Returns
bool True if code exists

References $code.

Referenced by testCodeLang().

◆ getCode()

static getCode ( string  $code)
static

Get a language code according to a language name

Parameters
string$codeLanguage name
Returns
string Language code

References $code.

Referenced by testgetCode().

◆ getISOcodes()

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

Referenced by dcDefaultPostActions\doChangePostLang(), dcThemeEditor\findLocales(), dcAdminCombos\getAdminLangsCombo(), dcAdminCombos\getLangsCombo(), defaultWidgets\langs(), and testGetISOcodes().

◆ getLanguageName()

static getLanguageName ( string  $code)
static

Get a language name according to a lang code

Parameters
string$codeLanguage code
Returns
string Language name

References $code.

Referenced by dcDefaultPostActions\doChangePostLang(), lang(), testgetCode(), and testgetLanguageName().

◆ getLanguagesName()

static getLanguagesName ( )
static

Get languages names

Returns
array List of languages names by languages codes

◆ getLanguageTextDirection()

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)

References $code.

Referenced by dcLegacyEditorBehaviors\jsToolBar(), lang(), dcPage\open(), dcPage\openPopup(), and testGetTextDirection().

◆ getLanguagesTextDirection()

static getLanguagesTextDirection ( )
static

Get languages text directions

Returns
array List of text directions by languages codes

◆ getLanguagePluralsNumber()

static getLanguagePluralsNumber ( string  $code)
static

Get a number of plurals according to a language code

Parameters
string$codeLanguage code
Returns
int Number of plurals

References $code.

Referenced by lang(), and testPluralForLanguageWithoutPluralForms().

◆ getLanguagesPluralsNumber()

static getLanguagesPluralsNumber ( )
static

Get languages numbers of plurals

Returns
array List of numbers of plurals by languages codes

◆ getLanguagePluralExpression()

static getLanguagePluralExpression ( string  $code)
static

Get a plural expression according to a language code

Parameters
string$codeLanguage code
Returns
string Plural expression

References $code.

Referenced by lang(), and testPluralForLanguageWithoutPluralForms().

◆ getLanguagesPluralExpression()

static getLanguagesPluralExpression ( )
static

Get languages plural expressions

Returns
array List of plural expressions by languages codes

◆ getLanguagesDefinitions()

static getLanguagesDefinitions ( int  $type,
string  $default = '' 
)
staticprotected

Get languages definitions of a given type

The list follows ISO 639.1 norm with additionnal IETF codes as pt-br

Countries codes and names from:

Text direction from:

Plural-forms taken from:

$languages_definitions types look like this: 0 = code ISO 639.1 (2 digit) + IETF add 1 = code ISO 639.2 (english 3 digit) 2 = English name 3 = natal name 4 = text direction (ltr or rtl) 5 = number of plurals (1 means no plural form) 6 = plural expression (as of gettext .po plural form)

null values represent missing values

Parameters
integer$typeType of definition
string$defaultDefault value if definition is empty
Returns
array List of requested definition by languages codes

Field Documentation

◆ $files

$files = []
static

Referenced by init().

◆ $locales

$locales = []
static

Referenced by generatePhpFileFromPo(), init(), and set().

◆ $languages_definitions

$languages_definitions = []
staticprotected

◆ $languages_name

$languages_name
staticprotected

◆ $languages_textdirection

$languages_textdirection
staticprotected

◆ $languages_pluralsnumber

$languages_pluralsnumber
staticprotected

◆ $languages_pluralexpression

$languages_pluralexpression
staticprotected

◆ $language_code

$language_code
staticprotected

Referenced by lang().

◆ $language_name

$language_name
staticprotected

◆ $language_textdirection

$language_textdirection
staticprotected

◆ $language_pluralsnumber

$language_pluralsnumber
staticprotected

◆ $language_pluralexpression

$language_pluralexpression
staticprotected

◆ $language_pluralfunction

$language_pluralfunction
staticprotected

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