check locale string

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