@stack-spot/portal-translate
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

Translate

This is a very simple library common to every StackSpot Web project. This is responsible for implementing internationalization and currently supports english and portuguese.

Main functionalities

  1. Get the current language: getLanguage, useLanguage.
  2. Change the current language: setLanguage.
  3. Get the translations from a dictionary according to the current language: translate, useTranslate.
  4. Interpolate a string with variables: interpolate.

Example on React

import { useTranslate, interpolate, Dictionary } from '@stack-spot/portal-translate'

const MyComponent = ({ username }: { username: string }) => {
  const t = useTranslate(dictionary)
  const language = useLanguage()

  return (
    <>
      <h1>{t.title}</h1>
      <p>{interpolate(t.hello, username, new Date().toLocaleString(language))}</p>
    </>
  )
}

const dictionary = {
  en: {
    title: 'Main page',
    hello: 'Hello $0, today it is $1.',
  },
  pt: {
    title: 'Página principal',
    hello: 'Olá $0, hoje é $1.',
  },
} satisfies Dictionary

Readme

Keywords

none

Package Sidebar

Install

npm i @stack-spot/portal-translate

Weekly Downloads

369

Version

1.1.0

License

none

Unpacked Size

19.8 kB

Total Files

19

Last publish

Collaborators

  • caiorezendezup
  • larissacostazup
  • leonardo.palis
  • rafamsilva-zup
  • lucasgarciazup
  • hiltonpaulozup
  • magno.lemos
  • tiagobalbinodesazup
  • carolinegoncalveszup
  • renanrodrigueszup
  • tarcisiogc
  • arthurbleilzup
  • tiagoperesfr