You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Martin Reinders <ma...@helios.de> on 2016/07/15 11:31:03 UTC

[users@httpd] Content negotiation with language subtags

Im am using content negotiation to present different HTML pages
depending on the browsers language preference. This works in general,
but not with language "subtags", e.g. if the preferred language is sent
as "de-DE" only.

Here is my setup (reduced to two languages for simplicity):
----------------------------------------------
// .htaccess:
AddHandler type-map var
DirectoryIndex index.var
LanguagePriority en de
ForceLanguagePriority Prefer Fallback

// index.var:
URI: index

URI: index.en.html
Content-type: text/html
Content-language: en

URI: index.de.html
Content-type: text/html
Content-language: de

// index.en.html: English index page
// index.de.html: German index page
----------------------------------------------

This works as expected when the client sends the preferred language as

   Accept-Language: de,en;q=0.8

and "index.de.html" is returned from the Apache server. But with

   Accept-Language: de-DE,en-US;q=0.8

the server returns "index.en.html", so apparently "de-DE" does not match
"de" when the language is negotiated.

Do I really have to add all possible combinations in "index.var", such
as "de, de-DE, de-CH, de-AT" for German? Or is there at way to specify
"match this language with any language subtags"? My naive approach
"de-*" did not work.

Or is it a bug in the HTTP client (in my case: Android WebView) if it
sends only "de-DE" in the Accept-Language header, without a plain "de"?

Thanks for any help,
Martin


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Content negotiation with language subtags

Posted by Martin Reinders <ma...@helios.de>.
OK, thanks for the clarification.

Martin

On 15.07.16 14:46, Marat Khalili wrote:
> According to RFC 2616
> <https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html>:
>>        Note: This use of a prefix matching rule does not imply that
>>        language tags are assigned to languages in such a way that it is
>>        always true that if a user understands a language with a certain
>>        tag, then this user will also understand all languages with tags
>>        for which this tag is a prefix. The prefix rule simply allows the
>>        use of prefix tags if this is the case.
> Thus the server must not simply return "de" version in response to
> "de-DE" request from the client. The browser is probably in error in not
> stating that "de" version is acceptable (likewise for "en").
> 
> -- 
> 
> With Best Regards,
> Marat Khalili
> 
> On 15/07/16 14:31, Martin Reinders wrote:
>> Im am using content negotiation to present different HTML pages
>> depending on the browsers language preference. This works in general,
>> but not with language "subtags", e.g. if the preferred language is sent
>> as "de-DE" only.
>>
>> Here is my setup (reduced to two languages for simplicity):
>> ----------------------------------------------
>> // .htaccess:
>> AddHandler type-map var
>> DirectoryIndex index.var
>> LanguagePriority en de
>> ForceLanguagePriority Prefer Fallback
>>
>> // index.var:
>> URI: index
>>
>> URI: index.en.html
>> Content-type: text/html
>> Content-language: en
>>
>> URI: index.de.html
>> Content-type: text/html
>> Content-language: de
>>
>> // index.en.html: English index page
>> // index.de.html: German index page
>> ----------------------------------------------
>>
>> This works as expected when the client sends the preferred language as
>>
>>     Accept-Language: de,en;q=0.8
>>
>> and "index.de.html" is returned from the Apache server. But with
>>
>>     Accept-Language: de-DE,en-US;q=0.8
>>
>> the server returns "index.en.html", so apparently "de-DE" does not match
>> "de" when the language is negotiated.
>>
>> Do I really have to add all possible combinations in "index.var", such
>> as "de, de-DE, de-CH, de-AT" for German? Or is there at way to specify
>> "match this language with any language subtags"? My naive approach
>> "de-*" did not work.
>>
>> Or is it a bug in the HTTP client (in my case: Android WebView) if it
>> sends only "de-DE" in the Accept-Language header, without a plain "de"?
>>
>> Thanks for any help,
>> Martin
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>> For additional commands, e-mail: users-help@httpd.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Content negotiation with language subtags

Posted by Marat Khalili <mk...@rqc.ru>.
According to RFC 2616 
<https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html>:
>        Note: This use of a prefix matching rule does not imply that
>        language tags are assigned to languages in such a way that it is
>        always true that if a user understands a language with a certain
>        tag, then this user will also understand all languages with tags
>        for which this tag is a prefix. The prefix rule simply allows the
>        use of prefix tags if this is the case.
Thus the server must not simply return "de" version in response to 
"de-DE" request from the client. The browser is probably in error in not 
stating that "de" version is acceptable (likewise for "en").

--

With Best Regards,
Marat Khalili

On 15/07/16 14:31, Martin Reinders wrote:
> Im am using content negotiation to present different HTML pages
> depending on the browsers language preference. This works in general,
> but not with language "subtags", e.g. if the preferred language is sent
> as "de-DE" only.
>
> Here is my setup (reduced to two languages for simplicity):
> ----------------------------------------------
> // .htaccess:
> AddHandler type-map var
> DirectoryIndex index.var
> LanguagePriority en de
> ForceLanguagePriority Prefer Fallback
>
> // index.var:
> URI: index
>
> URI: index.en.html
> Content-type: text/html
> Content-language: en
>
> URI: index.de.html
> Content-type: text/html
> Content-language: de
>
> // index.en.html: English index page
> // index.de.html: German index page
> ----------------------------------------------
>
> This works as expected when the client sends the preferred language as
>
>     Accept-Language: de,en;q=0.8
>
> and "index.de.html" is returned from the Apache server. But with
>
>     Accept-Language: de-DE,en-US;q=0.8
>
> the server returns "index.en.html", so apparently "de-DE" does not match
> "de" when the language is negotiated.
>
> Do I really have to add all possible combinations in "index.var", such
> as "de, de-DE, de-CH, de-AT" for German? Or is there at way to specify
> "match this language with any language subtags"? My naive approach
> "de-*" did not work.
>
> Or is it a bug in the HTTP client (in my case: Android WebView) if it
> sends only "de-DE" in the Accept-Language header, without a plain "de"?
>
> Thanks for any help,
> Martin
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>