1.2.0 • Published 1 year ago

@bothrs/translations v1.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Translations

A hook which loads the translations from an external source and initializes i18next.

  • Compatible with React Native & Web

Getting started

yarn add @bothrs/translations

Usage with Airtable

useAirtableTranslations returns a boolean which indicates if the translations are loaded. This can be used to hide the splashscreen.

import { useAirtableTranslations } from '@bothrs/translations'
import i18next from 'i18next'

export function AirtableExample() {
  const translationsLoaded = useAirtableTranslations({
    expirationTime: 60 * 1000,
    loadPath: api + 'translations',
    // Any other i18next options
    lng: 'nl',
    fallbackLng: 'nl',
  })
  return <div>{translationsLoaded ? i18next.t('Ready') : 'Loading'}</div>
}
NameExplanation
expirationTimeTime between translation refreshes in ms
loadPathThe endpoint from where the translations will be loaded

Airtable table structure

The table should have the folowing columns

column namemandatoryexplanation
keytruethe key that will be used in the i18next t method
en / nl / fr / ...truethe iso code of the supported languages
categoryfalseWe recommend to use a category column to group related records in airtable

Example Airtable base

Example Airtable base

Generic usage

useTranslations returns a boolean which indicates if the translations are loaded. This can be used to hide the splashscreen.

import { useTranslations } from '@bothrs/translations'
import i18next from 'i18next'

export function GenericExample() {
  const ready = useTranslations({
    lng: 'nl',
    fetchOptions: {
      loadPath: 'https://api.i18next.com/example.json',
      parse: (text) => JSON.parse(text),
    },
  })
  return <div>{ready ? i18next.t('Ready') : 'Loading'}</div>
}
NameExplanation
expirationTimeTime between translation refreshes in ms
loadPathThe endpoint from where the translations will be loaded
1.2.0

1 year ago

1.1.4

1 year ago

1.1.3

1 year ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.1

2 years ago

1.0.0-rc.5

2 years ago

0.3.0

2 years ago

1.0.0-rc.3

2 years ago

1.0.0-rc.4

2 years ago

1.0.0-rc.1

2 years ago

1.0.0-rc.2

2 years ago

1.0.0-rc.0

2 years ago

0.2.1

2 years ago

0.2.0

3 years ago

0.1.7

3 years ago

0.1.4

3 years ago

0.1.6

3 years ago

0.1.5

3 years ago

0.1.2

3 years ago

0.1.3

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago