Automatic detection of user's preferred language
From OpenCms Wiki
Revision as of 13:09, 28 October 2008 by 134.100.101.14 (Talk)
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.