LanguageManagerInterface.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. <?php
  2. namespace Drupal\Core\Language;
  3. use Drupal\Core\Url;
  4. /**
  5. * Common interface for the language manager service.
  6. */
  7. interface LanguageManagerInterface {
  8. /**
  9. * Returns whether or not the site has more than one language added.
  10. *
  11. * @return bool
  12. * TRUE if more than one language is added, FALSE otherwise.
  13. */
  14. public function isMultilingual();
  15. /**
  16. * Returns an array of the available language types.
  17. *
  18. * @return array
  19. * An array of language type machine names.
  20. */
  21. public function getLanguageTypes();
  22. /**
  23. * Returns information about all defined language types.
  24. *
  25. * @return array
  26. * An associative array of language type information arrays keyed by
  27. * language type machine name, in the format of
  28. * hook_language_types_info(). In some implementing classes, this is based
  29. * on information from hook_language_types_info() and
  30. * hook_language_types_info_alter().
  31. */
  32. public function getDefinedLanguageTypesInfo();
  33. /**
  34. * Returns the current language for the given type.
  35. *
  36. * @param string $type
  37. * (optional) The language type; e.g., the interface or the content
  38. * language. Defaults to
  39. * \Drupal\Core\Language\LanguageInterface::TYPE_INTERFACE.
  40. *
  41. * @return \Drupal\Core\Language\LanguageInterface
  42. * The current language object for the given type of language.
  43. */
  44. public function getCurrentLanguage($type = LanguageInterface::TYPE_INTERFACE);
  45. /**
  46. * Resets the given language type or all types if none specified.
  47. *
  48. * @param string|null $type
  49. * (optional) The language type to reset as a string, e.g.,
  50. * LanguageInterface::TYPE_INTERFACE, or NULL to reset all language types.
  51. * Defaults to NULL.
  52. *
  53. * @return $this
  54. * The language manager that has been reset.
  55. */
  56. public function reset($type = NULL);
  57. /**
  58. * Returns a language object representing the site's default language.
  59. *
  60. * @return \Drupal\Core\Language\LanguageInterface
  61. * A language object.
  62. */
  63. public function getDefaultLanguage();
  64. /**
  65. * Returns a list of languages set up on the site.
  66. *
  67. * @param int $flags
  68. * (optional) Specifies the state of the languages that have to be returned.
  69. * It can be: LanguageInterface::STATE_CONFIGURABLE,
  70. * LanguageInterface::STATE_LOCKED, or LanguageInterface::STATE_ALL.
  71. *
  72. * @return \Drupal\Core\Language\LanguageInterface[]
  73. * An associative array of languages, keyed by the language code.
  74. */
  75. public function getLanguages($flags = LanguageInterface::STATE_CONFIGURABLE);
  76. /**
  77. * Returns a list of languages set up on the site in their native form.
  78. *
  79. * @return \Drupal\Core\Language\LanguageInterface[]
  80. * An associative array of languages, keyed by the language code, ordered
  81. * by weight ascending and name ascending.
  82. */
  83. public function getNativeLanguages();
  84. /**
  85. * Returns a language object from the given language code.
  86. *
  87. * @param string $langcode
  88. * The language code.
  89. *
  90. * @return \Drupal\Core\Language\LanguageInterface|null
  91. * A fully-populated language object or NULL.
  92. */
  93. public function getLanguage($langcode);
  94. /**
  95. * Produced the printed name for a language for display.
  96. *
  97. * @param string $langcode
  98. * The language code.
  99. *
  100. * @return string
  101. * The printed name of the language.
  102. */
  103. public function getLanguageName($langcode);
  104. /**
  105. * Returns a list of the default locked languages.
  106. *
  107. * @param int $weight
  108. * (optional) An integer value that is used as the start value for the
  109. * weights of the locked languages.
  110. *
  111. * @return \Drupal\Core\Language\LanguageInterface[]
  112. * An array of language objects.
  113. */
  114. public function getDefaultLockedLanguages($weight = 0);
  115. /**
  116. * Checks whether a language is locked.
  117. *
  118. * @param string $langcode
  119. * The language code.
  120. *
  121. * @return bool
  122. * Returns whether the language is locked.
  123. */
  124. public function isLanguageLocked($langcode);
  125. /**
  126. * Returns the language fallback candidates for a given context.
  127. *
  128. * @param array $context
  129. * (optional) An associative array of data that can be useful to determine
  130. * the fallback sequence. The following keys are used in core:
  131. * - langcode: Language code of the desired language.
  132. * - operation: The name of the operation indicating the context where
  133. * language fallback is being applied. The following operations are
  134. * defined in core, but more may be defined in contributed modules:
  135. * - entity_view: Invoked when an entity is about to be displayed.
  136. * The data key contains the loaded entity.
  137. * - views_query: Invoked when a field based views query is performed.
  138. * The data key contains a reference to the field object.
  139. * - locale_lookup: Invoked when a string translation was not found.
  140. * The data key contains the source string.
  141. * - data: A data structure that makes sense in the provided
  142. * context, see above.
  143. *
  144. * @return array
  145. * An array of language codes sorted by priority: first values should be
  146. * tried first.
  147. */
  148. public function getFallbackCandidates(array $context = []);
  149. /**
  150. * Returns the language switch links for the given language type.
  151. *
  152. * @param string $type
  153. * The language type.
  154. * @param \Drupal\Core\Url $url
  155. * The URL the switch links will be relative to.
  156. *
  157. * @return array
  158. * A keyed array of links ready to be themed.
  159. */
  160. public function getLanguageSwitchLinks($type, Url $url);
  161. /**
  162. * Sets the configuration override language.
  163. *
  164. * @param \Drupal\Core\Language\LanguageInterface $language
  165. * The language to override configuration with.
  166. *
  167. * @return $this
  168. */
  169. public function setConfigOverrideLanguage(LanguageInterface $language = NULL);
  170. /**
  171. * Gets the current configuration override language.
  172. *
  173. * @return \Drupal\Core\Language\LanguageInterface
  174. * The current configuration override language.
  175. */
  176. public function getConfigOverrideLanguage();
  177. /**
  178. * Some common languages with their English and native names.
  179. *
  180. * Language codes are defined by the W3C language tags document for
  181. * interoperability. Language codes typically have a language and, optionally,
  182. * a script or regional variant name. See:
  183. * http://www.w3.org/International/articles/language-tags/ for more
  184. * information.
  185. *
  186. * @return array
  187. * An array of language code to language name information. Language name
  188. * information itself is an array of English and native names.
  189. */
  190. public static function getStandardLanguageList();
  191. }