From aa03fa52face6f13f8da2e9b89e798671653a074 Mon Sep 17 00:00:00 2001 From: Svjatoslav Agejenko Date: Wed, 20 Aug 2014 18:56:56 +0300 Subject: [PATCH] localized navigation menu --- .../svjatoslav/commons/network/navigation/Navigation.java | 7 ++++++- .../commons/network/navigation/NavigationItem.java | 3 ++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/eu/svjatoslav/commons/network/navigation/Navigation.java b/src/main/java/eu/svjatoslav/commons/network/navigation/Navigation.java index 3a2877f..8b049bb 100755 --- a/src/main/java/eu/svjatoslav/commons/network/navigation/Navigation.java +++ b/src/main/java/eu/svjatoslav/commons/network/navigation/Navigation.java @@ -14,6 +14,9 @@ import java.net.URL; import javax.servlet.http.HttpServletRequest; +import eu.svjatoslav.commons.network.Locale; +import eu.svjatoslav.commons.network.LocaleHelper; + public class Navigation { private NavigationItem rootNavigationItem; @@ -56,6 +59,8 @@ public class Navigation { public String getTopMenu(final HttpServletRequest request) { + final Locale currentLocale = LocaleHelper.detectLocale(request); + final NavigationItem selectedItem = getSelectedItem(request); final StringBuffer result = new StringBuffer(); @@ -76,7 +81,7 @@ public class Navigation { + getGetNotNullString(item.getCssPrefix()) + "menuItem\" href=\"" + item.getLinkUrl() + "\">"); - result.append("
" + item.getTitle() + "
"); + result.append("
" + item.getTitle(currentLocale) + "
"); result.append(""); } diff --git a/src/main/java/eu/svjatoslav/commons/network/navigation/NavigationItem.java b/src/main/java/eu/svjatoslav/commons/network/navigation/NavigationItem.java index 22ba6b0..14c8b0a 100755 --- a/src/main/java/eu/svjatoslav/commons/network/navigation/NavigationItem.java +++ b/src/main/java/eu/svjatoslav/commons/network/navigation/NavigationItem.java @@ -99,7 +99,8 @@ public class NavigationItem { public String getTitle() { if (localeToTitle.size() != 1) - throw new RuntimeException("there shall be exactly one title"); + throw new RuntimeException( + "NavigationItem.getTitle() was called without locale parameter, but there there are multiple titles in diffirent locales available."); return localeToTitle.values().iterator().next(); } -- 2.20.1