ericnembot / google-api-translate-java

Automatically exported from code.google.com/p/google-api-translate-java
0 stars 0 forks source link

Get the object using its full name #74

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
i want to get the language object using the complete languagae string

example 
with string="german"
i want to get GERMAN Language object...

please suggest some techniques...

Original issue reported on code.google.com by mivaa...@gmail.com on 25 Oct 2009 at 9:38

GoogleCodeExporter commented 8 years ago
You could try something like this:

private Language getLanguage(final String displayLanguage) {
    Locale[] locales = Locale.getAvailableLocales();

    for (Locale locale : locales) {
        if (displayLanguage.equalsIgnoreCase(locale.getDisplayLanguage())) {
            return Language.fromString(locale.getLanguage());
        }
    }

    return null;
}

Original comment by rich.mid...@gmail.com on 6 Nov 2009 at 9:52