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. 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. Maurice Hulsman
    Replies:
    1
    Views:
    1,819
    Guus Bosman
    Jul 25, 2004
  2. Replies:
    4
    Views:
    982
  3. Gabriel Genellina
    Replies:
    0
    Views:
    681
    Gabriel Genellina
    Feb 18, 2009
  4. zade
    Replies:
    1
    Views:
    591
    James Kanze
    Mar 5, 2010
  5. Sibylle Koczian
    Replies:
    2
    Views:
    1,089
    Sibylle Koczian
    Nov 20, 2010
Loading...

Share This Page