check locale string

This commit is contained in:
Keith Woodlock
2012-05-29 02:18:49 +01:00
parent 442b9d93d0
commit 2e5a68fb41
@@ -119,26 +119,29 @@ public class ApiDataConversionServiceImpl implements ApiDataConversionService {
Locale locale = Locale.getDefault(); Locale locale = Locale.getDefault();
String[] localeParts = localeAsString.split("_"); if (StringUtils.isNotBlank(localeAsString)) {
String language = "en"; String[] localeParts = localeAsString.split("_");
String country = "GB";
String variant = "";
if (localeParts != null && localeParts.length == 1) {
language = localeParts[0];
locale = new Locale(language);
}
if (localeParts != null && localeParts.length == 2) { String language = "en";
language = localeParts[0]; String country = "GB";
country = localeParts[1]; String variant = "";
locale = new Locale(language, country); if (localeParts != null && localeParts.length == 1) {
} language = localeParts[0];
locale = new Locale(language);
}
if (localeParts != null && localeParts.length == 3) { if (localeParts != null && localeParts.length == 2) {
language = localeParts[0]; language = localeParts[0];
country = localeParts[1]; country = localeParts[1];
variant = localeParts[2]; locale = new Locale(language, country);
locale = new Locale(language, country, variant); }
if (localeParts != null && localeParts.length == 3) {
language = localeParts[0];
country = localeParts[1];
variant = localeParts[2];
locale = new Locale(language, country, variant);
}
} }
return locale; return locale;