comparing Locales for equality and degree of specificity

Discussion in 'Java' started by tom forsmo, Apr 18, 2007.

  1. tom forsmo

    tom forsmo Guest

    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
     
    tom forsmo, Apr 18, 2007
    #1
    1. Advertising

  2. tom forsmo

    tom forsmo Guest

    (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


    > 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
    >
    >
    >
     
    tom forsmo, Apr 18, 2007
    #2
    1. Advertising

  3. tom forsmo

    Ian Wilson Guest

    tom forsmo wrote:
    > 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
     
    Ian Wilson, Apr 18, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Smith

    comparing doubles for equality

    John Smith, Dec 30, 2006, in forum: C Programming
    Replies:
    12
    Views:
    760
  2. Matt Chwastek
    Replies:
    6
    Views:
    545
    Michael Angelo Ravera
    Nov 20, 2006
  3. Edward Rutherford

    Comparing fp types for equality

    Edward Rutherford, Dec 20, 2011, in forum: C Programming
    Replies:
    12
    Views:
    442
    Rui Maciel
    Dec 20, 2011
  4. Edgardo Hames

    Comparing two files for equality

    Edgardo Hames, Jan 12, 2005, in forum: Ruby
    Replies:
    11
    Views:
    503
    Martin DeMello
    Jan 18, 2005
  5. Jens Thoms Toerring

    Comparing objects for equality

    Jens Thoms Toerring, May 8, 2007, in forum: Perl Misc
    Replies:
    0
    Views:
    110
    Jens Thoms Toerring
    May 8, 2007
Loading...

Share This Page