Automatic detection of user's preferred language

(Difference between revisions)
Jump to: navigation, search
 
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>
 +
<%@ 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>
  
<%@ taglib prefix="cms" uri="http://www.opencms.org/taglib/cms" %>
+
I have three directorys in /sites/mypage/ where I redirect to.
<%@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");
+
  }
+
%>
+

Revision as of 18:42, 5 March 2007

Here's what I did, it's quick, dirty and working(?):

Invalid language.

You need to specify a language like this: <source lang="html">...</source>

Supported languages for syntax highlighting:

actionscript, ada, apache, applescript, asm, asp, autoit, bash, blitzbasic, bnf, c, c_mac, caddcl, cadlisp, cfdg, cfm, cpp, cpp-qt, csharp, css, d, delphi, diff, div, dos, eiffel, fortran, freebasic, gml, groovy, html4strict, idl, ini, inno, io, java, java5, javascript, latex, lisp, lua, matlab, mirc, mpasm, mysql, nsis, objc, ocaml, ocaml-brief, oobas, oracle8, pascal, perl, php, php-brief, plsql, python, qbasic, reg, robots, ruby, sas, scheme, sdlbasic, smalltalk, smarty, sql, tcl, text, thinbasic, tsql, vb, vbnet, vhdl, visualfoxpro, winbatch, xml, z80

I have three directorys in /sites/mypage/ where I redirect to.

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox