NAME
Lingua::DE::ASCII - Perl extension to convert german umlauts to and from ascii
SYNOPSIS
use Lingua::DE::ASCII;
print to_ascii("Umlaute wie ä,ö,ü,ß oder auch é usw. " .
"sind nicht im ASCII Format " .
"und werden deshalb umgeschrieben);
print to_latin1("Dies muesste auch rueckwaerts funktionieren ma cherie");
DESCRIPTION
This module enables conversion from and to the ASCII format of german texts.
It has two methods: to_ascii
and to_latin1
which one do exactly what they say.
Please note that both methods take only one scalar as argument and not whole a list.
to_ascii($string)
The to_ascii
method is just simple. It replaces each printable ANSI character (codes 160..255) with a (hopefully) sensfull ASCII representation (might be more than one character). The ANSI character with codes 128..160 are not printable and they are removed by default. The transliteration is defined with the global %Lingua::DE::ASCII::ANSI_TO_ASCII_TRANSLITERATION
variable. You can change this variable if you want to change the transliteration behaviour.
to_latin1($string)
The to_latin1
method is very complex (more than 700 lines of code). It retranslates 7-bit ASCII representations into a reasonable german ANSI representation. Thus it changes mainly 'ae' to 'ä', 'oe' to 'ö', 'ue' to 'ü', 'ss' to 'ß'. It also changes some other characters, e.g. '(C)' to '©' or in words like 'Crepe' it also restores the really writing 'Crêpe'.
Of course, the method only tries to change where it should. That explains the enormous complexity of this method, as it tries to solve a hard linguistic problem with a bit logic and many regular expressions (please also look to BUGS if you are interested in known problems).
At the moment you can't change the behaviour of the to_latin1
method (e.g. switching from the new german spelling to the old one), and I'm not sure whether I will enable it. Please inform me, if you feel that it would be important or much convenient in a case.
EXPORT
to_ascii($string) to_latin1($string)
BUGS
That's only a stupid computer program, faced with a very hard ai problem. So there will be some words that will be always hard to retranslate from ascii to latin1 encoding. A known example is the difference between "Maß(einheit)" and "Masseentropie" or similar. Another examples are "flösse" and "Flöße" or "(Der Schornstein) ruße" and "Russe", "Geheimtuer(isch)" and "Geheimtür", "anzu-ecken" and "anzücken" or quite even a lonely "ss" or "ß". Also, it's hard to find the right spelling for the prefixes "miss-" or "miß-". In doubt I tried to use to more common word and in even still a doubt the program tries to be conservative, that means it prefers not to translate to an umlaut. Reason is that the text is still readable with one "ae","oe","ue" or "ss" too much, but a wrong "ä", "ö", "ü" or "ß" can make it very unreadable.
I tried it with a huge list of german words, but please tell me if you find a bug.
This module is intended for ANSI code that is e.g. different from windows coding.
Misspelled words will create a lot of extra mistakes by the program. In doubt it's better to write with new Rechtschreibung.
The to_latin1
method is not very quick (but quick enough to work interactively with text files of about 20 KB). It's programmed to handle as many exceptions as possible.
I avoided localizations for character handling (thus it should work on every computer), but the price is that in some rare cases of words with multiple umlauts (like "Häkeltülle") some buggy conversions can occur. Please tell me if you find such words.
TESTS
The test scripts (called by e.g. make test
) need a long time. The reason is that I test it with a huge german word list. Normally you can skip this test if there is no failing in the first few seconds.
There are two major reasons why I added so many words to test even to the CPAN release. On the one hand, I wanted to give you a chance to detect strange behaviour under uncommon circumstances. (I haven't test it under a non-german locale based operation system e.g.) On the other hand, I also wanted you to give a chance to detect yourself whether a to_latin1
result is a bug or a feature. (Just search through the content of the test files to determine whether a strange looking word is tested for and thus wanted).
AUTHOR
Janek Schleicher, <bigj@kamelfreund.de>
SEE ALSO
Lingua::DE::Sentence (another cool module)
1 POD Error
The following errors were encountered while parsing the POD:
- Around line 876:
Non-ASCII character seen before =encoding in 'ä,ö,ü,ß'. Assuming CP1252