Nearly all browsers support an option to automacically select a document in a desired format.
Multiple documents have to be created first for each desired language. In addition to the normal file suffix another suffix is appended to the filename for the given language. A list of used language abbreviations is given in RFC1766. All suffixes can be permutated, but putting the language at the end has several advantages.
A document in HTML shall be presented in six languages:
Language | Countrycode | Documentname |
---|---|---|
german | de | index.html.de |
english | en | index.html.en |
spanish | es | index.html.es |
french | fr | index.html.fr |
norwegian | no | index.html.no |
swedish | se | index.html.se |
japanese | jp | index.gif.jp |
To access documents you can keep your old documents: You can link your documens with full name (including the language suffix) or only the part of the filename, which is commen to all versions. Even the suffix for the file format can be stripped, so the server can select the right file from the desired formats.
In addition to the example above, links select different documents:
Link | Possible results |
---|---|
<a href="index.html.en"> | only the english variant |
<a href="index.html"> | All variants in HTML |
<a href="index"> | All variants in all languages and formats |
Dependent on the configuration of browser and server different results will be displayed to the user:
Configured language | Requested URL | Returned document | Description |
---|---|---|---|
- | index.html | index.html.de | Selected by LanguagePriority |
- | index.html.jp | Error message for nonexisting URL | This variante does not exist |
en | index.html | index.html.en | The document does exist in the requested language |
fi,no,fr | index.html | index.html.fr | Finnish is unknown, a norwegian variant does not exist, but a french one |
it,po | index | List of all variants | There is no italian or polish version the user understands, so he can select one himself. |
Hint:
When multiple versions are given for an index page, all files should end with a language suffix.
If the file index.html still exists, this file is allways returned and no automatic selection is done when links point to homedir/index.html or homedir/.
By specifying LanguagePriority
the server allways returns a document, if the URL requested does not exist.
Instead of selecting documents by suffix, a file named with the common filename and the suffix .var
can be provided, which lists all variants.
The benefits are, additional informations can be provided and the files don't have to be named to the strict naming pattern.
For each variant the file contains an introduction URI: filename
followed by Content-type:
to specify the MIME type, Content-language:
to specify the language or Content-encoding:
, if the files are compressed.
For the type tag an optional token qs=0.2
specifies the quality of this variant, which is considered for selection.
A full description is available on the Apache web-site.
For the index document the following variants are described in index.var:
URI: index URI: index.html.de Content-type: text/html Content-language: de URI: index.txt Content-type: text/plain; qs=0.01 Content-language: en URI: index.html.de.gz Content-type: text/html Content-language: de Content-encoding: x-gzip
On tmgo.free.fr is a script, which displayes the Accept-Language
-HTTP-header as sent by the browser.