Home
Categories
Dictionary
Download
Project Details
Changes Log
Tutorials
FAQ
License

Localization



The MenusLocalization class handle the localization of the menus.

Overview

The MenusLocalization class is a singleton. You can always get the unique instance by calling the MenusLocalization.getInstance() method.

By default the language is US English. You can set the Locale by using one of the following methods:
By default only the following locales are supported:
  • "en": US English
  • "fr": French
  • "de": German
If a locale is not supported, US English will be used instead.

Default menus

By default only the menus used in the generic framework are supported. These menus are specified in the MenusKeys interface.

Setting a localization factory

The MenusLocalization.setMenusLocalizationFactory(MenusLocalizationFactory) method allows to define a custom localization factory. The factory must implement the following methods:
If the MenusLocalizationFactory.getMenuText(String, String) method returns null, then a default menu text will be used.

Default implementation

The DefaultMenusLocalizationFactory class provides a default implementation which:
  • Only support "en", "fr", and "de" locales
  • Only support the menus keys defined in the MenusKeys interface
You can override this class to support new languages or new menu keys.

For example here the Italian language is supported:
   public class CustomMenusLocalizationFactory extends DefaultMenusLocalizationFactory {
      @Override
      public boolean supportLanguage(String lang) {
        if (super.supportLanguage(String(lang)) {
          return true;
        } else {
          return lang.equals("it");
        }
      }
   
      protected String getMenuTextIt(String menuKey) {
        switch (menuKey) {
          case CLOSE:
            return "Vicino";
          ...
          case CLEAR:
            return "Chiaro";
          default:
            return getDefaultMenuDesc(menuKey);
          }
        }
      }       

      @Override
      public String getMenuText(String menuKey, String lang) {
        if (super.supportLanguage(lang)) {
          return super.getMenuText(menuKey, lang);
        } else if (lang.equals("it")) {
          return getMenuTextIt(menuKey);
        }
      }
   }

See also


Categories: General

Copyright 2006-2023 Herve Girod. All Rights Reserved. Documentation and source under the LGPL v2 and Apache 2.0 licences