![Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility](https://cdn.sanity.io/images/cgdhsj6q/production/97774ea8c88cc8f4bed2766c31994ebc38116948-1664x1366.png?w=400&fit=max&auto=format)
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
storybook-i18n
Advanced tools
A library for best-practice i18n addons in Storybook:
Requires storybook >=7.0.0
As an addon author, you can use this library by adding it as a dependency and adding the following to your src/manager.ts
and src/preview.ts
files:
src/manager.ts
export * from 'storybook-i18n/manager';
src/preview.ts
import type { Renderer, ProjectAnnotations } from '@storybook/types';
import i18n from 'storybook-i18n/preview';
import { withYourI18nDecorator } from './withYourDecorator';
const i18nDecorators = i18n?.decorators || [];
const preview: ProjectAnnotations<Renderer> = {
...i18n,
decorators: [...i18nDecorators, withYourI18nDecorator],
}
export default preview;
The currently selected locale is available in the locale
global, so you can access it in a decorator using the following snippet:
import { MyProvider } from 'your-i18n-library';
import { useGlobals } from '@storybook/manager-api';
const myDecorator = (story, context) => {
const [{locale}] = useGlobals();
return <MyProvider locale={locale}>;
}
End users configure the locales
and locale
globals in .storybook/preview.ts
.
locales
is an object where the keys are the "ids" of the locale/language and the values are the plain text name of that locale you want to use. This is what will appear in the dropdown in the toolbar.
const preview: Preview = {
globals: {
locale: "en",
locales: {
en: "English",
fr: "Français",
ja: "日本語",
},
},
};
Users can also use full locale strings.
const preview: Preview = {
globals: {
locale: "en_US",
locales: {
en_US: "English (US)",
en_GB: "English (GB)",
fr_FR: "Français",
ja_JP: "日本語",
},
},
};
The locales
object can also have values as an object with keys of title
, left
, or right
.
This is useful if you want to include an emoji flag or some other string to the left or right side.
For example:
const preview: Preview = {
globals: {
locale: "en",
locales: {
en: {title: "English", left: '🇺🇸'},
fr: {title: "Français", left: '🇫🇷'},
ja: {title: "日本語", left: '🇯🇵'},
},
},
};
Or something like this:
const preview: Preview = {
globals: {
locale: "en_US",
locales: {
en_US: {title: "English", right: 'US'},
en_GB: {title: "English", right: 'GB'},
fr_FR: {title: "Français", right: 'FR'},
ja_JP: {title: "日本語", right: 'JP'},
},
},
};
When the locale has been changed, an event is emitted on the addons-channel
.
You can subscribe to this event in your preview.ts
, to configure global environment settings yourself, related to your i18n-config.
The event is emmited with the selected locale as a parameter
.
Your implementation could look like this:
import { addons } from '@storybook/preview-api'
addons.getChannel().on('LOCALE_CHANGED', (newLocale) => {
changeMyI18nConfig(newLocale)
});
Addons should instruct them to use whichever format your i18n implementation expects.
v2.0.5 (Fri Apr 07 2023)
main
FAQs
Tool to set the locale in Storybook for i18n
The npm package storybook-i18n receives a total of 133,569 weekly downloads. As such, storybook-i18n popularity was classified as popular.
We found that storybook-i18n 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
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.