comparing Locales for equality and degree of specificity

T

tom forsmo

Hi

I have the following comparison problem with regards to Locale.

I need to compare two Locales and find out if they are related and which
is more specific than the other. In the same way as a ResourceBundle
finds the most specific resource property file. E.g for

locale 1: nb_NO
locale 2: NO

locale 1 is the most specific of them. locales of two unrelated
countries/languages should be treated as different locales no matter. So

locale 1: nb_NO
locale 2: UK

are different and should not be reported as that instead of locale 1
being more specific.

Any ideas if there is an implementation that does this out there?

tom
 
T

tom forsmo

(A couple of errors fixed:)

Hi

I have the following comparison problem with regards to Locale.

I need to compare two Locales and find out if they are related and which
is more specific than the other. In the same way as a ResourceBundle
finds the most specific resource property file. E.g for

locale 1: nb_NO
locale 2: NO

locale 1 is the most specific of them. Locales for two unrelated
countries/languages should be treated as different locales. So

locale 1: nb_NO
locale 2: UK

are different and should be reported as that instead of locale 1 being
reported as more specific.

Any ideas if there is an implementation that does this out there?

tom
 
I

Ian Wilson

tom said:
Hi

I have the following comparison problem with regards to Locale.

I need to compare two Locales and find out if they are related and which
is more specific than the other. In the same way as a ResourceBundle
finds the most specific resource property file. E.g for

locale 1: nb_NO
locale 2: NO

locale 1 is the most specific of them. locales of two unrelated
countries/languages should be treated as different locales no matter. So

locale 1: nb_NO
locale 2: UK

are different and should not be reported as that instead of locale 1
being more specific.

Any ideas if there is an implementation that does this out there?

No idea sorry.

Isn't it a case of comparing strings?

Of course, you may also have to decide which of the following is "more
specific"
de_CH
fr_CH
fr_FR
fr_FR_Loire

You're saying that region is more "specific" than language, I'm not sure
I agree, surely fr_CH is in some senses more specific than fr_FR.

You might also need to decide if PS is more specific than IL, a
contentious point. How about IM and GB? GS and GB? UM and US?

Maybe your rule is: If one string is a substring of the other then the
longest string is most specific. In which case it ought to be reasonably
straightforward to code.

All the locales on my JVM appear to be of one of three forms:
language
language_REGION
language_REGION_Variation

There are no cases of
REGION
suggesting your NO and UK are unlikely to occur as locales? (UK would
anyway typically be GB in locales)


public class ListLocales {
public static void main(String[] args) {
Locale[] localeList = NumberFormat.getAvailableLocales();
String[] localeStringList = new String[localeList.length];
for (int i = 0; i < localeList.length; i++ ) {
localeStringList = localeList.toString();
}
Arrays.sort(localeStringList);
for (int i = 0; i < localeStringList.length; i++ ) {
System.out.println(localeStringList);
}
}
}

Just my en_GB 0.02 worth
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top