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

@bothrs/translations

Package Overview
Dependencies
Maintainers
5
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.0.0-rc.4
  • rc
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
40
decreased by-47.37%
Maintainers
5
Weekly downloads
 
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'

export function AirtableExample() {
  const translationsLoaded = useAirtableTranslations({
    expirationTime: 60 * 1000,
    loadPath: api + 'translations',
    // Any other i18next options
    lng: 'nl',
    fallbackLng: 'nl',
  })
  return <div>{translationsLoaded ? i.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'

export function GenericExample() {
  const ready = useTranslations({
    lng: 'nl',
    fetchOptions: {
      loadPath: 'https://api.i18next.com/example.json',
      parse: (text) => JSON.parse(text),
    },
  })
  return <div>{ready ? i.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 10 Feb 2022

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