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

e7n

v1.7.5

Published

A tool for Chrome extensions i18n/l10n to auto-populate _locales/<default_locale>/messages.json with messages from JS and HTML files

Downloads

9

Readme

🌎 e7n: Chrome Extension Internationalization

l10n ➡️ localization “refers to the adaptation of a product, application or document content to meet the language, cultural and other requirements of a specific target market (a locale).” -W3C

i18n ➡️ internationalization “is the design and development of a product, application or document content that enables easy localization for target audiences that vary in culture, region, or language.” -W3C

e7n ➡️ extension “is a library for making it easier to use the chrome.i18n infrastructure” -@mrcoles

This tool auto-populates _locales/<default_locale>/messages.json with strings found in a Chrome extension project, and makes it easy to convert from those strings into localized text.

1. Mark up localizable strings

HTML

Mark HTML tags with a data-e7n tag. Such tags should only contain text (or comments):

<div>
  <span data-e7n>Hello!</span>
  <img src="foo.png" />
</div>

The i18n key is auto-derived from the text. You can also manually specify the key by setting a value on the data attr, e.g., data-e7n="hello".

The content will automatically get HTML-escaped, if you want to parse raw HTML, e.g., if you have a link in the text, then add the data-e7n-html to the markup too:

<p data-e7n data-e7n-html>More info <a href="https://example.com/">here</a>.</p>

JavaScript

Use the e7n tr JavaScript function to signify text that is a localizable string. Use string literals or variables that are string literals.

This can run in JavaScript, Typescript, and JSX code—it will look for files matching the glob **/*.{js,jsx,ts,tsx}.

import { tr } from 'e7n';

// auto-generated key
const FOO = tr('This is a localized string.');

// manually specified key
const BAR = tr('This is also localized', 'bar');

// auto-generated key from concatenated string literals
const MULTI = tr('This is combined ' + 'via plus signs');

// with placeholders (you can also set the key 2nd arg to `null`)
const BAZ = tr(
  'Hi, $name$, your number is $number$.',
  'hiYourNumber',
  ['Alice', '10'],
  {
    name: { content: '$1', example: 'Alyssa P' },
    number: { content: '$2', example: '1' }
  }
);

2. Setup auto-conversion

In HTML files, auto-convert your marked tags with the updateHtml function:

import { updateHtml } from 'e7n';

document.addEventListener('DOMContentLoaded', event => {
  updateHtml();
});

const update = () => {
  fetch('/something')
    .then(r => r.text())
    .then(html => {
      let elt = document.getElementById('something');
      elt.innerHTML = html;
      updateHtml(elt);
    });
};

In JavaScript files, the tr function will already convert messages for you.

Pseudo-localization

You can enable pseudo-localization (sometimes called "pseudoloc") by setting the pseudoloc option to true.

import { options as e7nOptions } from 'e7n';

e7nOptions.pseudoloc = true;

This can let you test to make sure parts of your UI are connected up properly without having to change your browser's language.

For example "Delete image" would get convrted to: "Ḓḗḗŀḗḗŧḗḗ īḿȧȧɠḗḗ".

3. Build project

Generate your _locales/<default_locale>/messages.json file via the following steps:

  1. Add a "default_locale" value to your extension’s manifest.json file, e.g., "default_locale": "en",
  2. Create a starting messages.json file: mkdir -p _locales/en/ && echo '{}' > _locales/en/messages.json (TODO: automate this more, so you don't need to create the directory or file)
  3. Run e7n: e7n [path_to_src_directory_with_manifest]

The build will fail if it encounters issues generating the messages. If it succeeds, it will print out the JSON for the new file and also update the file in place.

4. Perform translations

You may translate your files via any service you like or using AWS Translate with e7n-aws-translate.

Todos

  • currently it HTML-escapes results in HTML, should this not happen?
  • better error messages to grab sample bad text from source in parsers/javascript