Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[questions/qa-when-lang-neg] Language negotiation using client-side JavaScript #545

Open
xfq opened this issue Sep 30, 2023 · 4 comments
Open

Comments

@xfq
Copy link
Member

xfq commented Sep 30, 2023

[source] (https://www.w3.org/International/questions/qa-when-lang-neg.en.html) [en]

Language negotiation is a function of the HTTP protocol which lets a server choose among several language versions of a page, based on the URL and on preference information sent by the browser (specifically in the Accept-Language header). This is distinct from page selection based on the IP address of the browser or from a manual selection by the user on a language-selection page.

In addition to the HTTP functions mentioned above, I think there's another language negotiation approach, which is navigator.languages. The advantage of this approach is that it does not require server-side support. The disadvantage is that it can only be used with JavaScript enabled.

We can mention it in this article, at least briefly.

@aphillips
Copy link
Contributor

There are more approaches than using Accept-Language or navigator.languages. The article (which was published in 2004!) actually goes on to acknowledge this. If it were me, I wouldn't start with such a limited definition of language negotiation, since I generally call "language negotiation" the thing that happens when there is any mutability in the language returned from a request.

@xfq
Copy link
Member Author

xfq commented Oct 12, 2023

Is there any other approach in the browser? If not, we can limit the scope of this article to browsers.

If necessary, we can write another general article on language negotiation and link to this article in the new article.

@r12a
Copy link
Contributor

r12a commented Oct 12, 2023

I wouldn't start with such a limited definition of language negotiation

A simpler way to improve the article might be to change the heading to "When to use HTTP language negotiation".

@xfq, i understand what navigator.languages represents, but how would one actually do language negotiation using navigator.languages ?

@xfq
Copy link
Member Author

xfq commented Oct 17, 2023

navigator.languages can be used if the content is generated client-side.

Currently, when you open a ReSpec document, you may see errors/warnings in the upper right corner. When you click the "error/warning pill", you will see errors in English. If ReSpec supports multiple languages, it might use navigator.languages to generate the error messages in the language the user wants to see.

The ReSpec example might not be very good, tho. For some web applications, the entire application is generated using JavaScript. In this case, navigator.languages is a potential solution, especially when the application developer has no control over the server.

Here are some real code examples for your reference:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants