I want to create a java.util.Locale object using the display name of the locale. For example, i want the locale of thailand having the value
th_TH
if the display name is
Thai (Thailand)
How to do this?
One way i could think of is to iterate in all the available locales and comparing the display name of each locale with my display name and finding the locale object. But i want to know if there is any smarter way available for this.
If all you have to go on is a display name string, then comparing with display names of available locales is all you can do.
If you will be performing the operation multiple times, then it makes sense to build a Map of locales by display name once and then using that to answer your queries.
Could the display name be in more that one language. For example, could the display name be in French – thaï (Thaïlande)?
If so, you need to do a double loop to query for local display names. In the outer loop, you need to use all locales the language of which may be used to supply a display name.
Here is an example in which the display name may be in the language of any supported locale: