fmt:message with community-list.jsp

44 views
Skip to first unread message

paulw...@gmail.com

unread,
May 24, 2022, 9:38:22 AM5/24/22
to DSpace Technical Support
I am interested in using the Messages.properties and Messages_de.properties entries with community-list.jsp.  Right now, the jsp calls the showCommunity method in order to display the list of communites and collections.  I want the names to appear in the user's selected language, and I have everything entered in Message.properties and Message_de.properties to do this.  But how do I use the <fmt:message> tag inside this method?  The names are all raw:

out.println( "<div class=\"media-body\"><h4 class=\"media-heading\"><a href=\"" + request.getContextPath() + "/handle/"
                + c.getHandle() + "\">" + c.getName() + "</a>");

Thanks for any suggestions.

-Paul

paulw...@gmail.com

unread,
May 24, 2022, 10:55:25 AM5/24/22
to DSpace Technical Support
I found the answer.  

In the jsp, enter the I18nUtil class, the Locale class, and the UIUtil class:

<%@ page import="org.dspace.core.I18nUtil" %>
<%@ page import="java.util.Locale"%>
<%@ page import="org.dspace.app.webui.util.UIUtil" %>

Inside the showCommunity method, capture the current locale from the request:

Locale sessionLocale = UIUtil.getSessionLocale(request);

Then, down where you call c.getName(), you change it to:

I18nUtil.getMessage("jsp.home.com.name." + c.getName())

or whatever name you have given your entry in Message.properties.

And do not forget to do the same with the collections.

Very simple solution!

Best regards,
Paul

paulw...@gmail.com

unread,
May 24, 2022, 10:58:01 AM5/24/22
to DSpace Technical Support
Sorry, I forgot to edit one thing in the answer above.  You must include the locale in the call to I18nUtil.getMessage:

18nUtil.getMessage("jsp.home.com.name." + c.getName(), sessionLocale)

Best regards,
Paul

Reply all
Reply to author
Forward
0 new messages