Prove of concept (AKA, Not ready for production) for text transliteration. It uses the OS iconv with //TRANSLITERATE//IGNORE for transforming character between locales.
The locale must be available in the OS.
(you can see the tests for more results):
let tt = TextTransliterate::new();
let result = tt.transliterate("ü ä ö ß Ü Ä Ö ç ñ 的 😒", "de_DE.UTF-8");
if let Ok(result) = result {
assert_eq!("ue ae oe ss UE AE OE c n ? ?", result);
}
For using the correct locale (for example, to transliterate German letter correctly) it must use the function uselocale
from C. This changes the locale of the thread. For avoiding you can use the "off-thread" version, that creates a new thread for executing the uselocale
and iconv
let mut tt = TextTransliterateOffThread::new();
let result = tt.transliterate("ü ä ö ß Ü Ä Ö ç ñ 的 😒", "de_DE.UTF-8");
if let Ok(result) = result {
assert_eq!("ue ae oe ss UE AE OE c n ? ?", result);
}
- The test results can change between machines. Keep in mind that.
- The code depends of GNU libc
- There is a unsafe code that can create problems:
Apache-2.0/MIT