1<?php 2 3namespace Drupal\Core\Language; 4 5/** 6 * Defines an interface for languages. 7 * 8 * @ingroup i18n 9 */ 10interface LanguageInterface { 11 12 /** 13 * Special system language code (only applicable to UI language). 14 * 15 * Refers to the language used in Drupal and module/theme source code. Drupal 16 * uses the built-in text for English by default, but if configured to allow 17 * translation/customization of English, we need to differentiate between the 18 * built-in language and the English translation. 19 */ 20 const LANGCODE_SYSTEM = 'system'; 21 22 /** 23 * The language code used when no language is explicitly assigned (yet). 24 * 25 * Should be used when language information is not available or cannot be 26 * determined. This special language code is useful when we know the data 27 * might have linguistic information, but we don't know the language. 28 * 29 * See http://www.w3.org/International/questions/qa-no-language#undetermined. 30 */ 31 const LANGCODE_NOT_SPECIFIED = 'und'; 32 33 /** 34 * The language code used when the marked object has no linguistic content. 35 * 36 * Should be used when we explicitly know that the data referred has no 37 * linguistic content. 38 * 39 * See http://www.w3.org/International/questions/qa-no-language#nonlinguistic. 40 */ 41 const LANGCODE_NOT_APPLICABLE = 'zxx'; 42 43 /** 44 * Language code referring to the default language of data, e.g. of an entity. 45 * 46 * See the BCP 47 syntax for defining private language tags: 47 * http://www.rfc-editor.org/rfc/bcp/bcp47.txt 48 */ 49 const LANGCODE_DEFAULT = 'x-default'; 50 51 /** 52 * Language code referring to site's default language. 53 */ 54 const LANGCODE_SITE_DEFAULT = 'site_default'; 55 56 /** 57 * A regex for validating language codes according to W3C specifications. 58 * 59 * @see https://www.w3.org/International/articles/language-tags/ 60 */ 61 const VALID_LANGCODE_REGEX = '[a-zA-Z]{1,8}(-[a-zA-Z0-9]{1,8})*'; 62 63 /** 64 * The language state when referring to configurable languages. 65 */ 66 const STATE_CONFIGURABLE = 1; 67 68 /** 69 * The language state when referring to locked languages. 70 */ 71 const STATE_LOCKED = 2; 72 73 /** 74 * The language state used when referring to all languages. 75 */ 76 const STATE_ALL = 3; 77 78 /** 79 * The language state used when referring to the site's default language. 80 */ 81 const STATE_SITE_DEFAULT = 4; 82 83 /** 84 * The type of language used to define the content language. 85 */ 86 const TYPE_CONTENT = 'language_content'; 87 88 /** 89 * The type of language used to select the user interface. 90 */ 91 const TYPE_INTERFACE = 'language_interface'; 92 93 /** 94 * The type of language used for URLs. 95 */ 96 const TYPE_URL = 'language_url'; 97 98 /** 99 * Language written left to right. Possible value of $language->direction. 100 */ 101 const DIRECTION_LTR = 'ltr'; 102 103 /** 104 * Language written right to left. Possible value of $language->direction. 105 */ 106 const DIRECTION_RTL = 'rtl'; 107 108 /** 109 * Gets the name of the language. 110 * 111 * @return string 112 * The human-readable name of the language (in the language that was 113 * used to construct this object). 114 */ 115 public function getName(); 116 117 /** 118 * Gets the ID (language code). 119 * 120 * @return string 121 * The language code. 122 */ 123 public function getId(); 124 125 /** 126 * Gets the text direction (left-to-right or right-to-left). 127 * 128 * @return string 129 * Either self::DIRECTION_LTR or self::DIRECTION_RTL. 130 */ 131 public function getDirection(); 132 133 /** 134 * Gets the weight of the language. 135 * 136 * @return int 137 * The weight, used to order languages with larger positive weights sinking 138 * items toward the bottom of lists. 139 */ 140 public function getWeight(); 141 142 /** 143 * Returns whether this language is the default language. 144 * 145 * @return bool 146 * Whether the language is the default language. 147 */ 148 public function isDefault(); 149 150 /** 151 * Returns whether this language is locked. 152 * 153 * @return bool 154 * Whether the language is locked or not. 155 */ 156 public function isLocked(); 157 158} 159