mirror of
				https://github.com/mcMMO-Dev/mcMMO.git
				synced 2025-11-04 02:53:43 +01:00 
			
		
		
		
	Added a way to add new localization files
This commit is contained in:
		@@ -1,6 +1,8 @@
 | 
				
			|||||||
package com.gmail.nossr50.locale;
 | 
					package com.gmail.nossr50.locale;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import java.text.MessageFormat;
 | 
					import java.text.MessageFormat;
 | 
				
			||||||
 | 
					import java.util.ArrayList;
 | 
				
			||||||
 | 
					import java.util.List;
 | 
				
			||||||
import java.util.Locale;
 | 
					import java.util.Locale;
 | 
				
			||||||
import java.util.MissingResourceException;
 | 
					import java.util.MissingResourceException;
 | 
				
			||||||
import java.util.ResourceBundle;
 | 
					import java.util.ResourceBundle;
 | 
				
			||||||
@@ -12,6 +14,8 @@ import com.gmail.nossr50.config.Config;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
public final class LocaleLoader {
 | 
					public final class LocaleLoader {
 | 
				
			||||||
    private static final String BUNDLE_ROOT = "com.gmail.nossr50.locale.locale";
 | 
					    private static final String BUNDLE_ROOT = "com.gmail.nossr50.locale.locale";
 | 
				
			||||||
 | 
					    private static List<ResourceBundle> bundles = new ArrayList<ResourceBundle>();
 | 
				
			||||||
 | 
					    private static List<ResourceBundle> defaultBundles = new ArrayList<ResourceBundle>();
 | 
				
			||||||
    private static ResourceBundle bundle = null;
 | 
					    private static ResourceBundle bundle = null;
 | 
				
			||||||
    private static ResourceBundle enBundle = null;
 | 
					    private static ResourceBundle enBundle = null;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -33,6 +37,16 @@ public final class LocaleLoader {
 | 
				
			|||||||
            initialize();
 | 
					            initialize();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        for(ResourceBundle bundle : bundles) {
 | 
				
			||||||
 | 
					        	if(bundle.containsKey(key)) {
 | 
				
			||||||
 | 
					        		return getString(key, bundle, messageArguments);
 | 
				
			||||||
 | 
					        	}
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        for(ResourceBundle bundle : defaultBundles) {
 | 
				
			||||||
 | 
					        	if(bundle.containsKey(key)) {
 | 
				
			||||||
 | 
					        		return getString(key, bundle, messageArguments);
 | 
				
			||||||
 | 
					        	}
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
            return getString(key, bundle, messageArguments);
 | 
					            return getString(key, bundle, messageArguments);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@@ -75,6 +89,14 @@ public final class LocaleLoader {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    private static void initialize() {
 | 
					    private static void initialize() {
 | 
				
			||||||
        if (bundle == null) {
 | 
					        if (bundle == null) {
 | 
				
			||||||
 | 
					            Locale locale = getLocalFromConfig();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            bundle = ResourceBundle.getBundle(BUNDLE_ROOT, locale);
 | 
				
			||||||
 | 
					            enBundle = ResourceBundle.getBundle(BUNDLE_ROOT, Locale.US);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						private static Locale getLocalFromConfig() {
 | 
				
			||||||
		Locale.setDefault(new Locale("en", "US"));
 | 
							Locale.setDefault(new Locale("en", "US"));
 | 
				
			||||||
		Locale locale = null;
 | 
							Locale locale = null;
 | 
				
			||||||
		String[] myLocale = Config.getInstance().getLocale().split("[-_ ]");
 | 
							String[] myLocale = Config.getInstance().getLocale().split("[-_ ]");
 | 
				
			||||||
@@ -85,10 +107,13 @@ public final class LocaleLoader {
 | 
				
			|||||||
		else if (myLocale.length >= 2) {
 | 
							else if (myLocale.length >= 2) {
 | 
				
			||||||
		    locale = new Locale(myLocale[0], myLocale[1]);
 | 
							    locale = new Locale(myLocale[0], myLocale[1]);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
							return locale;
 | 
				
			||||||
            bundle = ResourceBundle.getBundle(BUNDLE_ROOT, locale);
 | 
					 | 
				
			||||||
            enBundle = ResourceBundle.getBundle(BUNDLE_ROOT, Locale.US);
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    public static void addResourceBundle(String bundleRoot, Locale defaultLocale) {
 | 
				
			||||||
 | 
					    	Locale locale = getLocalFromConfig();
 | 
				
			||||||
 | 
					    	bundles.add(ResourceBundle.getBundle(bundleRoot, locale));
 | 
				
			||||||
 | 
					    	defaultBundles.add(ResourceBundle.getBundle(bundleRoot, defaultLocale));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private static String addColors(String input) {
 | 
					    private static String addColors(String input) {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user