Chris@0: 'Long month name']); Chris@0: * \Drupal::translation()->formatPlural($count, '1 something', Chris@18: * '@count somethings', [], ['context' => 'My context']); Chris@0: * Chris@0: * // JavaScript code Chris@0: * Drupal.t('May', {}, {'context': 'Long month name'}); Chris@0: * Drupal.formatPlural(count, '1 something', '@count somethings', {}, Chris@0: * {'context': 'My context'}); Chris@0: * Chris@0: * // *.links.yml file Chris@0: * title: 'May' Chris@0: * title_context: 'Long month name' Chris@0: * Chris@0: * // *.routing.yml file Chris@0: * my.route.name: Chris@0: * pattern: '/something' Chris@0: * defaults: Chris@0: * _title: 'May' Chris@0: * _title_context: 'Long month name' Chris@0: * Chris@0: * // Config schema to say that a certain piece of configuration should be Chris@0: * // translatable using the Config Translation API. Note that the schema label Chris@0: * // is also translatable, but it cannot have context. Chris@0: * date_format: Chris@0: * type: string Chris@0: * label: 'PHP date format' Chris@0: * translatable: true Chris@0: * translation context: 'PHP date format' Chris@0: * Chris@0: * // Twig template Chris@0: * {% trans with {'context': 'Long month name'} %} Chris@0: * May Chris@0: * {% endtrans %} Chris@0: * @endcode Chris@0: * Chris@0: * @see transliteration Chris@0: * @see t() Chris@0: * @} Chris@0: */ Chris@0: Chris@0: /** Chris@0: * @addtogroup hooks Chris@0: * @{ Chris@0: */ Chris@0: Chris@0: /** Chris@0: * Perform alterations on language switcher links. Chris@0: * Chris@0: * A language switcher link may need to point to a different path or use a Chris@0: * translated link text before going through the link generator, which will Chris@0: * just handle the path aliases. Chris@0: * Chris@0: * @param array $links Chris@0: * Nested array of links keyed by language code. Chris@0: * @param string $type Chris@0: * The language type the links will switch. Chris@0: * @param \Drupal\Core\Url $url Chris@0: * The URL the switch links will be relative to. Chris@0: */ Chris@0: function hook_language_switch_links_alter(array &$links, $type, \Drupal\Core\Url $url) { Chris@0: $language_interface = \Drupal::languageManager()->getCurrentLanguage(); Chris@0: Chris@0: if ($type == LanguageInterface::TYPE_CONTENT && isset($links[$language_interface->getId()])) { Chris@0: foreach ($links[$language_interface->getId()] as $link) { Chris@0: $link['attributes']['class'][] = 'active-language'; Chris@0: } Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * @} End of "addtogroup hooks". Chris@0: */ Chris@0: Chris@0: /** Chris@0: * @defgroup transliteration Transliteration Chris@0: * @{ Chris@0: * Transliterate from Unicode to US-ASCII Chris@0: * Chris@0: * Transliteration is the process of translating individual non-US-ASCII Chris@0: * characters into ASCII characters, which specifically does not transform Chris@0: * non-printable and punctuation characters in any way. This process will always Chris@0: * be both inexact and language-dependent. For instance, the character Ö (O with Chris@0: * an umlaut) is commonly transliterated as O, but in German text, the Chris@0: * convention would be to transliterate it as Oe or OE, depending on the context Chris@0: * (beginning of a capitalized word, or in an all-capital letter context). Chris@0: * Chris@0: * The Drupal default transliteration process transliterates text character by Chris@0: * character using a database of generic character transliterations and Chris@0: * language-specific overrides. Character context (such as all-capitals Chris@0: * vs. initial capital letter only) is not taken into account, and in Chris@0: * transliterations of capital letters that result in two or more letters, by Chris@0: * convention only the first is capitalized in the Drupal transliteration Chris@0: * result. Also, only Unicode characters of 4 bytes or less can be Chris@0: * transliterated in the base system; language-specific overrides can be made Chris@0: * for longer Unicode characters. So, the process has limitations; however, Chris@0: * since the reason for transliteration is typically to create machine names or Chris@0: * file names, this should not really be a problem. After transliteration, Chris@0: * other transformation or validation may be necessary, such as converting Chris@0: * spaces to another character, removing non-printable characters, Chris@0: * lower-casing, etc. Chris@0: * Chris@0: * Here is a code snippet to transliterate some text: Chris@0: * @code Chris@0: * // Use the current default interface language. Chris@0: * $langcode = \Drupal::languageManager()->getCurrentLanguage()->getId(); Chris@0: * // Instantiate the transliteration class. Chris@0: * $trans = \Drupal::transliteration(); Chris@0: * // Use this to transliterate some text. Chris@0: * $transformed = $trans->transliterate($string, $langcode); Chris@0: * @endcode Chris@0: * Chris@0: * Drupal Core provides the generic transliteration character tables and Chris@0: * overrides for a few common languages; modules can implement Chris@0: * hook_transliteration_overrides_alter() to provide further language-specific Chris@0: * overrides (including providing transliteration for Unicode characters that Chris@0: * are longer than 4 bytes). Modules can also completely override the Chris@0: * transliteration classes in \Drupal\Core\CoreServiceProvider. Chris@0: */ Chris@0: Chris@0: /** Chris@0: * Provide language-specific overrides for transliteration. Chris@0: * Chris@0: * If the overrides you want to provide are standard for your language, consider Chris@0: * providing a patch for the Drupal Core transliteration system instead of using Chris@0: * this hook. This hook can be used temporarily until Drupal Core's Chris@0: * transliteration tables are fixed, or for sites that want to use a Chris@0: * non-standard transliteration system. Chris@0: * Chris@0: * @param array $overrides Chris@0: * Associative array of language-specific overrides whose keys are integer Chris@0: * Unicode character codes, and whose values are the transliterations of those Chris@0: * characters in the given language, to override default transliterations. Chris@0: * @param string $langcode Chris@0: * The code for the language that is being transliterated. Chris@0: * Chris@0: * @ingroup hooks Chris@0: */ Chris@0: function hook_transliteration_overrides_alter(&$overrides, $langcode) { Chris@0: // Provide special overrides for German for a custom site. Chris@0: if ($langcode == 'de') { Chris@0: // The core-provided transliteration of Ä is Ae, but we want just A. Chris@0: $overrides[0xC4] = 'A'; Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * @} End of "defgroup transliteration". Chris@0: */