
Security News
Package Maintainers Call for Improvements to GitHub’s New npm Security Plan
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.
@translata/react
Advanced tools
Provides a react integration for Translata.
yarn add @translata/core @translata/react
Create a translator provider using a default locale and a factory function. The factory function gets the current active locale and should return a setup translator function which is created by createTranslator:
// AppTranslator.ts
import { createTranslator, withTranslations, withDefaultLocale } from '@translata/core';
import { createTranslatorProvider } from '@translata/react';
export default createTranslatorProvider('en', locale => createTranslator(
withTranslations('en', {
'message.greeting': 'Hello!',
'button.de': 'Goto german',
'button.en': 'Goto english'
}),
withTranslations('en', {
'message.greeting': 'Hallo!',
'button.de': 'Wechsel zu Deutsch',
'button.en': 'Wechsel zu Englisch'
})
withDefaultLocale(locale)
));
Wrap this Provider around your application:
// App.tsx
import AppTranslator from './AppTranslator';
import Component from './Component';
export default () => {
return (
<AppTranslator>
<Component />
</AppTranslator>
);
}
Use the translator context inside your components:
// Component.tsx
import AppTranslator from './AppTranslator';
export default () => {
// get the actual translator function.
const _ = AppTranslator.useTranslator();
// get the current active locale.
const locale = AppTranslator.useLocale();
// get a locale setter to change the locale on the context.
// this will reinvoke your translator factory function passed to createTranslatorProvider().
const setLocale = AppTranslator.useSetLocale();
// callback to change locale to "de"
const setLocaleToDe = useCallback(() => {
setLocale('de');
}, [])
// callback to change locale to "en"
const setLocaleToEn = useCallback(() => {
setLocale('en');
}, [])
// use the translata as you would without react.
return (
<div>
{_('message.greeting')}
<button disabled={locale === 'de'} onClick={setLocaleToDe}>{_('button.de')}</button>
<button disabled={locale === 'en'} onClick={setLocaleToDe}>{_('button.en')}</button>
</div>
);
}
FAQs
React integration for translata: The Composable Translation Utility
The npm package @translata/react receives a total of 1 weekly downloads. As such, @translata/react popularity was classified as not popular.
We found that @translata/react demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.
Product
Socket Firewall is a free tool that blocks malicious packages at install time, giving developers proactive protection against rising supply chain attacks.
Research
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.