1
package org.herac.tuxguitar.gui.system.language;
3
import java.io.IOException;
5
import java.util.Enumeration;
6
import java.util.Locale;
7
import java.util.Properties;
9
public class TGResourceBundle {
11
private Locale locale;
12
private Properties properties;
14
public TGResourceBundle(Locale locale, Properties properties){
16
this.properties = properties;
19
public Locale getLocale() {
23
public void setLocale(Locale locale) {
27
public String getString(String key) {
28
return this.properties.getProperty(key);
31
public static TGResourceBundle getBundle(String baseName, Locale locale,ClassLoader loader){
32
Properties properties = new Properties();
34
String bundleName = baseName.replace('.','/');
35
String bundleExtension = ".properties";
38
TGResourceBundle.loadResources( (bundleName + bundleExtension ), properties, loader);
42
if(locale.getLanguage() != null && locale.getLanguage().length() > 0){
43
bundleName += locale.getLanguage();
44
TGResourceBundle.loadResources( (bundleName + bundleExtension ), properties, loader);
49
if(locale.getCountry() != null && locale.getCountry().length() > 0){
50
bundleName += locale.getCountry();
51
TGResourceBundle.loadResources( (bundleName + bundleExtension ), properties, loader);
56
if(locale.getVariant() != null && locale.getVariant().length() > 0){
57
bundleName += locale.getVariant();
58
TGResourceBundle.loadResources( (bundleName + bundleExtension ), properties, loader);
61
return new TGResourceBundle(locale, properties);
64
private static void loadResources(String name, Properties p, ClassLoader loader){
66
Enumeration enumeration = loader.getResources(name);
67
while (enumeration.hasMoreElements()) {
68
URL url = (URL) enumeration.nextElement();
69
Properties properties = new Properties();
70
properties.load( url.openStream() );
73
} catch (IOException e) {