next-translate-localekeys-generator 1.0.0
Install from the command line:
Learn more about npm packages
$ npm install @elementrics/next-translate-localekeys-generator@1.0.0
Install via package.json:
"@elementrics/next-translate-localekeys-generator": "1.0.0"
About this version
Intended for use in conjunction with next-translate. Used for generating all possible keys for the useTranslation hook with type safety.
npm install --save-dev next-translate-localekeys-generator
npx next-translate-localekeys-generate
- Translation Files are in /examples/locales/en
- Goal to get all my locale keys in the generated (/examples/generated) folder with typescript support and translation comments
- Using default seperator for next-translate
- run
npm next-translate-localekeys-generate --rootDir ./examples/locales/en --outDir ./examples/generated --typescriptEnabled --translationsEnabled - Go to your file where you want to use the useTranslation hook
import { FC } from 'react';
import useTranslation from 'next-translate/useTranslation';
import { LocaleKeys } from './examples/generated/locale_keys.g';
export const DivWithTitleFromCommonNamespace: FC = () => {
const { t } = useTranslation(LocaleKeys.common);
return <div>{t(LocaleKeys._common.title)}</div>;
}To get all configurations possible:
npx next-translate-localekeys-generate --help
| Flag | Description | Type | Default | Required |
|---|---|---|---|---|
rootDir |
where the locale translation json files are located. | string |
- | * |
outDir |
where the generated output should be placed in. | string |
- | * |
errDir |
where the error file should be placed in. | string |
outDir |
|
typescriptEnabled |
enables typescript with type safety and readonly modifier. | boolean |
- | |
translationsEnabled |
enables translation comments. | boolean |
- | |
nsSeparator |
char to split namespace from key. | string |
":" |
|
keySeparator |
change the separator that is used for nested keys. | string |
"." |
Details
- next-translate-localekeys-generator
-
elementrics
- over 3 years ago
- ISC
- 4 dependencies
Assets
- next-translate-localekeys-generator-1.0.0-npm.tgz
Download activity
- Total downloads 12
- Last 30 days 0
- Last week 0
- Today 0