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

@xirelogy/rollup-plugin-xwts-i18n

v1.0.3

Published

Process xwts-i18n compatible locale translations with rollup

Downloads

12

Readme

Rollup plugin to compile i18n resources

Introduction

This is a rollup plugin to compile the i18n resources defined using XW (Typescript) framework.

Usage

This plugin is used in corresponding vite.config.ts to control how i18n resources (locales) are compiled.

The plugin can be included using:

import xwtsI18n from '@xirelogy/rollup-plugin-xwts-i18n';

And configured like:

const i18n = xwtsI18n({
  output: { ... },
  roots: {
    'locales': [],
  },
  include: 'locales/**',
});

with following configuration options:

| Key | Usage | | --- | --- | | output | Define the output type. Currently virtual and file supported. | | roots | Module prefix of the locales defined. This correspond to the names where the i18n module is initialized using xw.i18n.initModule(...) | | include | Search folder for locale translation files |

Usage in projects (virtual output)

This is normally used for projects, whereby the deliverable is the project output. Locales will be compiled into a virtual module defined using the moduleName argument.

| Key | Usage | | --- | --- | | moduleName | The module name whereby the locales can be included. |

Example:

import { defineConfig } from 'vite';

import xwtsI18n from '@xirelogy/rollup-plugin-xwts-i18n';

const i18n = xwtsI18n({
  output: {
    type: 'virtual',
    moduleName: 'locale:compiled',
  },
  roots: {
    'locales': [],
  },
  include: 'locales/**',
});

export default defineConfig({
  plugins: [
    i18n,
  ],
  ...
});

Usage in libraries (file output)

This is normally used for libraries, whereby its outputs will be used by other projects. Locales will be compiled into file supporting the following distribution target:

| Key | Usage | | --- | --- | | fileName | The filename for output in the ESM format. | | cjsFileName | The filename for output in the CommonJS/UMD format. | | dtsFilename | The filename for output containing the Typescript definition (.d.ts). |

Example:

import { defineConfig } from 'vite';

import xwtsI18n from '@xirelogy/rollup-plugin-xwts-i18n';

const i18n = xwtsI18n({
  output: {
    type: 'file',
    fileName: 'locales.es.js',
    cjsFileName: 'locales.umd.js',
    dtsFilename: 'locales.d.ts',
  },
  roots: {
    'locales': [ '<module>', '<names>' ],
  },
  include: 'locales/**'
});

export default defineConfig({
  plugins: [
    i18n,
  ],
  ...
});

Importing the locales

Compiled locales are normally imported and used in the the entrance file (like main.ts), in a section of code something like below:

import { xw } from '@xirelogy/xwts';

// Import current project locales (virtual output)
import locales from 'locale:compiled';
locales(xw.i18nSetup);

// Import libraries locales (file output)
import xwLocales from '@xirelogy/xwts/locales';
xwLocales(xw.i18nSetup);

...

Working with Typescript

When importing current project locales like below:

import locales from 'locale:compiled';
locales(xw.i18nSetup);

The corresponding module might not be recognized and causes a warning. Create a shim file shims-locale.d.ts with the following content shall overcome this:

/* eslint-disable */
declare module 'locale:compiled' {
  import { XwI18nModuleDefinable } from '@xirelogy/xwts';
  export default function locales(modDef: XwI18nModuleDefinable): void;
}