@solid-aria/i18n
v0.2.0
Published
Primitives for dealing with locale and layout direction.
Downloads
4,495
Readme
@solid-aria/i18n
Primitives for dealing with locale and layout direction.
I18nProvider
- Provides the locale for the application to all child components.useLocale
- Returns the current locale and layout direction.
Installation
npm install @solid-aria/i18n
# or
yarn add @solid-aria/i18n
# or
pnpm add @solid-aria/i18n
I18nProvider
I18nProvider
allows you to override the default locale as determined by the browser/system setting with a locale defined by your application (e.g. application setting). This should be done by wrapping your entire application in the provider, which will be cause all child elements to receive the new locale information via useLocale
.
How to use it
import { I18nProvider } from "@solid-aria/i18n";
function App() {
return (
<I18nProvider locale="fr-FR">
<YourApp />
</I18nProvider>
);
}
useLocale
useLocale
allows components to access the current locale and interface layout direction. By default, this is automatically detected based on the browser or system language, but it can be overridden by using the I18nProvider
at the root of your app.
useLocale
should be used in the root of your app to define the lang and dir attributes so that the browser knows which language and direction the user interface should be rendered in.
How to use it
import { useLocale } from "@solid-aria/i18n";
function App() {
const locale = useLocale();
return (
<div lang={locale().locale} dir={locale().direction}>
{/* your app here */}
</div>
);
}
Changelog
All notable changes are described in the CHANGELOG.md file.