1.0.5 • Published 3 months ago

i18n-table v1.0.5

Weekly downloads
-
License
MIT
Repository
-
Last release
3 months ago

Installation

npm install i18n-table

Get started

  1. Import TranslationManager and styles
import TranslationManager from "i18n-table";
import "i18n-table/dist/index.css";
  1. Prepare translations
const translations = {
  en: {
    colors: {
      red: "Red",
      blue: "Blue",
      green: "Green",
    },
  },
  es: {
    colors: {
      red: "Rojo",
      green: "Verde",
    },
  },
};

translations object should have locales as keys and objects or nested objects as values.

  1. Prepare locales with full and local names.

!IMPORTANT The locale property have to match with locale used in the first step.

const locales = [
  { locale: "en", fullName: "English", localName: "English" },
  { locale: "es", fullName: "Spanish", localName: "Español" },
];
  1. Render TranslationManager on your page
export const App = () => {
  const onSave = (translation) => {
    /* Handle saving translations - structure is the same as in the step 2. */
  };

  return <TranslationManager translations={translations} locales={locales} onSave={onSave} />;
};
  1. If you want to write your own styles, copy /src/lib/styles.css file to your project, modify it and import it instead of i18n-table/dist/index.css

  2. You can also customize header translations.

const componentTranslations = {
  save: t("save"),
  search: t("search"),
  select: t("select"),
  translationKey: t("translationKey"),
};

export const App = () => {
  const onLocaleChange = (locale) => i18n.setLocale(locale);

  return (
  <TranslationManager
    {/* ... */}
    componentTranslations={componentTranslations}
    onLocaleChange={onLocaleChange}
  />
)
};

License

Like every package maintained by Vazco, i18n-table package is MIT licensed.

1.0.5

3 months ago

1.0.4

4 months ago

1.0.3

5 months ago

1.0.2

7 months ago

1.0.1

7 months ago

1.0.0

8 months ago

0.1.1

8 months ago

0.1.0

8 months ago