cal/server/lib/i18n.ts
Mihai C 8d6fec79d3
feat: add translations for emails and type error fixes overall (#994)
* feat: add translations for forgot password email and misc

* fix: type fixes

* feat: translate invitation email

* fix: e2e tests

* fix: lint

* feat: type fixes and i18n for emails

* Merge main

* fix: jest import on server path

* Merge

* fix: playwright tests

* fix: lint

Co-authored-by: Bailey Pumfleet <pumfleet@hey.com>
2021-10-25 14:05:21 +01:00

19 lines
668 B
TypeScript

import i18next from "i18next";
import { i18n as nexti18next } from "next-i18next";
import { serverSideTranslations } from "next-i18next/serverSideTranslations";
export const getTranslation = async (locale: string, ns: string) => {
const create = async () => {
const { _nextI18Next } = await serverSideTranslations(locale, [ns]);
const _i18n = i18next.createInstance();
_i18n.init({
lng: locale,
resources: _nextI18Next.initialI18nStore,
fallbackLng: _nextI18Next.userConfig?.i18n.defaultLocale,
});
return _i18n;
};
const _i18n = nexti18next != null ? nexti18next : await create();
return _i18n.getFixedT(locale, ns);
};