Automatic detection of user's preferred language

From OpenCms Wiki
Revision as of 18:38, 5 March 2007 by Marc.johnen (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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");
  }

%>

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox