Skip to content

Add locale attribute instead of detecting language#1244

Merged
loiswells97 merged 6 commits into
mainfrom
add-locale-attribute
Sep 18, 2025
Merged

Add locale attribute instead of detecting language#1244
loiswells97 merged 6 commits into
mainfrom
add-locale-attribute

Conversation

@loiswells97

@loiswells97 loiswells97 commented Sep 18, 2025

Copy link
Copy Markdown
Contributor

Switches to determining the language from an attribute rather than detecting through i81n. This maintains independence from the setup of the host page whilst allowing the web component to be consistent with the host in its choice of language.

closes https://github.com/RaspberryPiFoundation/digital-editor-issues/issues/883

@loiswells97
loiswells97 temporarily deployed to previews/1244/merge September 18, 2025 11:46 — with GitHub Actions Inactive
@loiswells97
loiswells97 temporarily deployed to previews/1244/merge September 18, 2025 14:30 — with GitHub Actions Inactive

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the internationalization setup to use an explicit locale attribute instead of automatic browser language detection. This change provides more control over the language used in the web component.

  • Remove i18next-browser-languagedetector dependency and related configuration
  • Add locale attribute support to web component with default value of "en"
  • Implement useEffect to set language via i18n.changeLanguage when locale changes

Reviewed Changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/web-component.js Adds "locale" to the observed attributes array
src/utils/i18n.js Removes LanguageDetector import and configuration
src/containers/WebComponentLoader.jsx Adds locale prop with default "en" and useEffect to change language
src/containers/WebComponentLoader.test.js Adds mock for react-i18next and test for language setting
package.json Removes i18next-browser-languagedetector dependency
CHANGELOG.md Documents the feature change

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread src/containers/WebComponentLoader.test.js Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@loiswells97
loiswells97 temporarily deployed to previews/1244/merge September 18, 2025 15:03 — with GitHub Actions Inactive

@adrian-rpf adrian-rpf left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good code and changes make sense.
⚠️ Requires update to the readme.md for new attribute

@adrian-rpf adrian-rpf left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looking good

@loiswells97
loiswells97 merged commit 6d48167 into main Sep 18, 2025
8 checks passed
@loiswells97
loiswells97 deleted the add-locale-attribute branch September 18, 2025 15:51
@loiswells97 loiswells97 mentioned this pull request Sep 19, 2025
loiswells97 added a commit that referenced this pull request Sep 19, 2025
### Added

- Ability to translate demo project instructions (#1230)
- Translations (#1212)

### Changed

- Improved status bar styling (#1221)
- Added method to translate last saved time (#1223)
- Deleting unused strings and components (#1225)
- Determine locale from web component attribute instead of browser path
(#1244)

### Fixed

- CrowdIn issue for pluralised strings with no `one` version (#1234)
- Update `imagePanel.gallery` string to remove Title Casing for
consistency (#1238)
- Update `imageUploadButton.uploadImage` string to remove Title Casing
for consistency (#1238)
- Fixed typo in the `en.json` translation file (#1241)

### Removed

- Remove unused translation string `filePanel.images` (#1238)
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.

3 participants