Skip to content

Generate url_key with Magento's translit filter so non-Latin target languages work - #71

Merged
SamueleMartini merged 3 commits into
mage-os:mainfrom
Bashev:fix-url-key-translation
Aug 26, 2026
Merged

SamueleMartini merged 3 commits into
mage-os:mainfrom
Bashev:fix-url-key-translation

Conversation

@Bashev

@Bashev Bashev commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Problem

When the target store view uses a non-Latin script (Greek, Cyrillic, …), translating a category or product fails on save with:

Invalid URL key. The "-" URL key can not be used to generate Latin URL key.
Please use Latin letters and numbers to avoid generating URL key issues.

AdminhtmlCategoryBeforeSavePlugin (and AdminhtmlProductBeforeSavePlugin) translate the url_key value and then sanitise it with:

strtolower((string)preg_replace('#[^0-9a-z]+#i', '-', $value))

That regex simply strips every character that is not a-z0-9. For a Latin-script target (de/fr/it) this is fine, but for Greek/Cyrillic/etc. every letter is removed and the key collapses to a single -, which Magento then rejects — the whole save blows up.

Fix

Use the same transliteration Magento core uses to build url keys (Magento\Catalog\Model\Category::formatUrlKey → FilterManager::translitUrl).
translitUrl transliterates via Magento\Framework\Filter\Translit (which already covers Greek and other scripts), lowercases, and normalises separators.

$requestPostValue[$attributeCode] = $this->filterManager->translitUrl((string)$value);

FilterManager is injected through the constructor of both plugins.

Result

Greek input now produces a proper Latin slug instead of an invalid key:

input before after
Βιολογικά βότανα και τσάι - (save error) biologika-botana-kai-tsai
Καλλυντικά προϊόντα - (save error) kalluntika-proionta

For a value that transliterates to nothing, translitUrl returns an empty string, so Magento auto-generates the key from the (translated) name — no more hard error.

Notes

  • Same bug and same fix in both the category and product save plugins.
  • No behaviour change for Latin-script target languages.

@Bashev
Bashev requested review from a team, SamueleMartini and dadolun95 as code owners August 24, 2026 14:34
@rhoerr

rhoerr commented Aug 25, 2026

Copy link
Copy Markdown
Member

Good to me in concept, thank you @Bashev

@SamueleMartini

SamueleMartini commented Aug 26, 2026 •

Copy link
Copy Markdown
Collaborator

Hi @Bashev, Thank you so much for your contribution! Could you also update the changelog file?
I think the correct version number cloud be 2.3.0 if we want to view the change as the addition of support for non-Latin alphabets, or 2.2.2 if we want to consider the change as a fix.
Once the changelog is updated, I'll approve the pull request. Thank you so much!

@SamueleMartini
SamueleMartini merged commit 3d0e368 into mage-os:main Aug 26, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants