Okay,
So my problem is that I have a XML Tamil (unicode) feed, I want to take this and display it in an Android application.
When I attempt to do this, due to Android not having native support for Tamil, a custom font must be used.
But then the issue comes up cause the rendering in unicode is completely different. How do I solve this?
How I solved this is,
I first mapped the unicode to to the font Bamini with the help of http://www.ucsc.cmb.ac.lk/ltrl/services/feconverter/.
Then it was a matter of just replacing the unicode character with the Bamini character. I send the text into that function and display it using the Bamini font.
public static String initialize(String text) {
text = text.replace("ஸ்ரீ", "=");
text = text.replace(",", ">");
text = text.replace("ஜௌ", "n[s");
text = text.replace("ஜோ", "N[h");
text = text.replace("ஜொ", "n[h");
text = text.replace("ஜா", "[h");
text = text.replace("ஜி", "[p");
text = text.replace("ஜீ", "[P");
text = text.replace("ஜு", "[{");
text = text.replace("ஜூ", "[_");
text = text.replace("ஜெ", "n[");
text = text.replace("ஜே", "N[");
text = text.replace("ஜை", "i[");
text = text.replace("ஜ்", "[;");
text = text.replace("ஜ", "[");
text = text.replace("கௌ", "nfs");
text = text.replace("கோ", "Nfh");
text = text.replace("கொ", "nfh");
text = text.replace("கா", "fh");
text = text.replace("கி", "fp");
text = text.replace("கீ", "fP");
text = text.replace("கு", "F");
text = text.replace("கூ", "$");
text = text.replace("கெ", "nf");
text = text.replace("கே", "Nf");
text = text.replace("கை", "if");
text = text.replace("க்", "f;");
text = text.replace("க", "f");
text = text.replace("ஙௌ", "nqs");
text = text.replace("ஙோ", "Nqh");
text = text.replace("ஙொ", "nqh");
text = text.replace("ஙா", "qh");
text = text.replace("ஙி", "qp");
text = text.replace("ஙீ", "qP");
text = text.replace("ஙு", "*");
text = text.replace("ஙூ", "*");
text = text.replace("ஙெ", "nq");
text = text.replace("ஙே", "Nq");
text = text.replace("ஙை", "iq");
text = text.replace("ங்", "q;");
text = text.replace("ங", "q");
text = text.replace("சௌ", "nrs");
text = text.replace("சோ", "Nrh");
text = text.replace("சொ", "nrh");
text = text.replace("சா", "rh");
text = text.replace("சி", "rp");
text = text.replace("சீ", "rP");
text = text.replace("சு", "R");
text = text.replace("சூ", "R+");
text = text.replace("செ", "nr");
text = text.replace("சே", "Nr");
text = text.replace("சை", "ir");
text = text.replace("ச்", "r;");
text = text.replace("ச", "r");
text = text.replace("ஞௌ", "nQs");
text = text.replace("ஞோ", "NQh");
text = text.replace("ஞொ", "nQh");
text = text.replace("ஞா", "Qh");
text = text.replace("ஞி", "Qp");
text = text.replace("ஞீ", "QP");
text = text.replace("ஞு", "*");
text = text.replace("ஞூ", "*");
text = text.replace("ஞெ", "nQ");
text = text.replace("ஞே", "NQ");
text = text.replace("ஞை", "iQ");
text = text.replace("ஞ்", "Q;");
text = text.replace("ஞ", "Q");
text = text.replace("டௌ", "nls");
text = text.replace("டோ", "Nlh");
text = text.replace("டொ", "nlh");
text = text.replace("டா", "lh");
text = text.replace("டி", "b");
text = text.replace("டீ", "B");
text = text.replace("டு", "L");
text = text.replace("டூ", "^");
text = text.replace("டெ", "nl");
text = text.replace("டே", "Nl");
text = text.replace("டை", "il");
text = text.replace("ட்", "l;");
text = text.replace("ட", "l");
text = text.replace("ணௌ", "nzs");
text = text.replace("ணோ", "Nzh");
text = text.replace("ணொ", "nzh");
text = text.replace("ணா", "zh");
text = text.replace("ணி", "zp");
text = text.replace("ணீ", "zP");
text = text.replace("ணு", "Z");
text = text.replace("ணூ", "Z}");
text = text.replace("ணெ", "nz");
text = text.replace("ணே", "Nz");
text = text.replace("ணை", "iz");
text = text.replace("ண்", "z;");
text = text.replace("ண", "z");
text = text.replace("தௌ", "njs");
text = text.replace("தோ", "Njh");
text = text.replace("தொ", "njh");
text = text.replace("தா", "jh");
text = text.replace("தி", "jp");
text = text.replace("தீ", "jP");
text = text.replace("து", "J");
text = text.replace("தூ", "J}");
text = text.replace("தெ", "nj");
text = text.replace("தே", "Nj");
text = text.replace("தை", "ij");
text = text.replace("த்", "j;");
text = text.replace("த", "j");
text = text.replace("நௌ", "nes");
text = text.replace("நோ", "Neh");
text = text.replace("நொ", "neh");
text = text.replace("நா", "eh");
text = text.replace("நி", "ep");
text = text.replace("நீ", "eP");
text = text.replace("நு", "E");
text = text.replace("நூ", "E}");
text = text.replace("நெ", "ne");
text = text.replace("நே", "Ne");
text = text.replace("நை", "ie");
text = text.replace("ந்", "e;");
text = text.replace("ந", "e");
text = text.replace("னௌ", "nds");
text = text.replace("னோ", "Ndh");
text = text.replace("னொ", "ndh");
text = text.replace("னா", "dh");
text = text.replace("னி", "dp");
text = text.replace("னீ", "dP");
text = text.replace("னு", "D");
text = text.replace("னூ", "D}");
text = text.replace("னெ", "nd");
text = text.replace("னே", "Nd");
text = text.replace("னை", "id");
text = text.replace("ன்", "d;");
text = text.replace("ன", "d");
text = text.replace("பௌ", "ngs");
text = text.replace("போ", "Ngh");
text = text.replace("பொ", "ngh");
text = text.replace("பா", "gh");
text = text.replace("பி", "gp");
text = text.replace("பீ", "gP");
text = text.replace("பு", "G");
text = text.replace("பூ", "G+");
text = text.replace("பெ", "ng");
text = text.replace("பே", "Ng");
text = text.replace("பை", "ig");
text = text.replace("ப்", "g;");
text = text.replace("ப", "g");
text = text.replace("மௌ", "nks");
text = text.replace("மோ", "Nkh");
text = text.replace("மொ", "nkh");
text = text.replace("மா", "kh");
text = text.replace("மி", "kp");
text = text.replace("மீ", "kP");
text = text.replace("மு", "K");
text = text.replace("மூ", "%");
text = text.replace("மெ", "nk");
text = text.replace("மே", "Nk");
text = text.replace("மை", "ik");
text = text.replace("ம்", "k;");
text = text.replace("ம", "k");
text = text.replace("யௌ", "nas");
text = text.replace("யோ", "Nah");
text = text.replace("யொ", "nah");
text = text.replace("யா", "ah");
text = text.replace("யி", "ap");
text = text.replace("யீ", "aP");
text = text.replace("யு", "A");
text = text.replace("யூ", "A+");
text = text.replace("யெ", "na");
text = text.replace("யே", "Na");
text = text.replace("யை", "ia");
text = text.replace("ய்", "a;");
text = text.replace("ய", "a");
text = text.replace("ரௌ", "nus");
text = text.replace("ரோ", "Nuh");
text = text.replace("ரொ", "nuh");
text = text.replace("ரா", "uh");
text = text.replace("ரி", "up");
text = text.replace("ரீ", "uP");
text = text.replace("ரு", "U");
text = text.replace("ரூ", "&");
text = text.replace("ரெ", "nu");
text = text.replace("ரே", "Nu");
text = text.replace("ரை", "iu");
text = text.replace("ர்", "u;");
text = text.replace("ர", "u");
text = text.replace("லௌ", "nys");
text = text.replace("லோ", "Nyh");
text = text.replace("லொ", "nyh");
text = text.replace("லா", "yh");
text = text.replace("லி", "yp");
text = text.replace("லீ", "yP");
text = text.replace("லு", "Y");
text = text.replace("லூ", "Y}");
text = text.replace("லெ", "ny");
text = text.replace("லே", "Ny");
text = text.replace("லை", "iy");
text = text.replace("ல்", "y;");
text = text.replace("ல", "y");
text = text.replace("ளௌ", "nss");
text = text.replace("ளோ", "Nsh");
text = text.replace("ளொ", "nsh");
text = text.replace("ளா", "sh");
text = text.replace("ளி", "sp");
text = text.replace("ளீ", "sP");
text = text.replace("ளு", "S");
text = text.replace("ளூ", "Sh");
text = text.replace("ளெ", "ns");
text = text.replace("ளே", "Ns");
text = text.replace("ளை", "is");
text = text.replace("ள்", "s;");
text = text.replace("ள", "s");
text = text.replace("வௌ", "nts");
text = text.replace("வோ", "Nth");
text = text.replace("வொ", "nth");
text = text.replace("வா", "th");
text = text.replace("வி", "tp");
text = text.replace("வீ", "tP");
text = text.replace("வு", "T");
text = text.replace("வூ", "T+");
text = text.replace("வெ", "nt");
text = text.replace("வே", "Nt");
text = text.replace("வை", "it");
text = text.replace("வ்", "t;");
text = text.replace("வ", "t");
text = text.replace("ழௌ", "nos");
text = text.replace("ழோ", "Noh");
text = text.replace("ழொ", "noh");
text = text.replace("ழா", "oh");
text = text.replace("ழி", "op");
text = text.replace("ழீ", "oP");
text = text.replace("ழு", "O");
text = text.replace("ழூ", "*");
text = text.replace("ழெ", "no");
text = text.replace("ழே", "No");
text = text.replace("ழை", "io");
text = text.replace("ழ்", "o;");
text = text.replace("ழ", "o");
text = text.replace("றௌ", "nws");
text = text.replace("றோ", "Nwh");
text = text.replace("றொ", "nwh");
text = text.replace("றா", "wh");
text = text.replace("றி", "wp");
text = text.replace("றீ", "wP");
text = text.replace("று", "W");
text = text.replace("றூ", "W}");
text = text.replace("றெ", "nw");
text = text.replace("றே", "Nw");
text = text.replace("றை", "iw");
text = text.replace("ற்", "w;");
text = text.replace("ற", "w");
text = text.replace("ஹௌ", "n`s");
text = text.replace("ஹோ", "N`h");
text = text.replace("ஹொ", "n`h");
text = text.replace("ஹா", "`h");
text = text.replace("ஹி", "`p");
text = text.replace("ஹீ", "`P");
text = text.replace("ஹு", "{`");
text = text.replace("ஹூ", "`_");
text = text.replace("ஹெ", "n`");
text = text.replace("ஹே", "N`");
text = text.replace("ஹை", "i`");
text = text.replace("ஹ்", "`;");
text = text.replace("ஹ", "`");
text = text.replace("ஷௌ", "n\\s");
text = text.replace("ஷோ", "N\\h");
text = text.replace("ஷொ", "n\\h");
text = text.replace("ஷா", "\\h");
text = text.replace("ஷி", "\\p");
text = text.replace("ஷீ", "\\P");
text = text.replace("ஷு", "\\{");
text = text.replace("ஷூ", "\\_");
text = text.replace("ஷெ", "n\\");
text = text.replace("ஷே", "N\\");
text = text.replace("ஷை", "i\\");
text = text.replace("ஷ்", "\\;");
text = text.replace('ஷ', '\\');
text = text.replace("ஸௌ", "n]s");
text = text.replace("ஸோ", "N]h");
text = text.replace("ஸொ", "n]h");
text = text.replace("ஸா", "]h");
text = text.replace("ஸி", "]p");
text = text.replace("ஸீ", "]P");
text = text.replace("ஸு", "]{");
text = text.replace("ஸூ", "]_");
text = text.replace("ஸெ", "n]");
text = text.replace("ஸே", "N]");
text = text.replace("ஸை", "i]");
text = text.replace("ஸ்", "];");
text = text.replace("ஸ", "]");
text = text.replace("அ", "m");
text = text.replace("ஆ", "M");
text = text.replace("இ", "");
text = text.replace("ஈ", "<");
text = text.replace("உ", "c");
text = text.replace("ஊ", "C");
text = text.replace("எ", "v");
text = text.replace("ஏ", "V");
text = text.replace("ஐ", "I");
text = text.replace("ஒ", "x");
text = text.replace("ஓ", "X");
text = text.replace("ஔ", "xs");
return text = text.replace("ஃ", "/");
}
The problem when using Bamini
is that it won't let you mix up Tamil and English strings together. It'll convert everything to Tamil. As the result, English strings will look ridiculous.
For an Example if you say என் பேர் மயூரேசன் (Mayooresan)
, it'll be converted as என் பேர் மயூரேசன் (அயலழழசநளயn)
So I would recomend you to use TSCII
, TAB
or TAM
fonts.
If you like to convert dynamically I would encourage you to check out the free library I wrote to convert encoding dynamically. Once you import the library all you have to do is just this.
// Initialise the Typeface (assumes TSCII, Bamini, Anjal, TAB or TAM font located inside assets/fonts folder)
Typeface tf = Typeface.createFromAsset(getAssets(),"fonts/mylai.ttf");
// Initialises the TextView
TextView tv = (TextView)findViewById(R.id.textView1);
//Setting the Typeface
tv.setTypeface(tf);
//Magic happens here ;) encoding conversion
String TSCIIString = TamilUtil.convertToTamil(TamilUtil.TSCII, "வணக்கம் அன்ரொயிட்");
//Setting the new string to TextView
tv.setText(TSCIIString);
来源:https://stackoverflow.com/questions/8486344/how-do-i-render-tamil-unicode-in-android