This document may contain examples in another language or script.
Use accesskey "n" to jump to the internal navigation links at any point. Right now you can
This note describes a hack that allows you to do language negotiation across files that are not necessarily in the same directory. It is a method described by Dominique Hazaël-Massieux with a couple of refinements I added relating to handling default files and language extensions appearing before the .html extension.
I haven't been able to test this properly with Apache 2. It didn't work on my localhost setup. If you are able to test it, please let me know.
Although this does seem to work on the W3C server, it is a hack and it is a lot more complicated than using MultiViews and negotiating among files in the same directory.
Let's use an actual example: http://www.w3.org/International/2004/07/test/about. You can test how this works by selecting that link after changing your browsers language preferences.
In the test directory there are the following files: about.en.html, about.es.html, and about.html (the default that will be served to those who's language preferences don't mention English, French or Spanish). Then there is another 'French translation' at http://people.w3.org/rishida/articles/about.html
I prefer to use language extensions before the .html (eg. about.en.html rather than about.html.en), since this makes editing and backward compatibility of default files easier. These instructions reflect that choice.
This approach presupposes you have mod_asis enabled on your Apache server, and the MultiViews option needs to be enabled as always for the classical content negotiation in Apache.
Step one is to create a type-map file (typically associated with the extension .var, but possibly not enabled on your server). We add this to the test directory and call it about.var.
AddHandler type-map
var URI: about URI: about.en.html Content-Language: en Content-Type: text/html URI: about.es.html Content-Language: es Content-Type: text/html URI: about-fr.redirect Content-Language: fr Content-Type: text/html URI: about.html Content-Type: text/html
We assume a Content-Type of text/html for all these files - adapt this if necessary.
If the user agent's preferences are set up to send an HTTP Content-Language header indicating a preference for Spanish (es), the server will return the file about.es.html. If, however, the Content-Language header indicates, say, Japanese (ja) only, the bottom two lines of the file will cause the server to return the default about.html file. If the Content-Language of the request is French (fr), the server will be directed to the file about-fr.redirect.
If your server is set up to enable this kind of redirect, the contents of the file shown below will point to the actual location of the French file. It is called about-fr.redirect. Note that the default extension for such a file would be .asis, but this has been changed to .redirect on the W3C server. Note that you should not use a name like about.fr.redirect for this file.
AddHandler send-as-is asis
AddHandler send-as-is redirectStatus: 301 Moved Permanently Location: http://people.w3.org/rishida/articles/about Content-Type: text/html <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"> <title>Redirection</title> <p>The correct URI for this page is <a href= "http://people.w3.org/rishida/articles/about" >http://people.w3.org/rishida/articles/about</a>.
A redirect file is a file served with the magic mime-type "httpd/send-as-is" that forces the server to send the file without adding any headers, assuming they are included in the files.
Also, pay close attention to linebreaks and empty lines in the above files.
In order to cater for those clever people who try to go directly to the French version by typing in about.fr.html, you can add a rewrite rule to the .htaccess file (assuming of course that this is enabled and is called .htaccess):
RewriteEngine On RewriteBase /International/2004/07/test/ RewriteRule ^about.fr.html$ about-fr.redirect
This will redirect the request to the appropriate place.
It depends on the type of material, but for the W3C's International site I'm keen to keep the same look & feel and behaviour for translated versions of FAQs, articles and the like. So that it's transparent to the user navigating through the material where the translation is located. Achieving that means some additional work for the translator if the file is located on another server.
Setting up the language negotiation is also a lot more work than setting up a MultiViews approach with all the files in the same directory.
And its still not clear for me whether it works on a server running Apache 2.
Note also that the filters page in the Apache 2 documentation says "Mod_Asis is a bit of a hack, but the handler needs to remove all filters except for connection filters, and send the data. If you are using mod_asis, all other bets are off."
So all in all, I've documented it, but I'd rather avoid doing it unless I have no choice.
Changing browser language preferences http://www.w3.org/International/questions/qa-lang-priorities
Checking HTTP Headers http://www.w3.org/International/questions/qa-headers-charset
FAQ: Apache MultiViews language negotiation set up http://www.w3.org/International/questions/qa-apache-lang-neg
Apache version 1.3 documentation http://httpd.apache.org/docs/
Apache version 2 documentation http://httpd.apache.org/docs-2.0/
Apache content negotiation: v1 http://httpd.apache.org/docs/mod/mod_negotiation.html; v2 http://httpd.apache.org/docs-2.0/content-negotiation.html
Apache Module mod_negotiation (type-maps): v1 http://httpd.apache.org/docs/content-negotiation.html; v2 http://httpd.apache.org/docs-2.0/mod/mod_negotiation.html
Apache Module mod_asis v1 http://httpd.apache.org/docs/mod/mod_asis; v2 http://httpd.apache.org/docs-2.0/mod/mod_asis.html
Other W3C I18N resources relating to Language negotiation http://www.w3.org/International/resource-index#lang