Region / Language Filters
On occasion if you're creating an internationalized (i18n) or multilingual site, you may find it useful to store content which is specific to a particular language or region in your database. DataFaucet provides two convenience methods for creating filters that will handle content containing standard Java-style locale identifiers.
A standard Java locale identifier looks like this:
en_US_TX ↑ ↑ ↑ language | region country
This example shows the identifier for "English as spoken in the fictional Texas region of the United States". I say fictionaly not because Texas isn't real, but because there isn't a standard Java locale for Texas (as far as I know). If I wanted "English as spoken in Canada", I could use "en_CA" or I could use simply "en" to indicate "English - otherwise unspecified".
If you have a table in your database containing these Java-style locale identifiers, the statement object has two convenience functions for fetching content by locale.
FilterLanguage(localeColumn, list): returns all records where the locale column begins with any of the language identifiers in the list. So for example if you specified statement.filterLanguage(localeColumn,"it,es_MX") it would return all records where the locale indicates either Spanish or Italian, in any country. So if your table contained records for es_SP (Spanish as spoken in Spain) and for es_MX (Spanish as spoken in Mexico) it would return all records for both. (The country "MX" in the language list is ignored.)
FilterLocale(localeColumn, locale): returns all records where the locale of the record contains the specified locale. So for example if you specified statement.filterLocale(localeColumn, "en_US_TX") for records relevant to (English as spoken in Texas), it will return records for "en_US_TX" but it will also include records for "en_US" (English as spoken in the United States and for "en" (English - otherwise unspecified). The locale filter will not include any unspecified regions, so if you specified only "en", it would return only records for "English - otherwise unspecified".