Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
@smg-automotive/i18n-pkg
Advanced tools
A boilerplate package setup
Shared i18n setup for React application
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 })}
count = 0
, cookies.zero
will be returnedcount = 1
, cookies.one
will be returnedcount > 2
, cookies.other
will be returnedIn 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';
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
A boilerplate package setup
The npm package @smg-automotive/i18n-pkg receives a total of 653 weekly downloads. As such, @smg-automotive/i18n-pkg popularity was classified as not popular.
We found that @smg-automotive/i18n-pkg demonstrated a healthy version release cadence and project activity because the last version was released less than 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
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.