PHP Class SimpleSAML\Locale\Translate

Show file Open project: simplesamlphp/simplesamlphp Class Usage Examples

Public Methods

Method Description
__construct ( SimpleSAML_Configuration $configuration, string | null $defaultDictionary = null ) Constructor
getAttributeTranslation ( string $name ) : string Translate the name of an attribute.
getLanguage ( ) : Language Return the internal language object used by this translator.
getPreferredTranslation ( array $translations ) : string Retrieve the preferred translation of a given text.
getTag ( string $tag ) : array This method retrieves a tag as an array with language => string mappings.
includeInlineTranslation ( string $tag, array | string $translation ) Include a translation inline instead of putting translations in dictionaries. This function is recommended to be used ONLU from variable data, or when the translation is already provided by an external source, as a database or in metadata.
includeLanguageFile ( string $file, SimpleSAML_Configuration | null $otherConfig = null ) Include a language file from the dictionaries directory.
noop ( string $tag ) : string Mark a string for translation without translating it.
t ( string | array $tag, array $replacements = [], boolean $fallbackdefault = true, $oldreplacements = [], $striptags = false ) : string Translate a tag into the current language, with a fallback to english.
translatePluralGettext ( $original, $plural, $value )
translateSingularGettext ( $original )

Private Methods

Method Description
getDictionary ( string $name ) : array This method retrieves a dictionary with the name given.
getStringNotTranslated ( string $tag, boolean $fallbacktag ) : string Return the string that should be used when no translation was found.
readDictionaryFile ( string $filename ) : array Read a dictionary file.
readDictionaryJSON ( string $filename ) : array Read a dictionary file in JSON format.
readDictionaryPHP ( string $filename ) : array Read a dictionary file in PHP format.

Method Details

__construct() public method

Constructor
public __construct ( SimpleSAML_Configuration $configuration, string | null $defaultDictionary = null )
$configuration SimpleSAML_Configuration Configuration object
$defaultDictionary string | null The default dictionary where tags will come from.

getAttributeTranslation() public method

Translate the name of an attribute.
public getAttributeTranslation ( string $name ) : string
$name string The attribute name.
return string The translated attribute name, or the original attribute name if no translation was found.

getLanguage() public method

Return the internal language object used by this translator.
public getLanguage ( ) : Language
return Language

getPreferredTranslation() public method

Retrieve the preferred translation of a given text.
public getPreferredTranslation ( array $translations ) : string
$translations array The translations, as an associative array with language => text mappings.
return string The preferred translation.

getTag() public method

This method retrieves a tag as an array with language => string mappings.
public getTag ( string $tag ) : array
$tag string The tag name. The tag name can also be on the form '{:}', to retrieve a tag from the specific dictionary.
return array An associative array with language => string mappings, or null if the tag wasn't found.

includeInlineTranslation() public method

Include a translation inline instead of putting translations in dictionaries. This function is recommended to be used ONLU from variable data, or when the translation is already provided by an external source, as a database or in metadata.
public includeInlineTranslation ( string $tag, array | string $translation )
$tag string The tag that has a translation
$translation array | string The translation array

includeLanguageFile() public method

Include a language file from the dictionaries directory.
public includeLanguageFile ( string $file, SimpleSAML_Configuration | null $otherConfig = null )
$file string File name of dictionary to include
$otherConfig SimpleSAML_Configuration | null Optionally provide a different configuration object than the one provided in the constructor to be used to find the directory of the dictionary. This allows to combine dictionaries inside the SimpleSAMLphp main code distribution together with external dictionaries. Defaults to null.

noop() public static method

Mark a string for translation without translating it.
public static noop ( string $tag ) : string
$tag string A tag name to mark for translation.
return string The tag, unchanged.

t() public method

This function is used to look up a translation tag in dictionaries, and return the translation into the current language. If no translation into the current language can be found, english will be tried, and if that fails, placeholder text will be returned. An array can be passed as the tag. In that case, the array will be assumed to be on the form (language => text), and will be used as the source of translations. This function can also do replacements into the translated tag. It will search the translated tag for the keys provided in $replacements, and replace any found occurrences with the value of the key.
Deprecation: Not used in twig, gettext
public t ( string | array $tag, array $replacements = [], boolean $fallbackdefault = true, $oldreplacements = [], $striptags = false ) : string
$tag string | array A tag name for the translation which should be looked up, or an array with (language => text) mappings. The array version will go away in 2.0
$replacements array An associative array of keys that should be replaced with values in the translated string.
$fallbackdefault boolean Default translation to use as a fallback if no valid translation was found.
return string The translated tag, or a placeholder value if the tag wasn't found.

translatePluralGettext() public static method

public static translatePluralGettext ( $original, $plural, $value )

translateSingularGettext() public static method

public static translateSingularGettext ( $original )