3 namespace Drupal\Core\Language;
8 * Common interface for the language manager service.
10 interface LanguageManagerInterface {
13 * Returns whether or not the site has more than one language added.
16 * TRUE if more than one language is added, FALSE otherwise.
18 public function isMultilingual();
21 * Returns an array of the available language types.
24 * An array of language type machine names.
26 public function getLanguageTypes();
29 * Returns information about all defined language types.
32 * An associative array of language type information arrays keyed by
33 * language type machine name, in the format of
34 * hook_language_types_info(). In some implementing classes, this is based
35 * on information from hook_language_types_info() and
36 * hook_language_types_info_alter().
38 public function getDefinedLanguageTypesInfo();
41 * Returns the current language for the given type.
44 * (optional) The language type; e.g., the interface or the content
45 * language. Defaults to
46 * \Drupal\Core\Language\LanguageInterface::TYPE_INTERFACE.
48 * @return \Drupal\Core\Language\LanguageInterface
49 * The current language object for the given type of language.
51 public function getCurrentLanguage($type = LanguageInterface::TYPE_INTERFACE);
54 * Resets the given language type or all types if none specified.
56 * @param string|null $type
57 * (optional) The language type to reset as a string, e.g.,
58 * LanguageInterface::TYPE_INTERFACE, or NULL to reset all language types.
61 * @return \Drupal\Core\Language\LanguageManagerInterface
62 * The language manager that has been reset.
64 public function reset($type = NULL);
67 * Returns a language object representing the site's default language.
69 * @return \Drupal\Core\Language\LanguageInterface
72 public function getDefaultLanguage();
75 * Returns a list of languages set up on the site.
78 * (optional) Specifies the state of the languages that have to be returned.
79 * It can be: LanguageInterface::STATE_CONFIGURABLE,
80 * LanguageInterface::STATE_LOCKED, or LanguageInterface::STATE_ALL.
82 * @return \Drupal\Core\Language\LanguageInterface[]
83 * An associative array of languages, keyed by the language code.
85 public function getLanguages($flags = LanguageInterface::STATE_CONFIGURABLE);
88 * Returns a list of languages set up on the site in their native form.
90 * @return \Drupal\Core\Language\LanguageInterface[]
91 * An associative array of languages, keyed by the language code, ordered
92 * by weight ascending and name ascending.
94 public function getNativeLanguages();
97 * Returns a language object from the given language code.
99 * @param string $langcode
102 * @return \Drupal\core\Language\LanguageInterface|null
103 * A fully-populated language object or NULL.
105 public function getLanguage($langcode);
108 * Produced the printed name for a language for display.
110 * @param string $langcode
114 * The printed name of the language.
116 public function getLanguageName($langcode);
119 * Returns a list of the default locked languages.
122 * (optional) An integer value that is used as the start value for the
123 * weights of the locked languages.
125 * @return \Drupal\Core\Language\LanguageInterface[]
126 * An array of language objects.
128 public function getDefaultLockedLanguages($weight = 0);
131 * Checks whether a language is locked.
133 * @param string $langcode
137 * Returns whether the language is locked.
139 public function isLanguageLocked($langcode);
142 * Returns the language fallback candidates for a given context.
144 * @param array $context
145 * (optional) An associative array of data that can be useful to determine
146 * the fallback sequence. The following keys are used in core:
147 * - langcode: Language code of the desired language.
148 * - operation: The name of the operation indicating the context where
149 * language fallback is being applied. The following operations are
150 * defined in core, but more may be defined in contributed modules:
151 * - entity_view: Invoked when an entity is about to be displayed.
152 * The data key contains the loaded entity.
153 * - views_query: Invoked when a field based views query is performed.
154 * The data key contains a reference to the field object.
155 * - locale_lookup: Invoked when a string translation was not found.
156 * The data key contains the source string.
157 * - data: A data structure that makes sense in the provided
158 * context, see above.
161 * An array of language codes sorted by priority: first values should be
164 public function getFallbackCandidates(array $context = []);
167 * Returns the language switch links for the given language type.
169 * @param string $type
171 * @param \Drupal\Core\Url $url
172 * The URL the switch links will be relative to.
175 * A keyed array of links ready to be themed.
177 public function getLanguageSwitchLinks($type, Url $url);
180 * Sets the configuration override language.
182 * @param \Drupal\Core\Language\LanguageInterface $language
183 * The language to override configuration with.
187 public function setConfigOverrideLanguage(LanguageInterface $language = NULL);
190 * Gets the current configuration override language.
192 * @return \Drupal\Core\Language\LanguageInterface
193 * The current configuration override language.
195 public function getConfigOverrideLanguage();
198 * Some common languages with their English and native names.
200 * Language codes are defined by the W3C language tags document for
201 * interoperability. Language codes typically have a language and, optionally,
202 * a script or regional variant name. See:
203 * http://www.w3.org/International/articles/language-tags/ for more
207 * An array of language code to language name information. Language name
208 * information itself is an array of English and native names.
210 public static function getStandardLanguageList();