Localization.php
1 <?php
2 /**
3  * wCMF - wemove Content Management Framework
4  * Copyright (C) 2005-2020 wemove digital solutions GmbH
5  *
6  * Licensed under the terms of the MIT License.
7  *
8  * See the LICENSE file distributed with this work for
9  * additional information.
10  */
11 namespace wcmf\lib\i18n;
12 
15 
16 /**
17  * Localization defines the interface for storing localized entity instances
18  * and retrieving them back.
19  *
20  * Localization is done against a default language. This means
21  * that all entity data in the store is supposed to use the default language
22  * except those data stored as translations. Translations maybe done in
23  * all supported languages.
24  *
25  * Language names may conform to ISO 639 language codes, but this is not mandatory.
26  * One of the supported languages must be equal to the value of default language.
27  *
28  * Generally only values are translatable.
29  *
30  * @author ingo herwig <ingo@wemove.com>
31  */
32 interface Localization {
33 
34  /**
35  * Get the default language that is used in the store.
36  * @return The default language value (e.g. en)
37  */
38  public function getDefaultLanguage();
39 
40  /**
41  * Get all supported languages.
42  * @return An associative array with the language codes as keys and the names as values.
43  */
44  public function getSupportedLanguages();
45 
46  /**
47  * Load a single translated object. The object is always loaded with BuildDepth::SINGLE.
48  * @param $oid The object id of the object to load the translation for.
49  * @param $lang The language of the translation to load.
50  * @param $useDefaults Boolean whether to use the default language values
51  * for untranslated/empty values or not. Optional, default is true
52  * @return PersistentObject
53  */
54  public function loadTranslatedObject(ObjectId $oid, $lang, $useDefaults=true);
55 
56  /**
57  * Load a translation of an entity for a specific language.
58  * @param $object The PersistentObject instance to load the translation into. The object
59  * is supposed to have it's values in the default language.
60  * @param $lang The language of the translation to load.
61  * @param $useDefaults Boolean whether to use the default language values
62  * for untranslated/empty values or not. Optional, default is true.
63  * @param $recursive Boolean whether to load translations for children too or not.
64  * Optional, default is true. For recursive use, the object must have a getChildren method.
65  * @return PersistentObject
66  */
67  public function loadTranslation(PersistentObject $object, $lang, $useDefaults=true, $recursive=true);
68 
69  /**
70  * Save a translation of an entity for a specific language. Only the
71  * values that have a non-empty value are considered as translations and stored.
72  * @param $object An instance of the entity type that holds the translations as values.
73  * @param $lang The language of the translation.
74  * @param $recursive Boolean whether to save translations for children too or not.
75  * Optional, default is true. For recursive use, the object must have a getChildren method.
76  */
77  public function saveTranslation(PersistentObject $object, $lang, $recursive=true);
78 
79  /**
80  * Remove translations for a given entity.
81  * @param $oid The id of the object
82  * @param $lang The language of the translation to remove. If null, all translations
83  * will be deleted (default: _null_)
84  */
85  public function deleteTranslation(ObjectId $oid, $lang=null);
86 
87  /**
88  * Delete all translations for a given language.
89  * @param $lang The language of the translations to remove
90  */
91  public function deleteLanguage($lang);
92 }
93 ?>
I18N related interfaces and classes.
Definition: namespaces.php:16
loadTranslation(PersistentObject $object, $lang, $useDefaults=true, $recursive=true)
Load a translation of an entity for a specific language.
deleteTranslation(ObjectId $oid, $lang=null)
Remove translations for a given entity.
getSupportedLanguages()
Get all supported languages.
ObjectId is the unique identifier of an object.
Definition: ObjectId.php:28
loadTranslatedObject(ObjectId $oid, $lang, $useDefaults=true)
Load a single translated object.
deleteLanguage($lang)
Delete all translations for a given language.
saveTranslation(PersistentObject $object, $lang, $recursive=true)
Save a translation of an entity for a specific language.
PersistentObject defines the interface of all persistent objects.
getDefaultLanguage()
Get the default language that is used in the store.
Localization defines the interface for storing localized entity instances and retrieving them back.