Detailed Description
Localization defines the interface for storing localized entity instances and retrieving them back.
Localization is done against a default language. This means that all entity data in the store is supposed to use the default language except those data stored as translations. Translations maybe done in all supported languages.
Language names may conform to ISO 639 language codes, but this is not mandatory. One of the supported languages must be equal to the value of default language.
Generally only values are translatable.
Definition at line 32 of file Localization.php.
Public Member Functions | |
getDefaultLanguage () | |
getSupportedLanguages () | |
loadTranslatedObject (ObjectId $oid, $lang, $useDefaults=true) | |
loadTranslation (PersistentObject $object, $lang, $useDefaults=true, $recursive=true) | |
saveTranslation (PersistentObject $object, $lang, $recursive=true) | |
deleteTranslation (ObjectId $oid, $lang=null) | |
deleteLanguage ($lang) | |
Member Function Documentation
◆ getDefaultLanguage()
getDefaultLanguage | ( | ) |
Get the default language that is used in the store.
- Returns
- The default language value (e.g. en)
Implemented in DefaultLocalization.
◆ getSupportedLanguages()
getSupportedLanguages | ( | ) |
Get all supported languages.
- Returns
- An associative array with the language codes as keys and the names as values.
Implemented in DefaultLocalization.
◆ loadTranslatedObject()
loadTranslatedObject | ( | ObjectId | $oid, |
$lang, | |||
$useDefaults = true |
|||
) |
Load a single translated object.
The object is always loaded with BuildDepth::SINGLE.
- Parameters
-
$oid The object id of the object to load the translation for. $lang The language of the translation to load. $useDefaults Boolean whether to use the default language values for untranslated/empty values or not. Optional, default is true
- Returns
- PersistentObject
Implemented in DefaultLocalization.
◆ loadTranslation()
loadTranslation | ( | PersistentObject | $object, |
$lang, | |||
$useDefaults = true , |
|||
$recursive = true |
|||
) |
Load a translation of an entity for a specific language.
- Parameters
-
$object The PersistentObject instance to load the translation into. The object is supposed to have it's values in the default language. $lang The language of the translation to load. $useDefaults Boolean whether to use the default language values for untranslated/empty values or not. Optional, default is true. $recursive Boolean whether to load translations for children too or not. Optional, default is true. For recursive use, the object must have a getChildren method.
- Returns
- PersistentObject
◆ saveTranslation()
saveTranslation | ( | PersistentObject | $object, |
$lang, | |||
$recursive = true |
|||
) |
Save a translation of an entity for a specific language.
Only the values that have a non-empty value are considered as translations and stored.
- Parameters
-
$object An instance of the entity type that holds the translations as values. $lang The language of the translation. $recursive Boolean whether to save translations for children too or not. Optional, default is true. For recursive use, the object must have a getChildren method.
Implemented in DefaultLocalization.
◆ deleteTranslation()
deleteTranslation | ( | ObjectId | $oid, |
$lang = null |
|||
) |
Remove translations for a given entity.
- Parameters
-
$oid The id of the object $lang The language of the translation to remove. If null, all translations will be deleted (default: null)
Implemented in DefaultLocalization.
◆ deleteLanguage()
deleteLanguage | ( | $lang | ) |
Delete all translations for a given language.
- Parameters
-
$lang The language of the translations to remove
Implemented in DefaultLocalization.