Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@chickaree/language-loader
Advanced tools
A React hook for loading languages suitable for @wikimedia/react.i18n.
import Banana from 'banana-i18n';
import useLanguageLoader from '@chickaree/language-loader';
async function languageLoader(lang) {
const { default: messages } = await import(`../i18n/${lang}.json`);
return messages;
}
function Demo() {
const [locale, messages] = useLanguageLoader(languageLoader);
const banana = new Banana(locale, {
messages,
});
return (
<h1>{banana.i18n('hello')}</h1>
);
}
useLanguageLoader(
languageLoader: (lang: string) => Promise<object>
initialLanguages: string[] = []
initialMessages: object = {}
): [locale: string, messages: object, languages: string[]]
languageLoader
is a function that returns a promise (or an async function). The Promise should resolve to an object in the shame of { messageKey: "messageValue" }
. The function will be executed for every language the user has specified as well as the fallback languages. The function should not be created on every render or it may cause the browser to go into an infinite loop. It is better to use a named function (see example) or React's useCallback hook.initialLanguages
is an array of initial languages/locales to be used. This is useful for server-side rendering or static page generation where the initial render should be a specific language.initialMessages
is an object in the shape of: { langCode: { messageKey: "messageValue" } }
. Since the languageLoader
is only executed on theThe hook will return an array with 3 values. The first locale that contains messages, the messages object, and all of the languages the user might be interested in. The first two values can be passed direclty into the IntlProvider
provided by @wikimedia/react.i18n. The last value can be used to provide suggestions in a language switcher UI element.
FAQs
useLanguageLoader React hook
We found that @chickaree/language-loader 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.