com.google.gwt.libideas.server
Class LocaleMatcher

java.lang.Object
  extended by com.google.gwt.libideas.server.LocaleMatcher

public class LocaleMatcher
extends java.lang.Object

A class to choose the best locale given a list of supported locales and an HTTP Accept-Language header.


Constructor Summary
LocaleMatcher(java.io.InputStream localeListStream)
          Construct a locale matcher given a stream with a list of locales, one per line.
 
Method Summary
 java.lang.String findBestMatch(java.lang.String acceptLang)
          Select the best match from the list of available locales.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LocaleMatcher

public LocaleMatcher(java.io.InputStream localeListStream)
              throws java.io.IOException
Construct a locale matcher given a stream with a list of locales, one per line. The stream should be UTF8 (typically just ASCII). The file containing the list of supported locales would commonly be generated by LocaleListLinker.

Parameters:
localeListStream - input stream to read locale list from -- if null, no locales are read.
Throws:
java.io.IOException - if an error occurs reading the stream
Method Detail

findBestMatch

public java.lang.String findBestMatch(java.lang.String acceptLang)
Select the best match from the list of available locales. If no match is found, "default" will be returned. The Accept-Languages header is of the format: locale[;q=number][,locale[;q=number]]* The numbers are priorities between 0 and 1, with a higher value indicating higher preference. Note that Accept-Language locale identifiers only include a language and a country code, and they are separated by dashes not underscores.

Parameters:
acceptLang - the Accept-Languages header
Returns:
the selected locale name