com.innovativeastrosolutions.astrosoftcore.util.Internalization Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of AstrosoftCore Show documentation
Show all versions of AstrosoftCore Show documentation
https://github.com/erajasekar/AstrosoftCore
The newest version!
/**
* Internalization.java
* Created On 2005, Dec 21, 2005 3:13:24 PM
* @author E. Rajasekar
*/
package com.innovativeastrosolutions.astrosoftcore.util;
import java.util.EnumMap;
import java.util.Locale;
import java.util.Map;
import java.util.ResourceBundle;
import java.util.logging.Logger;
import com.innovativeastrosolutions.astrosoftcore.consts.DisplayFormat;
import com.innovativeastrosolutions.astrosoftcore.consts.Language;
import com.innovativeastrosolutions.astrosoftcore.exception.AstrosoftException;
public class Internalization {
private static final Logger log = Logger.getLogger(Internalization.class.getName());
public static String bundleName = "Internalization.AstrosoftBundle";
private static Map bundles;
static {
//setPreferedLanguate();
loadBundles();
/*AstroSoft.getPreferences().addPreferenceChangeListener(
new PreferenceChangeListener() {
public void preferenceChange(PreferenceChangeEvent evt) {
if (evt.getKey().equals(
AstrosoftPref.Preference.Language.name())) {
setLanguage(Enum.valueOf(Language.class, evt
.getNewValue()));
}
}
});*/
}
private static void loadBundles(){
bundles = new EnumMap(Language.class);
for (Language l : Language.values()){
ResourceBundle bundle = ResourceBundle.getBundle(bundleName, new Locale(l.isoCode()));
bundles.put(l,bundle);
}
}
/*private static void setPreferedLanguate() {
setLanguage(AstroSoft.getPreferences().getLanguage());
}
public static void setLanguage(Language language) {
log.info("Language changed to " + language);
Locale locale = new Locale(language.isoCode());
bundle = ResourceBundle.getBundle(bundleName, locale);
}*/
/*public static void useLanguage(Language language, CallBack caller) {
setLanguage(language);
caller.call();
setPreferedLanguate();
}*/
public static String getString(Language language, String key) {
ResourceBundle bundle = bundles.get(language);
log.finer("Bundle : " + bundle.getLocale() + " Key : " + key);
boolean langNotEnglish = !language.isEnglish();
if (langNotEnglish) {
throw new AstrosoftException("Unsupported Language: " + language);
}
return bundle.getString(key);
}
public static String getString(String key) {
/*String str = "";
setLanguage(language);
str = getString(key);
setPreferedLanguate();*/
//setLanguage(language);
//TODO
return getString(Language.ENGLISH, key);
//setPreferedLanguate(Ast);
//return str;
}
public static String getString(Language language, Enum string){
return getString(language, string.name());
}
public static String getString(DisplayFormat format, String... args) {
switch (format) {
case FULL_NAME:
default:
return getString(args[0]);
case SYMBOL:
return getString(args[1]);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy