numerals charcode convert into another language numerals
I want to convert numerals into other language numerals, how can I do this?
I want to be able to support as many languages as possible (google translation supported languages). I've been reading and I believe this can be done from charcode.
Here is some code I copied from some Javascript application, but it only supports 2 languages.
TextTools.arabicNumber = function (str) {
var res = String(str).replace(/([0-9])/g, functi开发者_C百科on (s, n, ofs, all) {
return String.fromCharCode(0x0660 + n * 1);
});
return res;
}
TextTools.farsiNumber = function (str) {
var res = String(str).replace(/([0-9])/g, function (s, n, ofs, all) {
return String.fromCharCode(0x06F0 + n * 1);
});
return res;
}
You've basically solved the problem already, you just need to look at the Unicode standard to find where the other numeral characters exist. You can check out Code Charts or just use Wikipedia for the character ranges. Some interesting things to note, though:
Not every language/culture uses a decimal positional number system, although most extant ones do. You'll want to verify that the number symbols are used the same way as they are in the West to be sure you've got it correct. For all I know, Japanese or Korean numbers are written out using a different system but they use Western numbers in other contexts the same way the West does. You'll need to verify all this to ensure you've got a correctly working system.
But from a technical translation point-of-view, assuming you're just going to convert Western numerals to numerals in another script, you've got it figured out.
ETA: In reference to a comment, consider the case of traditional Hebrew numbers. Numbers are formed as units + tens + hundreds (actually hundreds + tens + units when reading right-to-left). So 456 becomes 400 + 50 + 6, or in Hebrew, תנו.
I am not sure there's going to be a general solution for lots of languages. I don't have a good understanding, but as people have pointed out in the Hebrew discussion, if the characters are different, the ordering or interpretation is probably different. As you learned in grade school, there's a simple translation to Roman numerals, but it's not just a character-to-character transformation. I think you'll need to target specific languages, and consult an expert (or wikipedia) to build out code for each.
I thought maybe google translate would know how to do this, but it looks like they don't from a quick check. Correct me if I'm wrong.
But for the ones that are just transliterations, here are unicode numbers for an assortment of languages: roman numerals, Tamil, Arabic, Devanagari, Bengali, Gurmukhi, Gujarati, Thai, Tibetan, Mongolian, Hangzhou, etc. It's easy to find more using this utility I wrote.
精彩评论