@talixo-ds/translations
v2.0.1
Published
```bash npm install @talixo-ds/translations ```
Readme
@talixo-ds/translations
Installation
npm install @talixo-ds/translationsEntry points
@talixo-ds/translations— Browser-safe entry. Use for app code (React components, i18n setup). Exports:i18n,addResourcesForAllLocales,getMissingTranslations, andreact-i18nextre-exports. No Node-only modules.@talixo-ds/translations/node— Node-only entry. Use in scripts (e.g. fetch/upload translations to disk). Exports:fetchTranslations,uploadMissingKeys, and their option types. Requires Node (usespath,fs).
Importing (browser / app code)
import {
addResourcesForAllLocales,
useTranslation
} from "@talixo-ds/translations";Importing (Node scripts)
For build or CI scripts that fetch or upload translations:
import {
fetchTranslations,
uploadMissingKeys
} from "@talixo-ds/translations/node";Usage
Adding translations to the project
import { addResourcesForAllLocales } from "@talixo-ds/translations";
addResourcesForAllLocales(translationsFile as Record<string, any>);Fetching translations (Node script)
import { fetchTranslations } from "@talixo-ds/translations/node";
await fetchTranslations({
apiKey: process.env.LOCALISE_API_KEY,
saveTranslationsDirectory: [__dirname, "static", "translations"]
});Uploading missing keys (Node script)
import { uploadMissingKeys } from "@talixo-ds/translations/node";
await uploadMissingKeys({
apiKey: process.env.LOCALISE_API_KEY,
localTranslationsPath: [__dirname, "static", "translations", "all.json"]
});Usage with components
import { useTranslation } from "@talixo-ds/translations";
const { t } = useTranslation();
t("example.key");Migration from 1.x
If you previously imported fetchTranslations or uploadMissingKeys from @talixo-ds/translations, change the import to @talixo-ds/translations/node. See CHANGELOG.md for the 2.0.0 breaking changes.
