Skip to main content
Gábor Hojtsy on Drupal

Main navigation

  • Blog posts
    • Configuration schema cheat sheet
    • Drupal 11
    • Drupal 10
    • #DrupalCares
    • Drupal 9
    • DDD 2014 report
    • Multilingual Drupal 8
    • Multilingual Drupal 7
    • Drupal 6
  • About Gábor

Breadcrumb

  1. Home
  2. Multilingual Drupal 8

Drupal 8 multilingual tidbits 8: transliteration

By Gábor Hojtsy , 17 July, 2013

Up to date as of October 16th, 2015.

We went through most of the great new base language features in Drupal 8, but one thing that was not yet covered is built-in transliteration support. Yes, you read that right. Drupal 8 includes a powerful backend system for transliteration and it even uses it for machine name generation on the frontend.

Here are a few examples on how Drupal prefills the machine name for a content type for a Hungarian, Czech and Marathi type respectively:

Image
Image
Image

You don't even need to have language module enabled to use the transliteration services. However language specific transliteration patterns are supported, and the overrides are alterable. See https://drupal.org/node/1842748 for documentation on how to tap into this new API.

While this concludes the list of new base language features, that is only one of the language related modules in core. The tidbits are far from over! Excited about Drupal 8 yet?

Issues to work on

  • Transliteration is only applied to machine names in core. Files would be a natural next candidate. See existing discussions in https://drupal.org/node/1842718 (includes an early patch that includes file support) and https://drupal.org/node/567832. A specific issue for files is https://www.drupal.org/node/2492171. Contributed modules can implement transliteration for anything.
Tags
Drupal 8
Drupal
D8MI
multilingual

matrixlord (not verified)

10 years 9 months ago

API function

Very good! Is there an accessible API function that you can transliterate text on demand like in the transliteration module? Thanks!

Gábor Hojtsy

10 years 8 months ago

In reply to API function by matrixlord (not verified)

sure

<?phpuse Drupal\Core\Transliteration\PHPTransliteration;$transliterator = new PHPTransliteration();$transliterated = $transliterator->transliterate('Árvíztűrő tükörfúrógép', 'hu');?>

David Park (not verified)

9 years 5 months ago

In reply to sure by Gábor Hojtsy

Not working

Hi it seems like the constructur needs the second argument so the code

$transliterator = new PHPTransliteration();

don't work.

Gábor Hojtsy

9 years 5 months ago

In reply to Not working by David Park (not verified)

right!

Right, it may have worked in 2014 when I posted about it :) Looks like now there is a transliteration class in Core which does require the module handler and then there is a transliteration class in Component that does not. The difference is support for an alter hook. You need to pass in the module handler to the Core one. So that would become:

<?phpuse Drupal\Core\Transliteration\PHPTransliteration;$transliterator = new PHPTransliteration(NULL, \Drupal::moduleHandler());$transliterated = $transliterator->transliterate('Árvíztűrő tükörfúrógép', 'hu');?>

In a global scope at least.

Hennie (not verified)

8 years ago

Removing accents in D8

Thanks for this article. We're busy with a Hungarian site and I need to replace the accents in URLs, how can I do this? With D7 you would use pathauto and transliteration but with D8 I do not know. Any suggestions?

Gábor Hojtsy

7 years ago

In reply to Removing accents in D8 by Hennie (not verified)

pathauto itself

Pathauto itself should do the trick.

Anish Sheela (not verified)

7 years 3 months ago

Transliteration for Indian

Transliteration for Indian languages needs improvement though. I will try to contribute that.

Multilingual Drupal 8

  • Introduction
  • Language first
  • Core modules
  • Simple language setup, optional English
  • Highly flexible detection options
  • Almost limitless language assignment
  • Easier right to left styling
  • Blocks and views
  • Transliteration
  • Deployment friendly automated downloads
  • Context specific text translation APIs
  • String customizations tracked
  • English can now be translated to
  • Much improved software translation UI
  • Intro to content and configuration
  • Configuration translation basics
  • Configuration translation development
  • Content translation basics
  • Content translation development
  • Core content translation workflow
  • Combination use cases with content and menus
RSS feed

Content, unless noted otherwise is licensed under Creative Commons BY-NC 4.0. Feel free to copy, remix, redistribute and build upon my content, with proper attribution. Hosted at Acquia

Powered by Drupal