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

@smg-automotive/i18n-pkg

Package Overview
Dependencies
Maintainers
1
Versions
58
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@smg-automotive/i18n-pkg

A boilerplate package setup

  • 1.1.5-display-trans-keys-94f841ef1fb799633e9aa34d5f5c28ce8ac5e455.1
  • display-trans-keys
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
662
increased by43.91%
Maintainers
1
Weekly downloads
 
Created
Source

SMG Automotive I18n

Shared i18n setup for React application

CircleCI

Usage

npm install @smg-automotive/i18n-pkg

In your project (preferrably server-side) pass the translation files to the I18nProvider:

import type { AppProps } from 'next/app';
import { filterDictionaryScopes, I18nProvider } from '@smg-automotive/i18n-pkg';

import DeDictionary from './locales/de/dict.json';
import ItDictionary from './locales/it/dict.json';
import FrDictionary from './locales/fr/dict.json';
import EnDictionary from './locales/en/dict.json';

const dictionaries = {
  de:  DeDictionary,
  fr:  FrDictionary,
  it:  ItDictionary,
  en:  EnDictionary,
};

const MyApp = ({ Component, pageProps }: AppProps) => {
  return (
    <I18nProvider
      lngDict={filterDictionaryScopes({
        dictionaryScopes: pageProps.scopes,
        dictionaries: dictionaries,
        language: pageProps.lang,
      });}
      language={pageProps.lang}
      onMissingTranslation={(error: string) => {
        console.error(`Missing translation: ${error}`);
      }}
    >
      <Component {...pageProps} />
    </I18nProvider>
  );
};

export default MyApp;

To use the t function in the case above you need to specify before the key if the translation is common across MS24 and AS24 or specific to one universe.

i18n.t('specific.homeSearchForm.subtitle')

or

i18n.t('common.homeSearchForm.lastSearch')

In case you need a plural and a singular version for 1 translation:

In your JSON file:

"plural": {
            "cookies": {
                "zero": "We did not bake anything",
                "other": "We baked {{ count }} cookies",
                "one": "We baked a cookie"
            }
        }

In your component/page:

{i18n.t('index.plural', { count: 1 })}
  • If count = 0, cookies.zero will be returned
  • If count = 1, cookies.one will be returned
  • If count > 2, cookies.other will be returned

Test

In order to test the package, you should create the following folders and file: __ mocks __>@smg-automotive>i18n-pkg.tsx In the i18n-pkg.tsx:

export { useI18n, Trans } from '@smg-automotive/i18n-pkg/dist/__mocks__/index';

Development

npm run build

You can link your local npm package to integrate it with any local project:

cd i18n-pkg
npm run build
cd email-templates
npm link ../i18n-pkg

FAQs

Package last updated on 19 Dec 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