Skip to content

Handle short locale ids#120

Open
lx1 wants to merge 5 commits into
pressidium:masterfrom
lx1:handle_short_locale
Open

Handle short locale ids#120
lx1 wants to merge 5 commits into
pressidium:masterfrom
lx1:handle_short_locale

Conversation

@lx1

@lx1 lx1 commented Mar 16, 2025

Copy link
Copy Markdown

My browser locale id, as reported by navigator.language, is "it".
In PCC config, the corresponding locale is named "it-IT", so the translation is not used and I always get the default "en" version.
I think that the two ids should match: when the requested language is "it", and "it-something" is available, it should be used.

My browser locale id is "it". In PCC config, the locale is named "it-IT". The two should match.
@lx1 lx1 marked this pull request as ready for review March 16, 2025 12:27

@over-engineer over-engineer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, @lx1!

Thanks for the PR—we appreciate your work!

Just like PR #117, we need to avoid modifying any files in the src/client/lib directory.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All files under the src/client/lib/ directory belong to the orestbida/cookieconsent library. We'd prefer not to modify these files directly to simplify future maintenance. If we edit this file, we’ll have to manually reapply changes after every library update.

Let's keep the contents of the src/client/lib/cookieconsent.js file as is. We could include any new JavaScript code elsewhere.

@lx1

lx1 commented Mar 21, 2025

Copy link
Copy Markdown
Author

Hey, @lx1!

Thanks for the PR—we appreciate your work!

Just like PR #117, we need to avoid modifying any files in the src/client/lib directory.

Maybe there are better solutions, but the possible way seems to me to change the settings.languages object when settings.auto_language === "browser", so for ex. the "it-IT" key becomes only "it", since cookieconsent.js expects the key name to be exactly the same as the browser locale id. (for instance, I did not check other languages). The code is trivial, but it seems it has to be executed before the code from cookieconsent.js.
I tried to put it at the top of src/client/index.js or in a file imported into it, but the "compiler" which generates bundle.client.js always defers my code after the code from cookieconsent.js. May I ask how could I impose an order in the import of ja files? Or if there is another solution? The code would be simple:

if(pressidiumCCClientDetails.settings.auto_language === "browser"){ for (var k in pressidiumCCClientDetails.settings.languages) { if(k.indexOf('-') !== -1){ pressidiumCCClientDetails.settings.languages[k.split("-")[0]] = pressidiumCCClientDetails.settings.languages[k]; // the next delete is not strictly necessary, we may leave the "extended" key there delete pressidiumCCClientDetails.settings.languages[k]; } } }

@lx1 lx1 requested a review from over-engineer April 1, 2025 17:54
@lx1

lx1 commented May 9, 2025

Copy link
Copy Markdown
Author

Hallo. I updated my branch to 1.8.0.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants