[jira] Created: (CLK-591) I18N for Menu control

3 messages Options
Embed this post
Permalink
JIRA jira@apache.org

[jira] Created: (CLK-591) I18N for Menu control

Reply Threaded More More options
Print post
Permalink
I18N for Menu control
---------------------

                 Key: CLK-591
                 URL: https://issues.apache.org/jira/browse/CLK-591
             Project: Click
          Issue Type: Wish
          Components: extras
    Affects Versions: 2.1.0 RC1
            Reporter: WarnerJan Veldhuis
            Priority: Minor


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) {
+                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);
+        }
+    }
 }





--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

JIRA jira@apache.org

[jira] Updated: (CLK-591) I18N for Menu control

Reply Threaded More More options
Print post
Permalink

     [ https://issues.apache.org/jira/browse/CLK-591?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Bob Schellink updated CLK-591:
------------------------------

    Issue Type: Sub-task  (was: Wish)
        Parent: CLK-592

> I18N for Menu control
> ---------------------
>
>                 Key: CLK-591
>                 URL: https://issues.apache.org/jira/browse/CLK-591
>             Project: Click
>          Issue Type: Sub-task
>          Components: extras
>    Affects Versions: 2.1.0 RC1
>            Reporter: WarnerJan Veldhuis
>            Priority: Minor
>
> 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) {
> +                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);
> +        }
> +    }
>  }

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

JIRA jira@apache.org

[jira] Commented: (CLK-591) I18N for Menu control

Reply Threaded More More options
Print post
Permalink
In reply to this post by JIRA jira@apache.org

    [ https://issues.apache.org/jira/browse/CLK-591?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12773254#action_12773254 ]

Malcolm Edgar commented on CLK-591:
-----------------------------------

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.

> I18N for Menu control
> ---------------------
>
>                 Key: CLK-591
>                 URL: https://issues.apache.org/jira/browse/CLK-591
>             Project: Click
>          Issue Type: Sub-task
>          Components: extras
>    Affects Versions: 2.1.0 RC1
>            Reporter: WarnerJan Veldhuis
>            Priority: Minor
>
> 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) {
> +                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);
> +        }
> +    }
>  }

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.