Problem/Motivation

In an English installation, the Danish letters "æ" is transliterated to "a", and "ø" to "o", which is not the same as in a Danish language installation.

Would it be possible to add support for transliterating specific Scandinavian and German characters with more correct replacements, to streamline between languages?

For example for Danish sites, it would be nice to replace æ - ø - å
æ = ae
ø = oe
å = aa

Background:

When generating URL path aliases from nodes with Danish special characters in the title, the characters 'å' and 'ø' gets transliterated incorrectly to 'a' and 'o' instead of 'aa' and 'oe' when node language is English. Danish language nodes work as expected.

A fair share of Drupal installation may be installed with only English as language, but the content is in reality Danish, German, Norwegian, Icelandic, Faroese or Swedish. In such cases, æ will be transliterated correctly, but not ø, ö or å, which is inconsistent. Also, this can cause slight differences in URL aliases for multilingual sites, where you prefer them to be streamlined, see #3157288: German letter "ä", "ü" in translation and Drupal 8 pathauto and Greek characters.

Example:

A node with the title "1æ 2ø 3å 4Æ 5Ø 6Å" gets these paths, first in a node with language Danish, and then English:

/da/1ae-2oe-3aa-4ae-5oe-6aa
/en/1ae-2o-3a-4ae-5o-6a

The English language node should get this path (identical with the Danish node, except for en bit):

/en/1ae-2oe-3aa-4ae-5oe-6aa

We could also include umlaut letters from German language as well, see #3157288: German letter "ä", "ü" in translation, Conversion table for diacritics (e.g. "ü" → "ue"), and How to handle URLs with diacritic characters.

Proposed resolution

Add a new Expand transliteration for certain characters option under Pathauto Settings /admin/config/search/path/settings below Transliterate prior to creating alias, for Scandinavian and German characters:

[ ] Expand transliteration for certain characters
Improve transliteration (for example "æ" => "ae") for these characters as well: æ, Æ, ø, Ø, å, Å, ä, Ä, ö, Ö, ü, Ü, ß.

This would help Drupal sites where the content is in Danish, German, Norwegian, Icelandic, Faroese, and Swedish, but "housed" in an English language Drupal installation, because they then won't have to create a custom module. It will also streamline URL aliases between languages for multilingual Drupal installations.

The MR adds support for these letters:

Workaround

Until this gets fixed, use the transliteration overrides function, which does the trick. Note, that if you are using this with a migration, you need to remove the nodes completely with a rollback. The aliases seem to stay, even with the --delete parameter :)

/**
 * Implements hook_transliteration_overrides_alter().
 */
function mymodule_transliteration_overrides_alter(&$overrides, $langcode) {
// Transliterate Danish letters æ, å, and ø for English-language nodes.
  if ($langcode == 'en') {
    $overrides = [
      0xC5 => 'Aa',
      0xD8 => 'Oe',
      0xE5 => 'aa',
      0xF8 => 'oe',
      0xC6 => 'Ae',
      0xE6 => 'ae',
    ];
  }
}

From https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Language%...

Remaining tasks

Decide if an "Expand transliteration for certain characters" option on the Pathauto Settings page should be added.

User interface changes

API changes

Data model changes

Issue fork pathauto-1811856

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

ayushjn’s picture

Hi Pafla,

I am not really sure if I am getting you. Are you saying that you want to put danish characters in the Separator?

ayushjn’s picture

Hi Pafla,
May be you are referring to this issue http://drupal.org/node/1809686 ?

Freso’s picture

Status: Active » Closed (works as designed)
Issue tags: +transliteration

It's already implemented if you use the transliteration option with the Transliteration module. See e.g., https://drupal.org/node/185664#comment-1960306

pafla’s picture

Hi

I don´t know if I or you misunderstood?

http://drupal.org/project/transliteration
Is it not only for files?

About http://drupal.org/node/1809686 - Is this thread fixed?
It does not have to be a complete translations
Only for
æ =ae
ø =oe
å=aa

The real one is:
http://www.mysite.dk/content/ønsk-at-få-hjælp
When go to it is:
http://www.mysite.dk/content/%C3%B8nsk-at-f%C3%A5-hj%C3%A6lp
It is not very nice - i like it to be:
http://www.mysite.dk/content/oensk-at-faa-hjaelp

When i made a content/node I can go to admin/config/search/path
and edit, but it must be done every time a user make a node with æ-ø-å

I got admin/config/search/path
admin/config/search/path/patterns
admin/config/search/path/settings
admin/config/search/path/update_bulk
admin/config/search/path/delete_bulk

Can it be done in one of those or do I need another module or?

Pafla

pafla’s picture

Issue summary: View changes
Status: Closed (works as designed) » Active

Create a node "Ønsk at få hjælp"
When go to it is:
http://www.mysite.dk/content/%C3%B8nsk-at-f%C3%A5-hj%C3%A6lp - It is not very nice

- The path should be: http://www.mysite.dk/content/oensk-at-faa-hjaelp
How to do this?

I tried to enable http://drupal.org/project/transliteration
How can transliteration do this?

http://drupal.org/node/1809686
Added the following code to mymodule.module: - Where do I find this file

add1sun’s picture

Project: Pathauto » Transliteration
Version: 7.x-1.x-dev » 7.x-3.2
Category: Feature request » Bug report
Issue tags: -transliteration

To clarify things a bit, you can use Transliteration module to remove the special Danish characters in Pathauto paths* (å, æ, and ø) but it does not replace å and ø "properly." What Transliteration does is just make them into a and o, respectively. The correct transliteration for them, as noted above, would be aa and oe. (æ is properly changed into ae.)

