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.