1

I am using CakePHP 3.6, and when I am using words with german umlauts like:

Text::slug('Grundstücke')

I will get:

Grundstucke (where ü = u)

but that's not correct, I should get:

Grundstuecke (where ü = ue)

Is there an option to set so that umlauts are being converted the way I want them to?

ndm
  • 59,784
  • 9
  • 71
  • 110
user1555112
  • 1,897
  • 6
  • 24
  • 43

1 Answers1

4

Change your transliterator

The Text::slug() uses internally transliterator_transliterate (see php doc).

So you need to change the default transliterator that is being used.

After some research I found one that will work for you.

At the end of your bootstrap.php file add:

\Cake\Utility\Text::setTransliteratorId( 'de-ASCII; Any-Latin; Latin-ASCII; [\u0080-\u7fff] remove ');

Then your text will be converted as you expect.

Notes

Resources I've used to find this answer:

Ilie Pandia
  • 1,829
  • 14
  • 16
  • 1
    It should be noted that `de-ASCII` is only [**available as of ICU 60.1**](http://bugs.icu-project.org/trac/browser/tags/release-60-1/icu4c/source/data/translit/de_ASCII.txt). In earlier versions one would have to supply rules manually AFAIR. – ndm May 19 '18 at 11:32
  • it looks like, I have no luck with this solution... do you mind, having a closer chat about this? Can I contact you? – user1555112 Jun 04 '18 at 09:54
  • quite busy these days. if this is not working for you it is likely that as ndm said above you need a newer version of the transliteration module. maybe upgrade your PHP version to the latest? – Ilie Pandia Jun 06 '18 at 04:21
  • ICU moved to GitHub/JIRA, the link I've posted above isn't valid anymore, [**look here**](https://github.com/unicode-org/icu/blob/release-60-1/icu4c/source/data/translit/de_ASCII.txt) instead. – ndm Aug 18 '18 at 23:33
  • 2
    I would like to upvote this a thousand times! I'm not even working with cakephp, but trying to transliterate German umlauts correctly with standard PHP. `iconv()` with `ASCII//TRANSLIT` wouldn't work, despite setting `setlocale(LC_ALL, "de_DE.utf-8")` as recommended everywhere (and yes, that locale is available on the system). I had been searching for hours (literally!) until I found this. – Constantin Groß Aug 02 '21 at 21:01