Integrating i18next for a plugin


For Obsidian Github Publisher, i wanted to update the translation file to using i18next, because some autocompletion will help me a lot during update.

I tryed to do it, but get undefined everywhere, without error in console.

I created the file i18next.ts in plugin/i18n and each translation file is in json
My i18next.ts file :

import i18next from 'i18next';
import {moment} from "obsidian";
import * as en from './locales/en.json';
import * as de from './locales/de.json';
//import fr from "./locales/fr.json";

//detect language
const locale = moment.locale();
export const translationLanguage = locale ? moment.locale() : "en";

console.log("Init i18next")

    fallbackLng: "en",
    resources: {
        en: {
            translation: en,
        de: {
            translation: de,

I call the i18next like that : i18next.t('somethings')

Maybe Obsidian Plugin can’t use json file ?

This was solved on Discord, right?


I created two file :

First : i18next.ts

import {moment} from "obsidian";
import * as en from "./locales/en.json";
import * as fr from "./locales/fr.json";

export const ressources = {
	en: { translation: en },
	fr: { translation: fr },
} as const;

export const translationLanguage = Object.keys(ressources).find(i => i==moment.locale()) ? moment.locale() : "en";

Second : i18next.d.ts

import { ressources } from "./i18next";

declare module "i18next" {
    interface CustomTypeOptions {
        readonly resources: typeof ressources["en"];
        readonly returnNull: false

After, in my main.ts I added the init in the start:

			lng: translationLanguage,
			fallbackLng: "en",
			resources: ressources,