Charcode digits convert to other langauge digits

I want to convert numbers to numbers in another language, how can I do this?

I want to be able to support as many languages โ€‹โ€‹as possible (languages โ€‹โ€‹that support Google translation). I read, and I believe that this can be done using charcode.

Here is the 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, function (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; } 
+6
source share
2 answers

You basically solved the problem, you just need to look at the Unicode standard to find where other numeric characters exist. You can check the Code Charts or just use Wikipedia for character ranges. It is interesting to note that:

Not every language / culture uses a decimal system of positional numbers, although most of them exist. You will need to make sure that the numeric characters are used in the same way as in the West, to make sure that you have it right. To my knowledge, Japanese or Korean numbers are written using a different system, but they use Western numbers in other contexts in the same way as the West does. You will need to check all this to make sure that your system is working properly.

But from a technical point of view of the translation, assuming that you are just going to convert Western numbers to numbers in another script, you understand this.

ETA:. For commentary, consider the case of traditional Jewish numbers . Numbers are formed as units + tens + hundreds (actually hundreds + tens + units when reading from right to left). Thus, 456 becomes 400 + 50 + 6, or in Hebrew, ืชื ื•.

+9
source

I am not sure if this will be a common solution for many languages. I donโ€™t have a good understanding, but, as people said in Hebrew, if the characters are different, the order or interpretation is probably different. As you learned in high school, there is a simple translation into Roman numerals, but it is not just a conversion of characters to characters. I think you need to target certain languages โ€‹โ€‹and contact an expert (or Wikipedia) to create code for each of them.

I thought that maybe google translate would know how to do this, but it looks like they are not doing a quick check . Correct me if I am wrong.

But for those that are just transliterations, Unicode numbers for a set of languages โ€‹โ€‹are listed here: Roman numerals , Tamil , Arabic , Devanagari , Bengali , Gurmukhi , Gujarati , Thai , Tibetan , Mongolian , Hangzhou , etc. It is easy to find more with this utility that I wrote.

+2
source

Source: https://habr.com/ru/post/893662/


All Articles