package net.sourceforge.phpeclipse.wiki.actions.mediawiki.config; //Parts of this sources are copied and modified from the jEdit Wikipedia plugin: //http://www.djini.de/software/wikipedia/index.html // //The modified sources are available under the "Common Public License" //with permission from the original author: Daniel Wunsch import java.io.IOException; import java.io.InputStream; import java.text.MessageFormat; import java.util.MissingResourceException; import java.util.PropertyResourceBundle; import java.util.ResourceBundle; import net.sourceforge.phpeclipse.wiki.editor.WikiEditorPlugin; import org.eclipse.core.runtime.Path; public class WikiProperties { private static final String PACKAGE_NAME = WikiProperties.class.getPackage().getName(); private String RESOURCE_BUNDLE = null; private ResourceBundle fgResourceBundle = null; protected WikiProperties(String locale) { try { InputStream is = WikiEditorPlugin.getDefault().openStream(new Path("wikis/"+locale+".properties")); fgResourceBundle = new PropertyResourceBundle(is); // RESOURCE_BUNDLE = PACKAGE_NAME + "." + locale; // fgResourceBundle = ResourceBundle.getBundle(RESOURCE_BUNDLE); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public String getString(String key) { try { return fgResourceBundle.getString(key); } catch (MissingResourceException e) { return '!' + key + '!'; } } /** * Gets a string from the resource bundle and formats it with the argument * * @param key * the string used to get the bundle value, must not be null */ public String getFormattedString(String key, Object arg) { return MessageFormat.format(getString(key), new Object[] { arg }); } /** * Gets a string from the resource bundle and formats it with arguments */ public String getFormattedString(String key, Object[] args) { return MessageFormat.format(getString(key), args); } // test code // public static void main(String[] args) { // WikiProperties p = new WikiProperties("EN"); // System.out.println(p.getString("uploadNoLogin")); // } }