I'm trying to get Cyrillic words to be in latin so I can have them in urls. I use icu4j transliterator, but it still gives weird characters like this: Vilʹândimaa. It should be more like viljandimaa. When I copy that url these letters turn to %.. something useless.
Does anybody know how to get Cyrillic to a-z with icu4j?
UPDATE
Can't answer myself already but found this question that was very helpful: Converting Symbols, Accent Letters to English Alphabet
Have a look at: https://ru.stackoverflow.com/questions/633355/Показать-правильный-пример-транслитерации-на-java
Add denepdency:
And transliterate:
Modify your identifier to do what you want. You can strip unwanted characters using a regular expression with the
Remove
transform.For example, consider the string "'Eé математика":
The identifier
"Any-Latin; NFD; [^\\p{Alnum}] Remove"
will transliterate to Latin (which may still include accents), decompose accented characters into the letter and diacritics and remove anything that isn't an alphanumeric. The resultant string is "Eematematika".You can read more on the identifiers under General Transforms on the ICU website.
Example:
Tested against ICU4J 49.1.
Have no idea about icu4j, but in the Unicode table Cyrillic takes only a small range. Instead of relaying onto third-party libraries with unclear workings, I'd define a transliteration sequence for each Cyrillic symbol and did the translation myself.
P.S. What language word "viljandimaa" comes from? Doesn't sound like Cyrillic to me...