Skip to content

Commit 9c47f0c

Browse files
committed
Updated locale handling
1 parent b3e727d commit 9c47f0c

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

lib/xmljava.jar

11 Bytes
Binary file not shown.

src/com/maxprograms/xml/Messages.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,22 @@ private Messages() {
2727
}
2828

2929
public static String getString(String key) {
30+
String resourceName = "xmljava";
3031
try {
3132
if (props == null) {
3233
Locale locale = Locale.getDefault();
33-
String extension = "en".equals(locale.getLanguage()) ? ".properties"
34-
: "_" + locale.getLanguage() + ".properties";
35-
if (Messages.class.getResource("xmljava" + extension) == null) {
34+
String language = locale.getLanguage();
35+
String extension = "_" + language + ".properties";
36+
// check if there is a resource for full language code
37+
if (Messages.class.getResource(resourceName + extension) == null) {
38+
// if not, check if there is a resource for language only
39+
extension = "_" + language.substring(0, 2) + ".properties";
40+
}
41+
if (Messages.class.getResource(resourceName + extension) == null) {
42+
// if not, use the default resource
3643
extension = ".properties";
3744
}
38-
try (InputStream is = Messages.class.getResourceAsStream("xmljava" + extension)) {
45+
try (InputStream is = Messages.class.getResourceAsStream(resourceName + extension)) {
3946
try (InputStreamReader reader = new InputStreamReader(is, StandardCharsets.UTF_8)) {
4047
props = new Properties();
4148
props.load(reader);

0 commit comments

Comments
 (0)