1.0.10 • Published 5 years ago

storybook-addon-linguijs v1.0.10

Weekly downloads
431
License
MIT
Repository
github
Last release
5 years ago

Lingui react Addon

The linguijs react addon can be used to provide locale switcher and linguijs react.

npm.io

Getting Started

First, install the addon

npm install -D storybook-addon-linguijs

Note: Following peer dependencies are required: @storybook/addons, @storybook/react, react and lingui/react.

Add this line to your addons.js file (create this file inside your storybook config directory if needed).

import "storybook-addon-linguijs/register";

In your config.js import the setLinguiConfig and withLingui function. Use setLinguiConfig to set the configuration for lingui/react and `withLingui as decorator.

import { addDecorator, configure } from "@storybook/react";
import { setLinguiConfig, withLingui } from "storybook-addon-linguijs";

// Provide a catalog or import and use your existing one
const catalogs = {
  en: {
    messages: {
      "Hello Button": "Hello Button"
    }
  },
  fr: {
    messages: {
      "Hello Button": "Bonjour Button"
    }
  }
};

// Set configuration
setLinguiConfig({
  locales: ["en", "fr"],
  defaultLocale: "en",
  catalogs
});

// Register decorator
addDecorator(withLingui);

// Run storybook
configure(() => require("./stories"), module);

In your story you need to wrap your component with <Trans> or a t function from @lingui/macro

import { Trans } from "@lingui/macro";

storiesOf("Button", Module).add("with text", () => (
  <Button>
    <Trans>Hello Button</Trans>
  </Button>
));
1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago