Skip to content

Conversation

@Ducica
Copy link

@Ducica Ducica commented Feb 6, 2026

  • app was using navigator.language which is always
  • browser setting. The change enables using localization
  • based on app settings and using translated strigns that exist in
  • citeproc library

Description

Currently, the citation is always generated based on browser selected locale. This change uses language selected in the app. Normally, in invenio you only have access to language code, so if the language setting in the browser starts with this language code it sends the entire locale i.e. en_GB, if not, it only sends en. The citeproc library has good behavior, even in case only language code is provided.

Before:
image

After:

image

Noter that benefit depens on the citation style i.e. some styles that contain more text, other than record data benefit more.

Please let us know what you think.

Reminder

By using GitHub, you have already agreed to the GitHub’s Terms of Service including that:

  1. You license your contribution under the same terms as the current repository’s license.
  2. You agree that you have the right to license your contribution under the current repository’s license.

Copy link
Member

@Samk13 Samk13 left a comment

Choose a reason for hiding this comment

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

LGTM 👍 Thanks for this!

Using the UI language as a fallback while keeping the more specific browser locale when it matches makes the behavior more predictable.

Comment on lines 61 to 63
const citationLocale = navigator.language.startsWith(i18next.language)
? navigator.language
: i18next.language;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const citationLocale = navigator.language.startsWith(i18next.language)
? navigator.language
: i18next.language;
const navLang = (navigator.language || "").toLowerCase();
const uiLang = (i18next.language || "").toLowerCase();
const citationLocale =
uiLang && navLang.startsWith(uiLang)
? navigator.language
: i18next.language || navigator.language;

Would it make sense to normalize casing and add a fallback here to avoid en-US vs en-us mismatches and prevent locale=undefined if i18next.language isn’t set yet, while keeping the same behavior otherwise?

Copy link
Author

Choose a reason for hiding this comment

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

@Samk13 Thanks for the feedback, generally, I've never had issue with missing values in context of i18next or navigator, but your suggestion is more defensive, so I've modified it like you proposed. Regards

* app was using navigator.language which is always
* browser setting. The change enables using localization
* based on app settings and using translated strigns that exist in
* citeproc library
@Ducica Ducica force-pushed the oarepo-contribution-citation-localization-based-on-app-locale branch from 858532e to 548d5b7 Compare February 9, 2026 07:39
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