Revision 44881 trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.i18n/src/main/java/org/gvsig/i18n/Messages.java
Messages.java | ||
---|---|---|
39 | 39 |
import java.util.Locale; |
40 | 40 |
import java.util.Properties; |
41 | 41 |
import java.util.Set; |
42 |
import org.gvsig.tools.util.URLUtils; |
|
42 | 43 |
|
43 | 44 |
import org.slf4j.Logger; |
44 | 45 |
import org.slf4j.LoggerFactory; |
... | ... | |
423 | 424 |
} |
424 | 425 |
} |
425 | 426 |
|
426 |
private static void addResourceFamily(Locale lang, Properties translations, |
|
427 |
String family, ClassLoader loader, String callerName) { |
|
428 |
logger.debug("addResourceFamily "+lang.toString()+", "+family+", "+loader.toString()); |
|
429 |
|
|
430 |
Properties properties = new Properties(); |
|
431 |
String langCode = lang.toString(); |
|
432 |
String resource = family.replace('.', '/') + "_" + langCode + ".properties"; |
|
433 |
URL resourceURL = loader.getResource(resource); |
|
434 |
InputStream is = loader.getResourceAsStream(resource); |
|
435 |
if( is==null && langCode.contains("_") ) { |
|
436 |
try { |
|
437 |
langCode = langCode.split("_")[0]; |
|
438 |
resource = family.replace('.', '/') + "_" + langCode + ".properties"; |
|
439 |
resourceURL = loader.getResource(resource); |
|
440 |
is = loader.getResourceAsStream(resource); |
|
441 |
if( is==null ) { |
|
442 |
resource = family.replace('.', '/') + ".properties"; |
|
443 |
resourceURL = loader.getResource(resource); |
|
444 |
is = loader.getResourceAsStream(resource); |
|
445 |
} |
|
446 |
} catch(Exception ex) { |
|
447 |
// Do nothing, is are null and are handled later |
|
448 |
} |
|
449 |
} |
|
450 |
if (is != null) { |
|
451 |
try { |
|
452 |
properties.load(is); |
|
453 |
} catch (IOException e) { |
|
454 |
} |
|
455 |
} else if (lang.equals(baseLocale)) { |
|
456 |
// try also "text.properties" for the base language |
|
457 |
is = loader.getResourceAsStream(family.replace('.', '/') |
|
458 |
+ ".properties"); |
|
427 |
private static void addResourceFamily(Locale lang, Properties translations, |
|
428 |
String family, ClassLoader loader, String callerName) { |
|
429 |
logger.debug("addResourceFamily " + lang.toString() + ", " + family + ", " + loader.toString()); |
|
459 | 430 |
|
431 |
Properties properties = new Properties(); |
|
432 |
String langCode = lang.toString(); |
|
433 |
String resource = family.replace('.', '/') + "_" + langCode + ".properties"; |
|
434 |
URL resourceURL = loader.getResource(resource); |
|
435 |
// InputStream is = loader.getResourceAsStream(resource); |
|
436 |
InputStream is = URLUtils.openStream(resourceURL); |
|
437 |
if (is == null && langCode.contains("_")) { |
|
438 |
try { |
|
439 |
langCode = langCode.split("_")[0]; |
|
440 |
resource = family.replace('.', '/') + "_" + langCode + ".properties"; |
|
441 |
resourceURL = loader.getResource(resource); |
|
442 |
// is = loader.getResourceAsStream(resource); |
|
443 |
is = URLUtils.openStream(resourceURL); |
|
444 |
if (is == null) { |
|
445 |
resource = family.replace('.', '/') + ".properties"; |
|
446 |
resourceURL = loader.getResource(resource); |
|
447 |
// is = loader.getResourceAsStream(resource); |
|
448 |
is = URLUtils.openStream(resourceURL); |
|
449 |
} |
|
450 |
} catch (Exception ex) { |
|
451 |
// Do nothing, is are null and are handled later |
|
452 |
} |
|
453 |
} |
|
454 |
if (is != null) { |
|
455 |
try { |
|
456 |
properties.load(is); |
|
457 |
} catch (IOException e) { |
|
458 |
} |
|
459 |
} else if (lang.equals(baseLocale)) { |
|
460 |
// try also "text.properties" for the base language |
|
461 |
resource = family.replace('.', '/') + ".properties"; |
|
462 |
resourceURL = loader.getResource(resource); |
|
463 |
is = URLUtils.openStream(resourceURL); |
|
464 |
// is = loader.getResourceAsStream(family.replace('.', '/') + ".properties"); |
|
460 | 465 |
|
461 |
if (is != null) {
|
|
462 |
try {
|
|
463 |
properties.load(is);
|
|
464 |
} catch (IOException e) {
|
|
465 |
}
|
|
466 |
}
|
|
466 |
if (is != null) {
|
|
467 |
try {
|
|
468 |
properties.load(is);
|
|
469 |
} catch (IOException e) {
|
|
470 |
}
|
|
471 |
}
|
|
467 | 472 |
|
468 |
}
|
|
469 |
if( resourceURL!=null && logger.isDebugEnabled() ) {
|
|
470 |
logger.debug("Load resources from '"+resourceURL.toString()+"' with classloader {"+loader.toString()+"}.");
|
|
471 |
}
|
|
472 |
Enumeration keys = properties.keys();
|
|
473 |
while (keys.hasMoreElements()) {
|
|
474 |
String currentKey = (String) keys.nextElement();
|
|
475 |
if (!translations.containsKey(currentKey)) {
|
|
476 |
translations.put(currentKey, properties.getProperty(currentKey));
|
|
477 |
}
|
|
478 |
}
|
|
473 |
}
|
|
474 |
if (resourceURL != null && logger.isDebugEnabled()) {
|
|
475 |
logger.debug("Load resources from '" + resourceURL.toString() + "' with classloader {" + loader.toString() + "}.");
|
|
476 |
} |
|
477 |
Enumeration keys = properties.keys();
|
|
478 |
while (keys.hasMoreElements()) {
|
|
479 |
String currentKey = (String) keys.nextElement();
|
|
480 |
if (!translations.containsKey(currentKey)) {
|
|
481 |
translations.put(currentKey, properties.getProperty(currentKey));
|
|
482 |
}
|
|
483 |
}
|
|
479 | 484 |
|
480 |
}
|
|
485 |
}
|
|
481 | 486 |
|
482 | 487 |
/** |
483 | 488 |
* <p>Adds an additional family of resource files containing some translations.</p> |
Also available in: Unified diff