Skip to content

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

Next-translate LocaleKeys Generator

Intended for use in conjunction with next-translate. Used for generating all possible keys for the useTranslation hook with type safety.

How to install

npm install --save-dev next-translate-localekeys-generator

How to run

npx next-translate-localekeys-generate

Code Example

Requirements

  1. Translation Files are in /examples/locales/en
  2. Goal to get all my locale keys in the generated (/examples/generated) folder with typescript support and translation comments
  3. Using default seperator for next-translate

Actions

  1. run npm next-translate-localekeys-generate --rootDir ./examples/locales/en --outDir ./examples/generated --typescriptEnabled --translationsEnabled
  2. 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>;
}

Configuration

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


Assets

  • next-translate-localekeys-generator-1.0.0-npm.tgz

Download activity

  • Total downloads 12
  • Last 30 days 0
  • Last week 0
  • Today 0

Recent versions

View all