![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
@solid-primitives/i18n
Advanced tools
Library of primitives for providing internationalization support.
npm i @solid-primitives/i18n
# or
pnpm add @solid-primitives/i18n
# or
yarn add @solid-primitives/i18n
createI18nContext
Creates a method for internationalization support. This primitive set is largely inspired by dlv and passes all its tests.
import { I18nContext, createI18nContext, useI18n } from "@solid-primitives/i18n";
const App: Component = () => {
const [t, { add, locale, dict }] = useI18n();
const [name, setName] = createSignal("Greg");
const addLanguage = () => {
add("sw", { hello: "hej {{ name }}, hur mar du?" });
locale("sw");
};
return (
<>
<button onClick={() => locale("fr")}>fr</button>
<button onClick={() => locale("en")}>en</button>
<button onClick={() => locale("unknownLanguage")}>unknown language</button>
<button onClick={addLanguage}>add and set swedish</button>
<input value={name()} onInput={e => setName(e.target.value)} />
<hr />
<h1>{t("hello", { name: name() }, "Hello {{ name }}!")}!</h1>
<p>{locale()}</p>
<pre>
<code>{JSON.stringify(dict("sw"), null, 4)}</code>
</pre>
</>
);
};
const dict = {
fr: {
hello: "bonjour {{ name }}, comment vas-tu ?",
},
en: {
hello: "hello {{ name }}, how are you?",
},
};
const value = createI18nContext(dict, "fr");
<I18nContext.Provider value={value}>
<App />
</I18nContext.Provider>;
createChainedI18n
Creates a chained dictionary and manages the locale. Provides a proxy wrapper around translate so you can do chained calls that always returns with the current locale. IE t.hello()
import { createChainedI18n } from "@solid-primitives/i18n";
const dictionaries = {
fr: {
hello: "bonjour {{ name }}, comment vas-tu ?",
goodbye: ({ name }: { name: string }) => `au revoir ${name}`,
},
en: {
hello: "hello {{ name }}, how are you?",
goodbye: ({ name }: { name: string }) => `goodbye ${name}`,
},
};
const [t, { locale, setLocale, getDictionary }] = createChainedI18n({
dictionaries,
locale: "en", // Starting locale
});
createEffect(() => {
t.hello({ name: "Mathiew" });
});
createChainedI18nContext
Creates chained I18n state wrapped in a Context Provider to be shared with the app using the component tree.
import { createChainedI18nContext } from "@solid-primitives/i18n";
const { I18nProvider, useI18nContext } = makeChainedI18nContext({
dictionaries,
locale: "en", // Starting locale
});
export const useI18n = () => {
const context = useI18nContext();
if (!context) throw new Error("useI18n must be used within an I18nProvider");
return context;
};
const App: Component = () => {
const [t, { locale, setLocale, getDictionary }] = useI18n();
const [name, setName] = createSignal("Greg");
return (
<>
<button onClick={() => setLocale("fr")}>fr</button>
<button onClick={() => setLocale("en")}>en</button>
<button onClick={addLanguage}>add and set swedish</button>
<input value={name()} onInput={e => setName(e.target.value)} />
<hr />
<h1>{t.hello({ name: name() })}!</h1>
<p>{locale()}</p>
<p>{t.goodbye({ name: name() })}</p>
</>
);
};
<I18nContext.Provider value={value}>
<App />
</I18nContext.Provider>;
useScopedI18n
Use useScopedI18n
to create a module-specific translate.
const dict = {
en: {
login: {
username: 'User name',
password: 'Password',
login: 'Login'
},
fr: {
...
}
}
}
export const LoginView = () => {
const [t] = useScopedI18n('login');
return <>
<div>{t('username')}<input /></div>
<div>{t('password')}<input /></div>
<button>{t('login') }</button>
</>
}
You may view a working example of createI18nContext here: https://codesandbox.io/s/use-i18n-rd7jq?file=/src/index.tsx
See CHANGELOG.md
FAQs
Library of primitives for providing internationalization support.
The npm package @solid-primitives/i18n receives a total of 3,439 weekly downloads. As such, @solid-primitives/i18n popularity was classified as popular.
We found that @solid-primitives/i18n demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers 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
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.