npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@intl-schematic/solid

v1.0.0-rc.9

Published

A reactive [`solid-js`](https://www.solidjs.com) adapter for [`intl-schematic`](/packages/core/).

Downloads

78

Readme

@intl-schematic/solid

A reactive solid-js adapter for intl-schematic.

npm i -s intl-schematic @intl-schematic/solid

Creates a reactive resource with the locale document and user's locale that is then passed in a closure to intl-schematic and user-defined plugins.

Basic usage

import { createLocaleResource } from '@intl-schematic/solid';

const getDocument = (locale: Intl.Locale) => import(`/locales/${locale.baseName}.json`);

const createTranslator = createLocaleResource(
  // Asynchronous locale fetching, can contain (and will react to) reactive solid bindings
  () => Promise.resolve(new Intl.Locale(navigator.language)),
  (getLocale: () => Intl.Locale) => [/* Array of custom plugins */]
)

export default function SolidComponent() {
  const t = createTranslator(getDocument);

  // Fully reactive,
  // automatically re-renders when the locale changes
  // or a new translation document is downloaded.
  return <p>{t('some translation key')}</p>;
}

JSX components

This library also provides some simple solid-js components which aim to help with wrapping parts of a translated string in html elements.

Going further let's assume that a file my-locale.ts containts something like this:

import { createTranslator } from 'intl-schematic';
import { ProcessorsPlugin, defaultProcessors } from '@intl-schematic/plugin-processors';

export const t = createTranslator(() => ({
  'my translation key': {
    dictionary: {
      'part one': 'intl-schematic',
      'part two': 'Stupidly simple, incredibly tiny, blazingly fast.'
    }
  }
}), [ProcessorsPlugin(defaultProcessors)]);

Dictionary Intl component with slots

Intl is a simple component, it helps to wrap parts of the translated string in html elements.
It assumes that the translation record is either a dictionary or a nested record, and allows to go one level deeper with the use of object children prop.

The component can be used in three different ways.

As a standalone component:

import Intl from '@intl-schematic/solid/Intl';
import { t } from './my-locale';

export default function MyComponent() {
  return <>
    <Intl t={t} k="my translation key">
      {{
        'part one': str => <h1>{str}</h1>,
        'part two': str => <h2>{str}</h1>
      }}
    </Intl>
  </>;
}

As a generic component factory:

import { useIntl } from '@intl-schematic/solid/Intl';
import { t } from './my-locale';

export default function MyComponent() {
  const Intl = useIntl(t);

  return <>
    <Intl k="my translation key">
      {{
        'part one': str => <h1>{str}</h1>,
        'part two': str => <h2>{str}</h1>
      }}
    </Intl>
  </>
}

As a component factory for a single translation key:

import { useIntl } from '@intl-schematic/solid/Intl';
import { t } from './my-locale';

export default function MyComponent() {
  const Intl = useIntl(t, 'my translation key');

  return <>
    <Intl children={{
      'part one': str => <h1>{str}</h1>,
      'part two': str => <h2>{str}</h1>
    }} />
  </>;
}

Multiline markup component

Multiline is a simple component, it helps to wrap separate lines of the translated string in html elements.
It assumes that the translation record contains either \n or \\n, but still allows to customize the line splitting mechanism.
Will wrap the lines in <p> with a custom class value, using the children prop will override this behavior.

The component can be used in four different ways.

As a standalone component with an optional custom line class:

import Multiline from '@intl-schematic/solid/Multiline';
import { t } from './my-locale';

export default function MyComponent() {
  return <>
    <Multiline t={t} k="my translation key" class="m-0 text-lg" />
  </>;
}

As a standalone component with a custom line renderer:

import Multiline from '@intl-schematic/solid/Multiline';
import { t } from './my-locale';

export default function MyComponent() {
  return <>
    <Multiline t={t} k="my translation key">
      {(line, lineNumber) => <p>{lineNumber()}: {line}</p>}
    </Multiline>
  </>;
}

As a generic component factory:

import { useMultiline } from '@intl-schematic/solid/Multiline';
import { t } from './my-locale';

export default function MyComponent() {
  const Multiline = useMultiline(t);

  return <>
    <Multiline k="my translation key">
      {(line, lineNumber) => <p>{lineNumber()}: {line}</p>}
    </Multiline>
  </>
}

As a component factory for a single translation key:

import { useMultiline } from '@intl-schematic/solid/Multiline';
import { t } from './my-locale';

export default function MyComponent() {
  const Multiline = useMultiline(t, 'my translation key');

  return <>
    <Multiline>
      {(line, lineNumber) => <p>{lineNumber()}: {line}</p>}
    </Multiline>
  </>;
}