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

@netatwork/aurelia-i18n-tools

v4.1.1

Published

A toolchain to help with localization in aurelia projects.

Downloads

16

Readme

@netatwork/aurelia-i18n-tools

A toolchain to help with localization in aurelia projects.

Installation

npm i -D @netatwork/aurelia-i18n-tools

Configuration

The configuration is usually defined in an es module called i18n-config.mjs in the package root directory. All relative file paths are resolved relative to the config files directory.

// i18n-config.mjs
import { defineConfig } from "@netatwork/aurelia-i18n-tools";

// "defineConfig" helps with auto completion, but is not required:
export default defineConfig({
  // This object contains all the config options.
  // All fields are optional with the defaults specified below unless specified otherwise.

  // The root directory for template and resource files:
  src: "./src",

  // The filename of the translation data file:
  translationData: "./i18n.json",

  // The filename template for compiled locale data.
  // The "[locale]" placeholder is replaced with the locale name.
  output: "./dist/[locale]/translation.json",

  // A prefix for translation ids.
  // Default is an empty string.
  prefix: "example.",

  // An array of locales.
  // The first one is the locale used in source files.
  // Default is `[en]`
  locales: ["en", "de"],

  // An array of rules to control what is not localized:
  // By default, nothing is ignored.
  // Matching patterns can be strings, regular expressions or functions.
  ignore: [
    // Matches <not-localized-example> elements and it's children:
    { element: "not-localized-example" },

    // Matches the complete text content "Hello World!":
    // Text content with interpolation is ignored automatically.
    { textContent: "Hello World!" },

    // Matches attributes with the value "example":
    { attributeValue: "example" },
  ],

  // An object to specify what elements and attributes are localized:
  // By default, nothing is localized.
  localize: {
    "example-element": {
      // Element content is not localized (default):
      content: "none",
      // Localize the element content as inner html:
      content: "html",
      // Localize the element content as inner text.
      content: "text",

      // An array of localized attribute names:
      attributes: ["value", "title"],
    },

    // "*" matches all elements:
    "*": { ... },
  },

  // An object to specify how whitespace is handled when extracting localized fragments:
  whitespace: {
    "example-element": {
      // An object to specify how whitespace is handled for specific attributes:
      attributes: {
        // Extract whitespace as is:
        value: "preserve",
        // Only trim leading and trailing whitespace:
        value: "trim",
        // Collapse leading, trailing and whitespace in between text to a single space:
        value: "collapse",
        // Trim and collapse:
        value: "trim-collapse",

        // "*" matches all attributes:
        "*": "preserve",
      },

      // Specify how whitespace is handled for element content:
      content: "preserve",
    },

    // "*" matches all elements:
    "*": {},
  },

  // Specify how diagnostics are handled:
  // By default, all diagnostics are treated as warnings.
  // Values can be "ignore", "warn" or "error".
  // See "src/diagnostics.ts" for a list of possible diagnostics.
  diagnostics: {
    "invalid-json-data": "error",
    // "all" is a fallback for unconfigured diagnostics:
    all: "warn",
  },

  // An object with locales and patterns to include external locale data:
  externalLocales: {
    en: ["./node_modules/@some-namespace/*/dist/en/translation.json"],
    en: ["./node_modules/@some-namespace/*/dist/de/translation.json"],
  },
});

Configuration options can be imported from other packages using imports:

export default defineConfig({
  localize: {
    // Import an es module:
    ...(await import("my-package/i18n-elements.mjs")).default,
    // or a json file:
    ...(await import("./my-package/i18n-elements.json", { assert: { type: "json" } })),
  },
});

Command Line Interface

naw-aurelia-i18n [...args]

# Usage examples:
# Specify a different config file:
naw-aurelia-i18n -c ./my-config.mjs
# Run the production workflow once:
naw-aurelia-i18n
# Run the development workflow and watch for changes:
naw-aurelia-i18n -d
# Run the development workflow once:
naw-aurelia-i18n -d --no-watch

--config <path>, -c <path>

Specify the configuration file to use.

  • Default is ./i18n-config.mjs.
  • Supported extensions are .js, .mjs, .cjs, json.
  • If the config is a javascript file, it's default export is used as configuration options.

--dev, -d

Enable development mode.

  • This actively updates the translation data file and translation IDs in any included sources.
  • This also watches for changes by default.

--watch, --no-watch, -w

Enable or disable watching for changes.

  • Watching is enabled by default in development mode and disabled otherwise.
  • When not watching for changes, the process will exit with a non-zero exit code if any error diagnostics have been raised.

--verbose, -v

Show verbose information like the effective configuration options.

--no-externals

If specified, external locales are not included in the output.