I think this is a Transliteration module issue and not Pathauto, so I'm moving it. The Danish corrections are listed in data/x00.php but for some reason they are not being applied in either Pathauto or for filename conversions.

* To activate Transliteration with Pathauto, you need check the "Transliterate prior to creating alias" box on the Pathauto Settings tab (admin/config/search/path/settings).

ressa’s picture

It looks like a Drupal core transliteration problem, see #3525904: Transliterate æ, ø, and å characters for all languages by default.

ressa’s picture

Project: Transliteration » Drupal core
Version: 7.x-3.2 » 11.2.x-dev
Component: Code » transliteration system
quietone’s picture

ressa’s picture

Title: Danish characters » Allow transliteration of Danish characters
Project: Drupal core » Pathauto
Version: 11.x-dev » 8.x-1.x-dev
Component: transliteration system » Code
Category: Bug report » Feature request
Issue summary: View changes

Thanks for checking @quietone, initially I thought that it was a duplicate, with a workaround in the other issue, and hopefully a more permanent solution.

On the other hand, this issue was initially created for Pathauto, which does offer a list of punctuation options, and it might make sense to similarly add a same style of options for letters such as æ, ø, and å ...

So moving back to Pathauto, and updating the Issue Summary to be a feature request :)

ressa’s picture

Title: Allow transliteration of Danish characters » Add support for transliteration of Danish characters
Issue summary: View changes
Related issues: +#3157288: German letter "ä", "ü" in translation

Updating the Issue Summary and adding a related issue. Perhaps German letters could also be included?

ressa’s picture

Title: Add support for transliteration of Danish characters » Add transliteration options for special characters such as æ, ø, å, ä, ü, etc.
ressa’s picture

ressa’s picture

@ghost of drupal past clarified in #3525904: Transliterate æ, ø, and å characters for all languages by default that this should not be handled in Drupal core, so Pathauto is probably the best bet.

ressa’s picture

Issue summary: View changes
Status: Active » Needs review

I added a new "Expand transliteration for certain characters" option on the Pathauto Settings page, could that work?

ressa’s picture

The failing tests seem unrelated ... I tried running them locally, with and without the MR, and get the same errors.

mably made their first commit to this issue’s fork.

ressa’s picture

Issue summary: View changes

Wouldn't this be a nice feature to have?

csakiistvan’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new52.92 KB
new79.1 KB
new73.13 KB

Environment

  • Drupal: 11.4.4
  • PHP: 8.5.5
  • Database: MariaDB 10.11.16
  • DDEV: v1.25.2
  • Pathauto: 1.15.0
  • Browser: Chrome

Prerequisites

  • Drupal 11 site with drupal/pathauto:1.15.0 installed, English only (no additional languages), so the reported "English installation with Scandinavian content" case applies.
  • A pathauto pattern of type Content with the pattern /[node:title].
  • An article with the title 1æ 2ø 3å 4Æ 5Ø 6Å, saved in English.

Steps

  1. Apply the fix from MR !112: add a Expand transliteration for certain characters setting (transliterate_extra, default off) to the pathauto settings form, schema and default config, and apply an extra replacement table in the alias cleaner for æ, Æ, ø, Ø, å, Å, ä, Ä, ö, Ö, ü, Ü and ß.
  2. Rebuild caches: ddev drush cr
  3. Go to Configuration > Search and metadata > URL aliases > Settings (/admin/config/search/path/settings) and check the new checkbox below Transliterate prior to creating alias.
  4. Leave the new option unchecked, save, re-save the article and look at its alias on /admin/config/search/path.
  5. Check Expand transliteration for certain characters, save the settings, re-save the article and look at its alias again.
  6. Repeat step 5 with an article titled Straße Müller Öl to cover the German letters.

Expected results

  • The settings form shows Expand transliteration for certain characters directly below Transliterate prior to creating alias, unchecked by default, so existing sites keep their current aliases.
  • With the option off, the alias stays /1ae-2oe-3aa-4ae-5oe-6aa unchanged from the pre-fix behaviour: /1ae-2o-3a-4ae-5o-6a.
  • With the option on, the English node gets /1ae-2oe-3aa-4ae-5oe-6aa, identical to what a Danish-language node produces.
  • German letters follow the same table: Straße Müller Öl becomes /strasse-mueller-oel instead of /strasse-muller-ol.

Actual results

Before the fix, the English article was aliased to /1ae-2o-3a-4ae-5o-6a: only æ/Æ were expanded, while ø, Ø, å and Å collapsed to o and a, and the settings page offered no way to change it. After applying MR !112 the new checkbox appeared below Transliterate prior to creating alias and was off by default, with the alias unchanged. Enabling it and re-saving the article produced /1ae-2oe-3aa-4ae-5oe-6aa, matching the Danish-language result, and Straße Müller Öl produced /strasse-mueller-oel. Toggling the option back off restored the old alias on the next save. No errors or deprecations were logged by pathauto in any state.

Notes for the maintainer

  • The new replacement runs unconditionally, independent of the transliterate setting. With Transliterate prior to creating alias unchecked, 1æ 2ø 3å 4Æ 5Ø 6Å still yields 1ae-2oe-3aa-4ae-5oe-6aa, because the #states rule only hides the checkbox in the UI, it does not clear the stored value. If the option is meant to be a refinement of transliteration, the condition in AliasCleaner::cleanString() should also require transliterate.
  • An update hook may be worth adding: transliterate_extra only reaches existing sites' active config once the settings form is saved, and it reads as NULL until then. That is harmless (falsy), but it leaves the config object out of sync with the schema.
  • The table is language-independent by design, which is what the issue asks for, but it also affects genuinely non-Scandinavian/German content on the same site (for example Turkish or Estonian ö/ü). Worth a sentence in the setting description.

Testing produced with the assistance of an LLM.