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

@scandipwa/webpack-i18n-runtime

v0.1.0

Published

Webpack internationalization plugin used used by CSA.

Downloads

3,400

Readme

@scandipwa/webpack-i18n-runtime

This package includes internationalization plugin used by Create Scandipwa App.

This package is intended to replace the @scandipwa/webpack-i18n-plugin, legacy i18n implementation.

Abstract

The legacy implementation forced to compile each language separately, resulting into multiple recompilations during one build cycle.

Also, it's been impossible to change language on the page without refetching it from the start.

This implementation lacks these limitations.

Benefits

  1. Single compilation for all locales

  2. Proper chunk splitting: each translation gets compiled into its own chunk, which contains only the translation mappings

  3. Locale switch in runtime fetches additional translation chunk, instead of fetching all the JS bundles + HTML document

Limitations

  1. This is a replacement for the legacy @scandipwa/webpack-i18n-plugin, hence it is not compatible with it.

  2. When using with @scandipwa/m2-theme extension, static content signing should be disabled in the M2 instance and en_US locale should always be deployed.

Dependencies

@scandipwa/webpack-after-emit-logger is used to provide useful output after builds. Make sure it is enabled in your application to have all the information this package provides!

scandipwa/locale PHP module is used to integrate this i18n implementation with Magento 2 framework. Use the latest version to get support for this functionality!

Runtime

This package globally provides a translation function __(translatable, ...args), it can be called anywhere throughout the application. It translates a string, then replaces all the %s literals within it with values from ...args, consequently.

How to use

  1. Enable it in your ScandiPWA project. It is enabled by default in the @scandipwa/scandipwa theme, no manual action required if you use it as a parent.
{
    "scandipwa": {
        "extensions": {
            "@scandipwa/webpack-i18n-runtime": true
        }
    }
}
  1. Define the desired locales in your package.json
{
    "scandipwa": {
        "locales": {
            "en_US": true,
            "fr_FR": true
        }
    }
}
  1. By default, the package utilizes the @scandipwa/framework to wrap the contents rendered by the Component/App/Component namespace's render function into a component that provides translations for the application. Feel free to wrap your application yourself if it does not have @scandipwa/framework or your App component's namespace differs from the default one. The component is @scandipwa/webpack-i18n-runtime/src/component/I18n

  2. Wrap all the translatable strings within your application into __(...) function calls.

  3. Build the application.

  4. See that translation files have been automatically created in your project's i18n directory. All properties of these files should be filled in order to eliminate missing translations. See an example below, the "Cart" and "Account" strings are translated, the other one is not.

{
    "Cart": "Chariot",
    "Account": "Compte",
    "Buy %s for %s and save %s": null
}