Automatic detection of user's preferred language
From OpenCms Wiki
(Difference between revisions)
Marc.johnen (Talk | contribs) |
|||
(One intermediate revision by one user not shown) | |||
Line 1: | Line 1: | ||
Here's what I did, it's quick, dirty and working(?): | Here's what I did, it's quick, dirty and working(?): | ||
+ | <code lang="java"> | ||
+ | <%@ taglib prefix="cms" uri="http://www.opencms.org/taglib/cms" %> | ||
+ | <%@page import="org.opencms.jsp.*, org.opencms.file.*, org.opencms.flex.*, java.util.*" %> | ||
+ | <%@ taglib prefix="cmstag" uri="http://www.opencms.org/taglib/cms" %> | ||
+ | <% | ||
+ | CmsJspActionElement cms = new CmsJspActionElement(pageContext, request, response); | ||
+ | String locale = request.getHeader("Accept-Language").substring(0, 2); | ||
+ | if (locale.indexOf("de") >-1) { | ||
+ | response.sendRedirect("de/index.html"); } | ||
+ | else if (locale.indexOf("no") >-1) { | ||
+ | response.sendRedirect("no/index.html"); | ||
+ | } | ||
+ | else{ | ||
+ | response.sendRedirect("en/index.html"); | ||
+ | } | ||
+ | %> | ||
+ | </code> | ||
− | + | I have three directorys in /sites/mypage/ where I redirect to. | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + |
Latest revision as of 13:09, 28 October 2008
Here's what I did, it's quick, dirty and working(?):
<%@ taglib prefix="cms" uri="http://www.opencms.org/taglib/cms" %> <%@page import="org.opencms.jsp.*, org.opencms.file.*, org.opencms.flex.*, java.util.*" %> <%@ taglib prefix="cmstag" uri="http://www.opencms.org/taglib/cms" %> <% CmsJspActionElement cms = new CmsJspActionElement(pageContext, request, response); String locale = request.getHeader("Accept-Language").substring(0, 2); if (locale.indexOf("de") >-1) { response.sendRedirect("de/index.html"); } else if (locale.indexOf("no") >-1) { response.sendRedirect("no/index.html"); } else{ response.sendRedirect("en/index.html"); } %>
I have three directorys in /sites/mypage/ where I redirect to.