Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@bothrs/translations

Package Overview
Dependencies
Maintainers
7
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bothrs/translations

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

  • 1.1.4
  • Source
  • npm
  • Socket score

Version published
Maintainers
7
Created
Source

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

FAQs

Package last updated on 17 Mar 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc