kiwix / libkiwix

Common code base for all Kiwix ports
https://download.kiwix.org/release/libkiwix/
GNU General Public License v3.0
112 stars 55 forks source link

Kiwix serve UI language is not detected (from Browser language) and always in English #1039

Closed kelson42 closed 5 months ago

kelson42 commented 6 months ago

I don't know how the language detection is supposed to work, but if I visit https://library.kiwix.org/ with a browser with Accept-Language: it I get redirected to https://library.kiwix.org/#lang=ita and the interface stays in English, while the content is mostly about Italian language wikis with Italian descriptions.

Screenshot_20240101_121518

Reorted first by @nemobis at https://github.com/kiwix/libkiwix/issues/1038#issuecomment-1873260728

kelson42 commented 6 months ago

@veloman-yunkan Can you please fix that one? This is pretty serious problem.

rgaudin commented 6 months ago

AFAIK the UI language is applied client-side, based on the userlang key on the Local Storage. The #lang=ita in the URL changes the filter for the content. it's unrelated to the UI.

UI lang can be changed with ?userlang=it though. That's what the UI lang switcher does.

If I understand it right, until there's this key in LocalStorage, it uses a defaultUserLanguage that is sent by the backend (with the value computed from Accept-Language).

Problem being that on library.kiwix.org we cache viewer_settings.js so that default value is not correct.

Two me there are two issues:

@kelson42 @veloman-yunkan WDYT ?

rgaudin commented 6 months ago

I've fixed it on Varnish and can confirm that a fresh browser with a supported Accept Language gets the proper UI directly now. https://github.com/kiwix/k8s/commit/d40cc56f16c0a529b12239126b9ee2a660d26c89

Please respond to the other question.

veloman-yunkan commented 6 months ago
  • Mixing server-side and client side for this is wrong IMO. We've decided to take the UI language management client side so we should parse the browser's data there and not rely on a server-side call.

There is a slight difference between client-side and server-side detection of browser language preferences:

The Accept-Language HTTP header in every HTTP request from the user's browser uses the same value for the navigator.languages property except for the extra qvalues (quality values) field (e.g. en-US;q=0.8).

If this can be ignored, then nothing prevents us from running the browser language detection fully on the client side.

mgautierfr commented 6 months ago

If this can be ignored, then nothing prevents us from running the browser language detection fully on the client side.

This can be ignore I think. At least, we must be able to "sort" the languages to use the one preferred by the user. The real qvalues are not so useful I think.

veloman-yunkan commented 5 months ago

Then the next question is why it is justified to spend any effort on this. The current implementation assumes that viewer_settings.js is not cached (so that a couple of kiwix-serve options are properly set in the viewer). If we are not going to change that too, I don't see any compelling reason to move the selection of the default user language from backend to frontend (which will inevitably perform worse for those users, if any, who deliberately set meaningful qvalues).

rgaudin commented 5 months ago

viewer_settings.js contains instance-related data. Those can even be considered default/fallback values as one can imagine that we will allow users to select those in the future.

As such (instance defaults), it should be cached.

The problem is that defaultUserLanguage is not an instance default, it's entirely based on the user's browser info.

If it comes from the browser and every other piece of language management is done entirely in the browser (client side), then it makes no sense to me to keep that in the backend.

Sure it works but this design is unsound. I'm not a maintainer here so I'll leave you with the decision to “spend any effort on this” or not.

veloman-yunkan commented 5 months ago

@rgaudin Your argument is convincing to an extent that my previous comment looks silly. I will provide a fix.