20 |
} |
} |
21 |
|
|
22 |
/** |
/** |
23 |
|
* Creates a {@link Translation}<br/> |
24 |
|
* <p> |
25 |
|
* <li>If <code>oneLineCoded</code> is empty or null, NO TRANSLATION is set. |
26 |
|
* <li>If format can't be recognized, the {@link String} is interpreted as |
27 |
|
* the translation in the <code>{@value #DEFAULT_KEY}</code> language |
28 |
|
* |
29 |
|
* @author Stefan Alfons Krüger |
30 |
|
*/ |
31 |
|
public static Translation createFromOneLIne(final String oneLineCoded) { |
32 |
|
Translation result = new Translation(); |
33 |
|
result.fromOneLine(oneLineCoded); |
34 |
|
return result; |
35 |
|
} |
36 |
|
|
37 |
|
/** |
38 |
|
* Returns the Translation to a String of the Format: "de{Baum}en{tree}" <br/> |
39 |
|
* |
40 |
|
* |
41 |
|
* @author Stefan Alfons Krüger |
42 |
|
*/ |
43 |
|
public static String toOneLine(Translation source) { |
44 |
|
StringBuffer oneLine = new StringBuffer(); |
45 |
|
for (String key : source.keySet()) { |
46 |
|
oneLine.append(key + "{" + source.get(key) + "}"); |
47 |
|
} |
48 |
|
return oneLine.toString(); |
49 |
|
} |
50 |
|
|
51 |
|
/** |
52 |
* @author Stefan Alfons Krüger |
* @author Stefan Alfons Krüger |
53 |
* @param code |
* @param code |
54 |
* @return true if the code paramter is a valid ISO Language code |
* @return true if the code paramter is a valid ISO Language code |
73 |
*/ |
*/ |
74 |
public static Locale getLocaleFor(String code) { |
public static Locale getLocaleFor(String code) { |
75 |
for (Locale l : Locale.getAvailableLocales()) { |
for (Locale l : Locale.getAvailableLocales()) { |
76 |
// System.out.println(l.getLanguage()+" not = "+code); |
if (l.getLanguage().equals(code.toLowerCase())) { |
|
if (l.getLanguage().toLowerCase().equals(code.toLowerCase())) { |
|
77 |
return l; |
return l; |
78 |
} |
} |
79 |
|
// LOGGER.debug(l.getLanguage() + " not = " + code); |
80 |
} |
} |
81 |
LOGGER.error("Can't create a Locale for code "+code+"! Returning the system default locale to avoid NPEs."); |
|
82 |
|
LOGGER.error("Can't create a Locale for code " + code |
83 |
|
+ "! Returning the system default locale to avoid NPEs."); |
84 |
|
|
85 |
return Locale.getDefault(); |
return Locale.getDefault(); |
86 |
} |
} |
87 |
|
|
88 |
|
/** |
89 |
|
* A convenience method that checks if the {@link Translation} object |
90 |
|
* contains a translation for the active language. A {@link String} |
91 |
|
* containing only spaces will return <code>false</code>. |
92 |
|
* |
93 |
|
* @param trans |
94 |
|
* {@link Translation} to check. |
95 |
|
*/ |
96 |
|
public static boolean isEmpty(final Translation trans) { |
97 |
|
if (trans == null) |
98 |
|
return true; |
99 |
|
return isEmpty(trans.toString()); |
100 |
|
} |
101 |
|
|
102 |
|
/** |
103 |
|
* A convenience method that checks if the {@link String} returned by from a |
104 |
|
* {@link Translation} object contains a "valid" translation for the active |
105 |
|
* language. A {@link String} containing only spaces or equals |
106 |
|
* {@link Translation}.NO_TRANSLATION will return <code>false</code>. |
107 |
|
* |
108 |
|
* @param transString |
109 |
|
* {@link String} to check. |
110 |
|
*/ |
111 |
|
public static boolean isEmpty(final String transString) { |
112 |
|
if (transString == null) |
113 |
|
return true; |
114 |
|
if (transString.trim().isEmpty()) |
115 |
|
return true; |
116 |
|
if (transString.equals(Translation.NO_TRANSLATION)) |
117 |
|
return true; |
118 |
|
return false; |
119 |
|
} |
120 |
} |
} |