How do I choose best locale from a specific list?

Discussion in 'Java' started by SBC Global News Server, Sep 22, 2003.

  1. I have a situation in which given a specific locale I need to know which
    locale from a specific list it best matches. Can anyone suggest a simple
    and effective approach?

    The reason for this is I have some code which uses a Locale object to
    determine what to do. As this code only supports a limited number of
    specific locales I must only pass it a locale it likes. Think of it as a
    locale being used in a switch like statement. (For purposes of brevity I
    won't go into all the reasons I have intentionally done what is probably a
    very unusual thing.)

    One kludgey approach I have considered is to create a resource bundle with
    defined resources for only the specific list of locales plus one for the
    default locale. I can then associate a different value for a single
    specific key with each resource (be it a properties file or a subclass of
    java.util.ResourceBundle).

    What I would prefer would be something like the following:

    List localeList = new ArrayList();
    localeList.add(Locale.US);
    localeList.add(Locale.UK);
    localeList.add(Locale.GERMANY);

    Locale defaultLocale = Locale.US;

    LocaleDecider localeDecider = new LocaleDecider(localeList, defaultLocale);

    Locale someLocaleTakenFromHTTPRequestHeader = Locale.FRANCE;

    Locale bestLocaleChoice =
    localeDecider.findBestLocale(someLocaleTakenFromHTTPRequestHeader);

    //bestLocaleChoice will be either Locale.US, Locale.UK or Locale.GERMANY.
    //The algorithm for deciding which to use should be similar to the way
    //a resource bundle works.

    Thank you for your time and effort in reading and possibly responding to
    this posting.

    Sincerely,
    James Carpenter
    ve me.com
     
    SBC Global News Server, Sep 22, 2003
    #1
    1. Advertisements

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. Gelmir Tinehtelë
    Replies:
    10
    Views:
    870
    Aidan
    Jun 9, 2004
  2. Maurice Hulsman
    Replies:
    1
    Views:
    2,241
    Guus Bosman
    Jul 25, 2004
  3. Mike Conmackie
    Replies:
    2
    Views:
    1,851
    Michael Wojcik
    Oct 13, 2004
  4. Yuan HOng

    Locale-specific string comparasion

    Yuan HOng, Jul 26, 2007, in forum: Python
    Replies:
    0
    Views:
    329
    Yuan HOng
    Jul 26, 2007
  5. Replies:
    4
    Views:
    1,356
  6. zade
    Replies:
    1
    Views:
    939
    James Kanze
    Mar 5, 2010
  7. Sibylle Koczian
    Replies:
    2
    Views:
    1,388
    Sibylle Koczian
    Nov 20, 2010
  8. Masao Mutoh
    Replies:
    0
    Views:
    226
    Masao Mutoh
    Dec 4, 2008
Loading...