Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- 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

Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
"highcharts": "^9.3.1",
"highcharts-react-official": "^3.1.0",
"i18next": "^22.0.3",
"i18next-browser-languagedetector": "^7.0.0",
"i18next-http-backend": "^3.0.2",
"identity-obj-proxy": "3.0.0",
"jest-axe": "^7.0.0",
Expand Down
9 changes: 9 additions & 0 deletions src/containers/WebComponentLoader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const WebComponentLoader = (props) => {
instructions,
theme,
loadRemixDisabled = false,
locale = "en",
outputOnly = false,
outputPanels = ["text", "visual"],
outputSplitView = false,
Expand Down Expand Up @@ -87,6 +88,8 @@ const WebComponentLoader = (props) => {
(state) => state.editor.renameFileModalShowing,
);

const { i18n } = useTranslation();

const [cookies, setCookie] = useCookies(["theme", "fontSize"]);
const themeDefault = window.matchMedia("(prefers-color-scheme:dark)").matches
? "dark"
Expand Down Expand Up @@ -127,6 +130,12 @@ const WebComponentLoader = (props) => {
}
}, [projectOwner, justLoaded]);

useEffect(() => {
if (locale) {
i18n.changeLanguage(locale);
}
}, [locale, i18n]);

useProject({
reactAppApiEndpoint,
projectIdentifier: projectIdentifier,
Expand Down
18 changes: 18 additions & 0 deletions src/containers/WebComponentLoader.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,19 @@ jest.mock("../hooks/useProjectPersistence", () => ({
useProjectPersistence: jest.fn(),
}));

const mockedChangeLanguage = jest.fn(() => new Promise(() => {}));

jest.mock("react-i18next", () => ({
useTranslation: () => {
return {
i18n: {
changeLanguage: mockedChangeLanguage,
},
t: (str) => str,
};
},
}));

let store;
let cookies;
const code = "print('This project is amazing')";
Expand Down Expand Up @@ -69,6 +82,7 @@ describe("When initially rendered", () => {
instructions={instructions}
authKey={authKey}
theme="light"
locale="es-LA"
/>
</CookiesProvider>
</Provider>,
Expand All @@ -90,6 +104,10 @@ describe("When initially rendered", () => {
expect(window.syntaxHighlight).toEqual(window.Prism);
});

test("it sets the language in i18n", () => {
expect(mockedChangeLanguage).toHaveBeenCalledWith("es-LA");
});

describe("react app API endpoint", () => {
describe("when react app API endpoint isn't set", () => {
beforeEach(() => {
Expand Down
7 changes: 0 additions & 7 deletions src/utils/i18n.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import i18n from "i18next";
import { initReactI18next } from "react-i18next";
import LanguageDetector from "i18next-browser-languagedetector";
import HttpBackend from "i18next-http-backend";

i18n
// detect user language
// learn more: https://github.com/i18next/i18next-browser-languageDetector
.use(LanguageDetector)
// pass the i18n instance to react-i18next.
.use(initReactI18next)
// init i18next
Expand Down Expand Up @@ -104,9 +100,6 @@ i18n
load: "currentOnly", // otherwise for fr-FR it's load ['fr-FR', 'fr']

// nonExplicitSupportedLngs: true, // allows locale variants on supportedLngs
detection: {
order: ["path"], // only use path to detect local for now
},

interpolation: {
escapeValue: false, // not needed for react!!
Expand Down
1 change: 1 addition & 0 deletions src/web-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class WebComponent extends HTMLElement {
"identifier",
"instructions",
"load_remix_disabled",
"locale",
"output_only",
"output_panels",
"output_split_view",
Expand Down
12 changes: 1 addition & 11 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1611,7 +1611,7 @@ __metadata:
languageName: node
linkType: hard

"@babel/runtime@npm:^7.0.0, @babel/runtime@npm:^7.11.2, @babel/runtime@npm:^7.12.1, @babel/runtime@npm:^7.12.5, @babel/runtime@npm:^7.15.4, @babel/runtime@npm:^7.16.3, @babel/runtime@npm:^7.17.8, @babel/runtime@npm:^7.18.3, @babel/runtime@npm:^7.20.6, @babel/runtime@npm:^7.20.7, @babel/runtime@npm:^7.23.2, @babel/runtime@npm:^7.24.1, @babel/runtime@npm:^7.5.5, @babel/runtime@npm:^7.8.4, @babel/runtime@npm:^7.9.2":
"@babel/runtime@npm:^7.0.0, @babel/runtime@npm:^7.11.2, @babel/runtime@npm:^7.12.1, @babel/runtime@npm:^7.12.5, @babel/runtime@npm:^7.15.4, @babel/runtime@npm:^7.16.3, @babel/runtime@npm:^7.17.8, @babel/runtime@npm:^7.18.3, @babel/runtime@npm:^7.20.6, @babel/runtime@npm:^7.20.7, @babel/runtime@npm:^7.24.1, @babel/runtime@npm:^7.5.5, @babel/runtime@npm:^7.8.4, @babel/runtime@npm:^7.9.2":
version: 7.25.7
resolution: "@babel/runtime@npm:7.25.7"
dependencies:
Expand Down Expand Up @@ -2816,7 +2816,6 @@ __metadata:
highcharts-react-official: ^3.1.0
html-webpack-plugin: 5.6.0
i18next: ^22.0.3
i18next-browser-languagedetector: ^7.0.0
i18next-http-backend: ^3.0.2
identity-obj-proxy: 3.0.0
jest: ^29.1.2
Expand Down Expand Up @@ -10131,15 +10130,6 @@ __metadata:
languageName: node
linkType: hard

"i18next-browser-languagedetector@npm:^7.0.0":
version: 7.2.1
resolution: "i18next-browser-languagedetector@npm:7.2.1"
dependencies:
"@babel/runtime": ^7.23.2
checksum: 159958be2d8f19444e9378512c36c2bf13a8ab85eddac2fc0000198a03dbc28c73a6f44594ab040b242bdc82dfeabb7c1ab805884b5438ee0a48a8e2b52ca062
languageName: node
linkType: hard

"i18next-http-backend@npm:^3.0.2":
version: 3.0.2
resolution: "i18next-http-backend@npm:3.0.2"
Expand Down
Loading