Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » EMF Edit localization in a stand-alone application
EMF Edit localization in a stand-alone application [message #1849449] Thu, 20 January 2022 12:27 Go to next message
Denis Nikiforov is currently offline Denis NikiforovFriend
Messages: 344
Registered: August 2013
Senior Member
Hi

I have an Ecore-metamodel and an edit-plugin. Edit-plugin contains two files in root: plugin.properties and plugin_ru.properties. Everithing works fine in Eclipse, I can see localized strings.

The problem is that localization doesn't work in a stand-alone application (based on Spring).

The method org.eclipse.emf.common.util.DelegatingResourceLocator::doGetString() contains the following code:
        try
        {
          bundle = resourceBundle = ResourceBundle.getBundle(packageName + ".plugin");
        }
        catch (MissingResourceException exception)
        {
          // If the bundle can't be found the normal way, try to find it as the base URL.
          // If that also doesn't work, rethrow the original exception.
          //
          try
          {
            InputStream inputStream =  new URL(baseURL.toString() + bundleLocalization).openStream();
            bundle = untranslatedResourceBundle = resourceBundle = new PropertyResourceBundle(inputStream);
            inputStream.close();
          }
          catch (IOException ioException)
          {
            // We'll rethrow the original exception, not this one.
          }
          if (bundle == null)
          {
            throw exception;
          }
        }


ResourceBundle.getBundle(packageName + ".plugin") tries to find a properties file at the following path:
com/examples/model/provider/plugin.properties

The file is not found at this location, because it's located at the jar's root. So, next, it tries to find it at the jar's root:

            InputStream inputStream =  new URL(baseURL.toString() + bundleLocalization).openStream();
            bundle = untranslatedResourceBundle = resourceBundle = new PropertyResourceBundle(inputStream);
            inputStream.close();


But the problem is that it finds only plugin.properties file, not plugin_ru.properties. Should this code take into consideration a current locale?

How could I let localization work in a stand-alone application? Should I put properties files to com/examples/model/provider/? Will Eclipse read the files from this location too? Or I should duplicate properties-files in both places? What is a right approach?
Re: EMF Edit localization in a stand-alone application [message #1849457 is a reply to message #1849449] Thu, 20 January 2022 14:39 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33143
Registered: July 2009
Senior Member
No one has ever asked for that before, so mostly it's focused on finding something.

For standalone it would of course be good to have it in the "standard place" but the plugin.properties also has things used in the plugin.xml so if you need it to work in both places, that's not so helpful.

Probably it should be more like this completely untested approach:
        catch (MissingResourceException exception)
        {
          Locale locale = Locale.getDefault();
          List<String> bundleLocalizations = new ArrayList<String>();
          bundleLocalizations.add(bundleLocalization);
          String translatedBundleLocalization = bundleLocalization.replace(".properties", "");
          String language = locale.getLanguage();
          if (language != "")
          {
            translatedBundleLocalization += '_' + language;
            bundleLocalizations.add(0, translatedBundleLocalization + ".properties");
            String script = locale.getScript();
            if (script != "")
            {
              translatedBundleLocalization += '_' + script;
              bundleLocalizations.add(0, translatedBundleLocalization + ".properties");
            }
            String country = locale.getCountry();
            if (country != "")
            {
              translatedBundleLocalization += '_' + country;
              bundleLocalizations.add(0, translatedBundleLocalization + ".properties");
              String variant = locale.getVariant();
              if (variant != "") {
                translatedBundleLocalization += '_' + variant;
                bundleLocalizations.add(0, translatedBundleLocalization + ".properties");
              }
            }
          }
          for (String localization : bundleLocalizations)
          {
            // If the bundle can't be found the normal way, try to find it as the base URL.
            // If that also doesn't work, rethrow the original exception.
            //
            try
            {
              InputStream inputStream =  new URL(baseURL.toString() + localization).openStream();
              bundle = untranslatedResourceBundle = resourceBundle = new PropertyResourceBundle(inputStream);
              inputStream.close();
              break;
            }
            catch (IOException ioException)
            {
              // We'll rethrow the original exception, not this one.
            }
          }
          if (bundle == null)
          {
            throw exception;
          }
        }
I.e., in general it should search for the most specific thing first until finally falling back to just the plugin.properties. You could override the method in plugin subclass, copy the entire base method, paste in the above code and try it.

If that works or if you have an improvement that works, you could open a Bugzilla to put in the base implementation.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: EMF Edit localization in a stand-alone application [message #1849493 is a reply to message #1849457] Fri, 21 January 2022 15:26 Go to previous message
Denis Nikiforov is currently offline Denis NikiforovFriend
Messages: 344
Registered: August 2013
Senior Member
Thanks a lot! Works fine for us. Here is a Bugzilla https://bugs.eclipse.org/bugs/show_bug.cgi?id=578312
Previous Topic:Genmodel Shorting Names for Edit Plugin
Next Topic:Short Survey About Requirements Engineering
Goto Forum:
  


Current Time: Thu May 02 13:17:36 GMT 2024

Powered by FUDForum. Page generated in 0.03172 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top