2.1.13 • Published 12 months ago

@sundaeswap/i18n-config v2.1.13

Weekly downloads
-
License
MIT
Repository
github
Last release
12 months ago

i18n-config

This is a base shared i18n.ts which all other i18n.ts's can require as a plugin.

Installation

To install, run:

bun run add i18next react-i18next @sundaeswap/i18n-config -D

And then from your root project's i18n.ts file, init the base config like this:

import { InitOptions } from "i18next";
import LanguageDetector from "i18next-browser-languagedetector";
import resourcesToBackend from "i18next-resources-to-backend";
import { i18next, i18nDefaultOptions } from "@sundaeswap/i18n-config";

// in case you want to extend the default options
const options: InitOptions = {
  ...i18nDefaultOptions(),
  fallbackLng: "en",
};

i18next
  // setup your `i18n` to load the proper files
  .use(
    resourcesToBackend((language, namespace, callback) => {
      console.debug(
        "[i18n]: loading '%s' language; '%s' namespace",
        language,
        namespace
      );
      import(`/path/to/translations/${language}/${namespace}.json`)
        .then((resources) => {
          console.debug(
            "[i18n]: successfully loaded '%s' language; '%s' namespace",
            language,
            namespace
          );
          callback(null, resources);
        })
        // errorhandling
        .catch((error) => {
          CALL_YOUR_ERROR_HANDLING_FN(error);
        });
    })
  )
  // extend more packages if necessary
  .use(LanguageDetector)
  // init with your desired options
  .init(options);

export default i18next;

Storybook

In case you're running an app that's using i18n, make sure to properly set up like this:

// .storybook/i18next.js
import { i18next, i18nDefaultOptions } from "@sundaeswap/i18n-config";

const supportedLngs = ["en", "fr"];
const options = { ...i18nDefaultOptions, supportedLngs };

i18next.init(options);

supportedLngs.forEach((lang) => {
  i18next.addResources(
    lang,
    undefined,
    require(`/path/to/translation/${lang}/file.json`)
  );
});

export { i18next };

// .storybook/main.js
module.exports = {
  ...config,
  addons: [...plugins, "storybook-react-i18next"],
};
2.1.13

12 months ago

2.1.12

12 months ago

2.1.11

12 months ago

2.1.10

1 year ago

2.1.9

1 year ago

2.1.8

1 year ago

2.1.7

1 year ago

2.1.6

1 year ago

2.1.5

1 year ago

2.1.4

1 year ago

2.1.3

1 year ago

2.1.2

1 year ago

2.1.1

1 year ago

2.1.0

1 year ago