Details

    • Type: Sub-task Sub-task
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 2.1.0 RC1
    • Fix Version/s: 2.2.0
    • Component/s: extras
    • Labels:
      None

      Description

      Menu is not I18N-able. I have created a patch that fixes that. Here's an example of how to set a messagekey in menu.xml, that corresponds to an item in the messageresources.

      The message attribute tells the menu which key should be used to get the text from the message resources. (The $path variable can be used as well, since I adjusted the writeMenu VM macro to use: #evaluate($submenu) instead of $submenu itself. Velocity now supports #evaluate to evaluate a string that contains VM directives )

      <menu>
      <menu label="Home" path="/home.htm">
      <menu message="menu_logoff" path="$path?actionLink=logoff" roles="SU, DU, VU, WU"/>
      </menu>
      </menu>

      The setParent method is overridden because the parent is needed to access the page's message resources. It will also recursively descend into the children as well. Once you add the menu to the page using Page.addControl(Menu.getRootMenu(new MyAccessController())); the page is set as parent for all menuitems.

      Attribute message takes precedence over attribute label. If both are set, message is the attribute used.

      So there you go. I18N for Menu

      Index: Menu.java
      ===================================================================
      — Menu.java (revision 831895)
      +++ Menu.java (working copy)
      @@ -244,6 +244,9 @@
      /** The menu display label. */
      protected String label;

      + /** The message key to be used from the click-controls.properties or click-page.properties */
      + protected String messageKey;
      +
      /**

      • The list of valid page paths. If any of these page paths match the
      • current request then the Menu item will be selected.
        @@ -335,7 +338,9 @@
        setAccessController(accessController);

      setLabel(menuElement.getAttribute("label"));
      -
      +
      + setMessageKey(menuElement.getAttribute("message"));
      +
      setImageSrc(menuElement.getAttribute("imageSrc"));

      setPath(menuElement.getAttribute("path"));
      @@ -846,12 +851,20 @@

      buffer.elementEnd();

      • if (getLabel() != null)
        Unknown macro: {+ if ( StringUtils.isNotBlank(getMessageKey())) { + buffer.append(getMessage(getMessageKey())); + }
        + else if (getLabel() != null) { buffer.append(getLabel()); }

        } else {
        - buffer.append(getLabel());
        + if (StringUtils.isNotBlank(getMessageKey())) { + buffer.append(getMessage(getMessageKey())); + }+ else { + buffer.append(getLabel()); + } }

      buffer.elementEnd("a");
      @@ -947,4 +960,23 @@
      return menu;
      }

      + public String getMessageKey()

      { + return messageKey; + }

      +
      + public void setMessageKey(String messageKey)

      { + this.messageKey = messageKey; + }

      +
      + /**
      + * @see org.apache.click.Control#setParent(Object)
      + * Sets the parent for this menu. This will automatically set the parent for the children as well.
      + * @param parent The parent
      + */
      + public void setParent(Object parent) {
      + super.setParent(parent);
      + for (Object child : children)

      { + ((Menu) child).setParent(parent); + }

      + }
      }

        Activity

        Hide
        Bob Schellink added a comment -

        fixed in trunk

        Show
        Bob Schellink added a comment - fixed in trunk
        Hide
        Adrian A. added a comment -

        > To do this we would need to introduce the name into the Menu control to follow
        > this convention.
        +1 for adding the 'name' property too.

        Show
        Adrian A. added a comment - > To do this we would need to introduce the name into the Menu control to follow > this convention. +1 for adding the 'name' property too.
        Hide
        Malcolm Edgar added a comment -

        Agree with this issue and approach. The menu in addition to the label property has a title property, and an imageSrc property which could also benefit from localization. If we use the convention used with other controls we can support internationalization as well

        menu_logoff.label=Log Off
        menu-logoff.title=Logout of the application
        menu-logoff.imageSrc=/assets/images/logoff.gif

        To do this we would need to introduce the name into the Menu control to follow this convention.

        Show
        Malcolm Edgar added a comment - Agree with this issue and approach. The menu in addition to the label property has a title property, and an imageSrc property which could also benefit from localization. If we use the convention used with other controls we can support internationalization as well menu_logoff.label=Log Off menu-logoff.title=Logout of the application menu-logoff.imageSrc=/assets/images/logoff.gif To do this we would need to introduce the name into the Menu control to follow this convention.

          People

          • Assignee:
            Unassigned
            Reporter:
            WarnerJan Veldhuis
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development