44 |
*/ |
*/ |
45 |
public static Locale getLocaleFor(String code) { |
public static Locale getLocaleFor(String code) { |
46 |
for (Locale l : Locale.getAvailableLocales()) { |
for (Locale l : Locale.getAvailableLocales()) { |
47 |
// System.out.println(l.getLanguage()+" not = "+code); |
// System.out.println(l.getLanguage()+" not = "+code); |
48 |
if (l.getLanguage().toLowerCase().equals(code.toLowerCase())) { |
if (l.getLanguage().toLowerCase().equals(code.toLowerCase())) { |
49 |
return l; |
return l; |
50 |
} |
} |
51 |
} |
} |
52 |
LOGGER.error("Can't create a Locale for code "+code+"! Returning the system default locale to avoid NPEs."); |
LOGGER.error("Can't create a Locale for code " + code |
53 |
|
+ "! Returning the system default locale to avoid NPEs."); |
54 |
return Locale.getDefault(); |
return Locale.getDefault(); |
55 |
} |
} |
56 |
|
|
57 |
|
/** |
58 |
|
* A convenience method that checks if the {@link Translation} object |
59 |
|
* contains a translation for the active language. A {@link String} |
60 |
|
* containing only spaces will return <code>false</code>. |
61 |
|
* |
62 |
|
* @param trans |
63 |
|
* {@link Translation} to check. |
64 |
|
*/ |
65 |
|
public static boolean isEmpty(final Translation trans) { |
66 |
|
if (trans == null) |
67 |
|
return true; |
68 |
|
return isEmpty(trans.toString()); |
69 |
|
} |
70 |
|
|
71 |
|
/** |
72 |
|
* A convenience method that checks if the {@link String} returned by from a |
73 |
|
* {@link Translation} object contains a "valid" translation for the active |
74 |
|
* language. A {@link String} containing only spaces or equals |
75 |
|
* {@link Translation}.NO_TRANSLATION will return <code>false</code>. |
76 |
|
* |
77 |
|
* @param transString |
78 |
|
* {@link String} to check. |
79 |
|
*/ |
80 |
|
public static boolean isEmpty(final String transString) { |
81 |
|
if (transString == null) |
82 |
|
return true; |
83 |
|
if (transString.trim().isEmpty()) |
84 |
|
return true; |
85 |
|
if (transString.equals(Translation.NO_TRANSLATION)) |
86 |
|
return true; |
87 |
|
return false; |
88 |
|
} |
89 |
} |
} |