How do I detect request base on system language instead of browser's?

I originally use below phrase in redirection rules for detecting browser language.

starts_with(http.request.accepted_languages[0],“zh”)

But lately in practice I found that system language would be more accurate for my goal.

May I ask how should achieve that? Thanks in advance.

I don’t think you will be able to find any browsers that will expose more than the browser’s own preference of languages for you.

2 Likes

Then I think it would only be available for other application? Because I do see such code for js. Just don’t know how to apply here in Cloudflare.

From the example you mentioned above:

That is based on the browser sending a HTTP Request header called “Accept-Language” together with the request for the website, depending on your browser’s configuration for what you have selected as your preferred language to show websites in.

In a configuration of, for example Mozilla Firefox, - (about:preferences#general):

→ Browser language: English (GB), e.g. the “en-GB” locale.

→ System language: Dansk (Danmark), … or, translated:. Danish (Denmark), e.g. the “da-DK” locale.

firefox_preferred_languages

→ Tell websites I want to see them in the language “Chinese [zh]”, if available.

Means that the browser is sending an the above “Accept-Language” header, with it’s request, asking for the language “Chinese [zh]”, which you’re already using in your own example.

Accessing the browser language English (GB), or “en-GB” locale might be possible using client side JavaScript (e.g. within your HTML), but as that information is never sent through the HTTP request, you won’t be able to use it in e.g. redirection rules.

Accessing the system language, in the above image indicated to be “Dansk (Danmark)”, is to my knowledge not possible using client side JavaScript.

I believe Internet Explorer is the only browser I’m aware of, that has actually been exposing the operating system’s language (e.g. “da” for Danish), which was under the JavaScript variable “navigator.systemLanguage”, but that one wouldn’t be sent with the HTTP Request, and as such, won’t be available in redirect rules either.

Maybe you’re confusing JavaScript (client-side, inside browser) with Node.js (server-side, outside browser).

Probably so, I was simply using Cloudflare for some easy re-routing to different sites. And thank you for your time. Will look into that.

1 Like

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.