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

@shopify/i18next-shopify

v0.2.9

Published

i18nFormat plugin to use Shopify's translation format with i18next

Downloads

23,325

Readme

@shopify/i18next-shopify

This package is an i18nFormat plugin for the i18next library. It allows developers to use the same format used by Shopify apps and themes for localization.

Key features include:

  • Variable interpolation with both single {} and double {{}} curly brace mustache formats
  • Pluralization as nested keys
    • E.g. { "keyWithCount": { "one": "value" } } instead of { "keyWithCount_one": "value" }
  • Variable interpolation with React components as replacement values
    • E.g. t("key", { businessName: <strong>Shopify</strong> })
  • Ordinal pluralization using the interpolation variable ordinal as number (e.g. t("key", { ordinal: 1 })) or using the interpolation variable ordinal as boolean and count as number (e.g. t("key", { ordinal: true, count: 1 }))
    • NOTE: When ordinal is explicitly set to 0 and count is also explicitly set, the plugin will treat this as cardinal pluralization (e.g. t("key", { count: 1, ordinal: 0 }))

Table of contents

Getting Started
Example
License
Contributing
References

Getting started

Add the package

$ npm install @shopify/i18next-shopify

or

$ yarn add @shopify/i18next-shopify

Configure i18next to use this plugin

Warning The Intl.PluralRules API is required for this plugin's plural handling. If your target environments do not support this API, you may need to polyfill it. This plugin's plural handling is not compatible with i18next's fallback to JSON format v3 plural handling.

import i18next from "i18next";
import ShopifyFormat from "@shopify/i18next-shopify";

i18next.use(ShopifyFormat).init(i18nextOptions);

Example

import i18next from "i18next";
import ShopifyFormat from "@shopify/i18next-shopify";

i18next.use(ShopifyFormat).init({
  lng: "en",
  resources: {
    en: {
      translation: {
        hello: "Hello {{casualName}}!",
        products: {
          "0": "I have no products.",
          "1": "I have a single product.",
          one: "I have {{count}} product.",
          other: "I have {{count}} products.",
        },
      },
    }
  }
});

i18next.t("hello", { casualName: "Shopify" }); // -> Hello Shopify!
i18next.t("products", { count: 2 }); // -> I have 2 products!

License

MIT

Contributing

Want to make i18next-shopify better for everyone? We'd love your help! Please start off by reading our Code of Conduct.

Report a bug

Bugs are tracked at GitHub issues. Search open issues to see if someone else has reported a similar bug. If it's something new, open an issue. We'll use the issue to have a conversation about the problem you want to fix. You may also suggest features using GitHub issues.

When creating a new issue, please ensure the issue is clear and include additional details to help maintainers reproduce it:

Use a clear and descriptive title for the issue to identify the problem.

  • Describe the exact steps which reproduce the problem in as many details as possible.
  • Provide specific examples to demonstrate the steps. Include links to files, or copy/pasteable snippets. If you're providing snippets in the issue, use Markdown code blocks.
  • Describe the behavior you observed after following the steps and point out what exactly is the problem with that behavior.
  • Explain which behavior you expected to see instead and why.
  • Include screenshots and animated GIFs where possible.

Contributing Code

Useful commands:

  • yarn install to install development dependencies
  • yarn test to run the test suite
  • yarn tdd to run tests after files are updated
  • yarn lint to run the linter
  • yarn changeset to generate a changeset

How to contribute:

  • Open a PR with your contribution. Fill out all applicable sections of the PR template
  • Include a changeset in your pull request. This helps us keep the changelog and version accurate.
    • If you believe an empty changeset is warranted and appropriate, one can be generated by running yarn changeset add --empty
  • Before you can merge your pull request, you must sign Shopify's Contributor License Agreement (CLA).

Thank you for your interest in contributing!

References