pank
pank

Reputation: 21

How to convert Whole Chinese String to English letters?

Currently I am converting German umlauts by using below code:

String nfdNormalizedString = Normalizer.normalize(displayName, Normalizer.Form.NFD);
Pattern pattern = Pattern.compile("\\p{InCombiningDiacriticalMarks}+");
pattern.matcher(nfdNormalizedString).replaceAll("");

I need to do the same for Chinese Characters; I need to remove this because of comparison of Strings.

Any help will be appreciated.

Upvotes: 1

Views: 2946

Answers (2)

Prokash Sarkar
Prokash Sarkar

Reputation: 11873

The best way to do this would be using the "Google Translate API"

Using this is super easy,

https://www.googleapis.com/language/translate/v2?key=INSERT-YOUR-KEY&q=hello%20world&source=en&target=de

Here,

Key = text to be translated

Source = your source language

Target = your target language

Once you make a GET request it'll return a JSON string containing your result,

{
    "data": {
        "translations": [
            {
                "translatedText": "Hallo Welt"
            }
        ]
    }
}

Here goes the reference link,

https://cloud.google.com/translate/v2/getting_started

Upvotes: 1

Tripesdeporc
Tripesdeporc

Reputation: 94

It it complicated to do the same as with German umlauts, because in German, there is only one character. In chinese, it is the whole language that has special characters.
But if you still want to try it, you can use a chinese to unicode converter and test the characters' unicode to replace it by a latin character.
Check this Chinese to unicode converter if you still have the lust to do this.

Good luck !

Upvotes: 0

Related Questions