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
| Comment | File | Size | Author |
|---|---|---|---|
| #20 | 1811856 after.png | 73.13 KB | csakiistvan |
| #20 | 1811856 settings.png | 79.1 KB | csakiistvan |
| #20 | 1811856 before.png | 52.92 KB | csakiistvan |
Issue fork pathauto-1811856
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
Comment #1
ayushjn commentedHi Pafla,
I am not really sure if I am getting you. Are you saying that you want to put danish characters in the Separator?
Comment #2
ayushjn commentedHi Pafla,
May be you are referring to this issue http://drupal.org/node/1809686 ?
Comment #3
Freso commentedIt's already implemented if you use the transliteration option with the Transliteration module. See e.g., https://drupal.org/node/185664#comment-1960306
Comment #4
pafla commentedHi
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
Comment #5
pafla commentedCreate 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
Comment #6
add1sun commentedTo 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).
Comment #7
ressaIt looks like a Drupal core transliteration problem, see #3525904: Transliterate æ, ø, and å characters for all languages by default.
Comment #8
ressaFYI I created an MR, #3525904: Transliterate æ, ø, and å characters for all languages by default.
Comment #9
quietone commented@ressa, is this a duplicate of #3525904: Transliterate æ, ø, and å characters for all languages by default.
Comment #10
ressaThanks 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 :)
Comment #11
ressaUpdating the Issue Summary and adding a related issue. Perhaps German letters could also be included?
Comment #12
ressaComment #13
ressaComment #14
ressa@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.
Comment #16
ressaI added a new "Expand transliteration for certain characters" option on the Pathauto Settings page, could that work?
Comment #17
ressaThe failing tests seem unrelated ... I tried running them locally, with and without the MR, and get the same errors.
Comment #19
ressaWouldn't this be a nice feature to have?
Comment #20
csakiistvanEnvironment
Prerequisites
drupal/pathauto:1.15.0installed, English only (no additional languages), so the reported "English installation with Scandinavian content" case applies./[node:title].1æ 2ø 3å 4Æ 5Ø 6Å, saved in English.Steps
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 ß.ddev drush cr/admin/config/search/path/settings) and check the new checkbox below Transliterate prior to creating alias./admin/config/search/path.Straße Müller Ölto cover the German letters.Expected results
/1ae-2oe-3aa-4ae-5oe-6aaunchanged from the pre-fix behaviour:/1ae-2o-3a-4ae-5o-6a./1ae-2oe-3aa-4ae-5oe-6aa, identical to what a Danish-language node produces.Straße Müller Ölbecomes/strasse-mueller-oelinstead 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 tooanda, 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, andStraße Müller Ölproduced/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
transliteratesetting. With Transliterate prior to creating alias unchecked,1æ 2ø 3å 4Æ 5Ø 6Åstill yields1ae-2oe-3aa-4ae-5oe-6aa, because the#statesrule 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 inAliasCleaner::cleanString()should also requiretransliterate.transliterate_extraonly reaches existing sites' active config once the settings form is saved, and it reads asNULLuntil then. That is harmless (falsy), but it leaves the config object out of sync with the schema.ö/ü). Worth a sentence in the setting description.Testing produced with the assistance of an LLM.