Note that there are some explanatory texts on larger screens.

plurals
  1. POTransliteration from Cyrillic to Latin ICU4j java
    text
    copied!<p>I need to do something rather simple but without hash mapping hard coding.</p> <p>I have a String s and it is in Cyrillic I need some sort of example on how to turn it into Latin characters using a custom filter of a sort (to give a purely Latin example as to not confuse anyone if String s = sniff; I want it to look up s-n-i-f-f and change them into something else (there might also be combinations).</p> <p>I can see that ICU4j can do this sort of thing but I have no idea how to achieve it as I can't find any working examples (or I'm just stupid).</p> <p>Any help is appreciated. </p> <p>Thanks</p> <p>Best Regards,</p> <p>PS I need a batch translate. I don't care about styles or dynamic transliteration just some basic example on what a ICU4j batch transliterator would look like. </p> <p>K I actually got it.</p> <pre><code>import com.ibm.icu.text.Transliterator; public class BulgarianToLatin { public static String BULGARIAN_TO_LATIN = "Bulgarian-Latin/BGN"; public static void main(String[] args) { String bgString = "Джокович"; Transliterator bulgarianToLatin = Transliterator.getInstance(BULGARIAN_TO_LATIN); String result1 = bulgarianToLatin.transliterate(bgString); System.out.println("Bulgarian to Latin:" + result1); } } </code></pre> <p>Also one last edit for a rule based transliteration ( if you do not wish to use the pre-existing once or just want something custom made )</p> <pre><code>import com.ibm.icu.text.Transliterator; public class BulgarianToLatin { public static String BULGARIAN_TO_LATIN = "Bulgarian-Latin/BGN"; public static void main(String[] args) { String bgString = "а б в г д е ж з и й к л м н о п р с т у ф х ц ч ш щ ю я \n Юлиян Джокович"; String rules="::[А-ЪЬЮ-ъьюяѢѣѪѫ];" + "Б &gt; B;" + "б &gt; b;" + "В &gt; V;" + "ТС &gt; TS;" + "Тс &gt; Ts;" + "ч &gt; ch;" + "ШТ &gt; SHT;" + "Шт &gt; Sht;" + "шт &gt; sht;" + "{Ш}[[б-джзй-нп-тф-щь][аеиоуъюяѣѫ]] &gt; Sh;" + "Я &gt; YA;" + "я &gt; ya;"; Transliterator bulgarianToLatin = Transliterator.createFromRules("temp", rules, Transliterator.FORWARD); String result1 = bulgarianToLatin.transliterate(bgString); System.out.println("Bulgarian to Latin:" + result1); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload