Skip to content

Commit

Permalink
feature: multi lang
Browse files Browse the repository at this point in the history
  • Loading branch information
CMonnin committed Jul 25, 2024
1 parent 714487e commit d592c30
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
File renamed without changes.
File renamed without changes.
3 changes: 1 addition & 2 deletions src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import pictureNamingTask from "./pictureNamingTask";
import { experimentSettings } from "./fetchAndParse";

pictureNamingTask(Number(experimentSettings.initialDifficulty));
pictureNamingTask(1);
6 changes: 4 additions & 2 deletions src/pictureNamingTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import i18n from "./services/i18n.ts";
*
*
*/

i18n.init;
const welcomeText = i18n.t("welcome");
console.log("++++++++++++++");
console.log(welcomeText);
Expand All @@ -31,6 +31,8 @@ let totalNumberOfTrialsToRun = Number(
);
let advancementSchedule = Number(experimentSettings.advancementSchedule);
let regressionSchedule = Number(experimentSettings.regressionSchedule);
// add logic to initialize with initialDifficulty
// let intialDifficulty = Number(experimentSettings.initialDifficulty);
let language = experimentSettings.language;
let seed = experimentSettings.seed;

Expand Down Expand Up @@ -124,7 +126,7 @@ export default function pictureNamingTask(difficultyLevelParam: number) {

const welcome = {
type: HtmlKeyboardResponsePlugin,
stimulus: `welcome`,
stimulus: `${welcomeText}`,
};

const preload = {
Expand Down
13 changes: 7 additions & 6 deletions src/services/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@ import i18n from "i18next";
import Backend from "i18next-http-backend";
import { experimentSettings } from "../fetchAndParse";

i18n.use(Backend).init({
initImmediate: false,
console.log(experimentSettings.language);
await i18n.use(Backend).init({
// initImmediate: true,
lng: experimentSettings.language,
fallbackLng: "en",
preload: ["en", "fr"],
ns: ["translation"],
defaultNS: "translation",
backend: {
loadPath: "../translations/{{lng}}/{{ns}}.json",
loadPath: "/locales/{{lng}}/{{ns}}.json",
},
});
// this will only work if initImmediate is set to false, because it's async
console.log("**** i18n init");
console.log(i18n.t("welcome"));
console.log(i18n.t("welcome", { lng: "fr" }));
//console.log("**** i18n init");
//console.log(i18n.t("welcome"));
//console.log(i18n.t("welcome", { lng: "fr" }));
export default i18n;

0 comments on commit d592c30

Please sign in to comment.