Search in sources :

Example 1 with IResourceBundleLoadCallback

use of org.pentaho.gwt.widgets.client.utils.i18n.IResourceBundleLoadCallback in project pentaho-platform by pentaho.

the class PerspectiveManager method loadResourceBundle.

private void loadResourceBundle(final HasText textWidget, final IPluginPerspective perspective) {
    try {
        String bundle = perspective.getResourceBundleUri();
        if (bundle == null) {
            return;
        }
        // $NON-NLS-1$
        String folder = "";
        String baseName = bundle;
        // we have to separate the folder from the base name
        if (bundle.indexOf(SEPARATOR) > -1) {
            folder = bundle.substring(0, bundle.lastIndexOf(SEPARATOR) + 1);
            baseName = bundle.substring(bundle.lastIndexOf(SEPARATOR) + 1);
        }
        // some may put the .properties on incorrectly
        if (baseName.contains(PROPERTIES_EXTENSION)) {
            baseName = baseName.substring(0, baseName.indexOf(PROPERTIES_EXTENSION));
        }
        // some may put the .properties on incorrectly
        if (baseName.contains(".properties")) {
            baseName = baseName.substring(0, baseName.indexOf(".properties"));
        }
        final ResourceBundle messageBundle = new ResourceBundle();
        messageBundle.loadBundle(folder, baseName, true, new IResourceBundleLoadCallback() {

            public void bundleLoaded(String arg0) {
                String title = ResourceBundleTranslator.translate(perspective.getTitle(), messageBundle);
                perspective.setTitle(title);
                textWidget.setText(title);
            }
        });
    } catch (Throwable t) {
        // $NON-NLS-1$
        Window.alert("Error loading message bundle: " + t.getMessage());
        t.printStackTrace();
    }
}
Also used : ResourceBundle(org.pentaho.gwt.widgets.client.utils.i18n.ResourceBundle) JsArrayString(com.google.gwt.core.client.JsArrayString) IResourceBundleLoadCallback(org.pentaho.gwt.widgets.client.utils.i18n.IResourceBundleLoadCallback)

Aggregations

JsArrayString (com.google.gwt.core.client.JsArrayString)1 IResourceBundleLoadCallback (org.pentaho.gwt.widgets.client.utils.i18n.IResourceBundleLoadCallback)1 ResourceBundle (org.pentaho.gwt.widgets.client.utils.i18n.ResourceBundle)1