Transliteration is different from language to language and the function does not support this. You should be able to feed the function an optional array that will be used for transliteration first.
Here is an example from two languages I know that come with different ‘rules’: German and Swedish.
Kreis Böblingen, a district in Germany, has the following website: `http://www.landkreis-boeblingen.de/`.
Örebro län, a district in Sweden, has Örebro has central city. The website for Örebro is: `http://orebro.se/`.
In German the ¨ (umlaut) is always transliterated as `-e`, while in Swedish the diacritic is simply dropped.
This isn’t just in domain names, I took those at they could easily be compared. This is also how a German versus a Swedish user will write text when they do not have access to the umlaut, for instance on foreign keyboards.
On a German website I would like an easy way to force the function to replace `ö` with `oe`.
“Hello; this is a batched-reply I'm giving to the e-mails I received about transliteration; I'm really most pleasantly surprised to have received so many so quickly, it's obviously a passionate subject for some. I care that my code does a good job as it already improves greatly on the single-function examples I've trawled through and discarded for years. Despite the fact that I don't have any experience of other languages and scripts, so I do not proclaim accuracy but I do proclaim that I tried harder than all the other functions I've seen thus far (excluding the full blown million-line long libraries :P). I'm open to all input on the subject.
:: Issue #1
The first thing you raised was German umlauts. "ä->ae, ö->oe, ü->ue" &c. Others added that this is not the case in Sweden.
:: Issue #2
"ñ" to either "ni" or "nn"; I always thought it should be "ny" (e.g. "Mañana" > "Manyana") -- can anybody else help confirm what it should be?
In answering these it's important to note that the function is specifically for filenames and URLs; not for body text. Perfection is inherently impossible because of differences in locales (such as Issue #2), and therefore we must simply weigh up the gains and the losses.
In that regard I am inclined to support converting umlauts in the way requested by multiple people ("ä->ae, ö->oe, ü->ue"), despite the fact that this goes against Swedish practices. It's only for URLs and filenames and so plays a tiny part, and I think it's the best option rather than the other way around.
---
RE: The licence. One person mentioned that there was no licence on the gist. The code is creative-commons 3. You may do anything you please so long as you give credit -- but to be honest I will not hunt you down if you don't credit. I licence with cc-by3 solely to preserve copyright so that someone can't come along and claim the code was their own invention and sue me for it or something. I'm completely lax when it comes to licences, just follow Wheaton's law. Credit only has to be a comment line to go along with the function, credit is not required outside the source code, and it can be used in close-source. You can re-licence, as long as credit is retained in the code.
“I am inclined to support converting umlauts in the way requested by multiple people ("ä->ae, ö->oe, ü->ue"), despite the fact that this goes against Swedish practices.”
Note that I used Swedish as an example because I speak it. Not because Swedish is an exception. I must protest against defaulting `¨` to `-e`. Let me just cite Wikipedia on this: [1]
“Note that unlike the O-umlaut, the letter Ö cannot be written as ‘oe’. Minimal pairs exist between ‘ö’ and ‘oe’ (and also with ‘oo’, ‘öö’ and ‘öe’). Consider Finnish eläinkö ‘animal?’ (interrogative) vs. eläinkoe ‘animal test’, or Finnish töissä ‘at work’, toissa ‘before last’. In the case the character Ö is unavailable, O is substituted and context is relied upon for inference of the intended meaning.”
There are languages where the Ö is not seen as an O with a diacritic, but as a wholy separate letter. And there are languages where Ö is an O with a diaeresis, not with an umlaut.
Again, to cite Wikipedia: [2]
“Strictly speaking, the words diaeresis and umlaut refer to two distinct phonological phenomena. The diaeresis is used to denote the phenomenon also known as diaeresis, or hiatus, in which a vowel letter is not part of a digraph or diphthong. The umlaut refers to a sound shift.”
A diaeresis in use in Dutch: coöperatief; or in English: zoölogy. Neither Dutch nor English know any sound shifts caused by umlauts, ¨ is always used as diaeresis.
• Böblingen → boeblingen ✓ (this is an o-umlaut.)
• Örebro → Oerebro ✗ (this is the 29th letter of the Swedish alphabet.)
• coöperatief → cooeperatief ✗ (this is an O with diaeresis as seen in Dutch.)
• zoölogy → zooelogy ✗ (this is an O with diaeresis as seen in English.)
Also note that you will be making an exception the rule. In German the umlaut only exists for a, o, and u. So what will you do with ï or ë? What makes it a good idea to transliterate with `-e` for only some characters? Both ï and ë are used in Dutch:
• pinguïn (diaeresis used to break the diphthong `ui`.)
• skiën (diaeresis used to break the digraph `ie`.)
Even in German there will be rare instances of proper names with an `ë` and these should not be transliterated as `ee`. There is no such thing as e-umlaut. [3]
I’d like to hear from other native speakers of languages. This post pretty much covers the languages I know: Dutch, German, English, and Swedish. How many languages can we find with umlauts versus diaeresis?
Hello Martijn, I'm a native speaker of Dutch, and in the Dutch language, the use of the diaeresis is indeed what you describe, to not misread the word.
As far as I know, there are a lot of words that use the ¨ in their plurar form, and many people use them incorrectly (including me) by placing them on the wrong vowel.
It doesn't make much difference to most people if you just drop the ¨ and write it only as e.
ATM, the code translates "ë" & "ï " to "e" and "i" respectively, and "ä/ö/ü" to "ae/oe/ue". Would it be best, given @Martijn's information, that I should change this to "ae/o/ue"? (drop the e on the o)
Reply
Your friendly neighbourhood moderators:
Kroc, Impressed, Martijn