Skip to content

ignaciolarranaga/intl-utils

Repository files navigation

intl-utils

This is an utility for internationalization of applications.

An example with NextJS will be as follows:

import withRouter, { WithRouterProps } from 'next/dist/client/with-router';
import buildTranslateFunction from 'intl-utils';

import translations from './translations';

function HomePage(props: WithRouterProps) {
  const t = buildTranslateFunction(translations, props.router.locale);

  return <p>{t('Hello World')}</p>
}

export default withRouter(HomePage);

Where translations.js is as follows:

/* spellchecker: disable */
module.exports = {
  "es": {
    "Hello World": "Hola mundo"
  },
  "fr": {
    "Hello World": "Bonjour le monde"
  },
  "it": {
    "Hello World": "Ciao mondo"
  },
  "pt": {
    "Hello World": "Olá, mundo"
  }
}

The structure of the file is:

module.exports = {
  LOCALE: {
    KEY: TRANSLATED_KEY
  }
}

Where TRANSLATED_KEY is the translation of KEY on LOCALE

Please note that intl-utils-aws-translate can help you to automatically generate the translation files using AWS Translate.

Release Process

  • Commit your changes
  • Test your changes npm test
  • Adjust the version, e.g.: npm version patch
  • Build npm run build
  • Publish npm publish
  • Push the changes e.g. git push --tags && git push
  • Create the release in Github