Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. AsciiSlugger.php

function AsciiSlugger::createTransliterator

1 call to AsciiSlugger::createTransliterator()
AsciiSlugger::slug in vendor/symfony/string/Slugger/AsciiSlugger.php
Creates a slug for the given string and locale, using appropriate transliteration when needed.

File

vendor/symfony/string/Slugger/AsciiSlugger.php, line 152

Class

AsciiSlugger
@author Titouan Galopin <galopintitouan@gmail.com>

Namespace

Symfony\Component\String\Slugger

Code

private function createTransliterator(string $locale) : ?\Transliterator {
    if (\array_key_exists($locale, $this->transliterators)) {
        return $this->transliterators[$locale];
    }
    // Exact locale supported, cache and return
    if ($id = self::LOCALE_TO_TRANSLITERATOR_ID[$locale] ?? null) {
        return $this->transliterators[$locale] = \Transliterator::create($id . '/BGN') ?? \Transliterator::create($id);
    }
    // Locale not supported and no parent, fallback to any-latin
    if (!($parent = self::getParentLocale($locale))) {
        return $this->transliterators[$locale] = null;
    }
    // Try to use the parent locale (ie. try "de" for "de_AT") and cache both locales
    if ($id = self::LOCALE_TO_TRANSLITERATOR_ID[$parent] ?? null) {
        $transliterator = \Transliterator::create($id . '/BGN') ?? \Transliterator::create($id);
    }
    return $this->transliterators[$locale] = $this->transliterators[$parent] = $transliterator ?? null;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal