Automatic detection of user's preferred language

From OpenCms Wiki
Jump to: navigation, search

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.

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox