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

@aofl/i18n-mixin

v3.14.1

Published

Adds i18n support to elements

Downloads

338

Readme

@aofl/i18n-mixin

The AOFL i18nMixin element decorates any element with i18n support.

Api Documentation

Examples

  • https://codesandbox.io/s/github/AgeOfLearning/aofl/tree/v3.0.0/aofl-js-packages/i18n-mixin/examples/basics

Requirements

For each component which will support internationalization an i18n directory will need to be created in the root of the component directory. Inside this directory language translations-[language-contrycode].js files will be expected.

A translation.js file will be generated via running aofl i18n. The command will find all component template instances of translation method strings, e.g. __('string to translate'), _c('more strings').

The translation.js can be used by a tranlsations api or translators to create the necessary translation-[lang].js files in the format of translation-LOCALE.js, e.g. translation-en-US or translation-pt-BZ.po, which again will be expected in the compontent's i18n directory.

Finally the component class will need to set the current language, e.g. this.lang = 'pt-BZ';

Usage with i18n Loader

Finally the i18n-loader will be required.

Run npm i -D @aofl/i18n-loader

Then add the loader to your webpack config:

module: {
  rules: [
    {
      test: /language\.js$/,
      use: '@aofl/i18n-loader'
    }
  ]
}

Multiple template support

The AOFL mixin supports multiple template to be rendered based on the currently set lang. For instance if de-DE is the selected language then the template associated with that language will be rendered.

The render method expects a template object like so:

return super._render({
  default: {
    template(context, html) {
      return html`<h2>${context.__('How are you %s1', context.person)}</h2>`
    },
    styles: []
  },
  'de-DE': {
    template(context, html) {
      return html`
        <h1>German version</h1>
        <h2>${context.__('How are you %s1', context.person)}</h2>
      `;
    },
    styles: []
  }
})

code example

import i18nMixin from '@aofl/i18n-mixin';
import {AoflElement} from '@aofl/web-components/aofl-element';
import styles from './styles.css';

class MyComp extends i18nMixin(AoflElement) {
  constructor() {
    super();
    this.langMap = langMap;
    this.lang = 'de-DE';
  }
  static get is() {
    return 'my-comp';
  }
  _render() {
    let person = 'Albert';
    let count = 1;
    return super._render({
      default: {
        template(context, html) {
          return html`<h2>${context._r(context.__('How are you %r1%'), context.person)}</h2>`
        },
        styles: []
      },
      'de-DE': {
        template(context, html) {
          return html`
            <h1>German version</h1>
            <h2>${context._r(context.__('How are you %r1%'), context.person)}</h2>
            <p>${context._c('There %c1% here!', {
              1: 'is one person',
              2: 'are two people',
              3: 'are many people'
            }, context.count)}</p>
          `;
        },
        styles: []
      }
    });
  }
};