package com.webom.crypt;
import org.apache.commons.lang3.StringEscapeUtils;
import com.ibm.icu.text.Transliterator;
public class Test {
public static String ARABIC_TO_LATIN = "Any-Arabic";
public static String ARABIC_TO_LATIN_NO_ACCENTS = "Arabic-Latin/BGN; nfd; [:nonspacing mark:] remove; nfc";
public static void main(String[] args) {
String ARABICString = "صدام حسين التكريتي";
String unicodeCodes = StringEscapeUtils.escapeJava(ARABICString);
System.out.println("Unicode codes:" + unicodeCodes);
// conversion
Transliterator ARABICToLatinTrans = Transliterator.getInstance(ARABIC_TO_LATIN);
String result1 = ARABICToLatinTrans.transliterate(ARABICString);
System.out.println("ARABIC to Latin:" + result1);
// conversion
Transliterator ARABICToLatinNoAccentsTrans = Transliterator.getInstance(ARABIC_TO_LATIN_NO_ACCENTS);
String result2 = ARABICToLatinNoAccentsTrans.transliterate(ARABICString);
System.out.println("ARABIC to Latin (no accents):" + result2);
}
}
由于实例存在问题,将阿拉伯语转换为拉丁语失败。您能找出正确的实例字符串吗?当你使用谷歌翻译器时,它会显示精确的转换。