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

i18n-web

v0.0.4

Published

A simple tool helps in externalizing the strings in a JavaScript Application. It has the additional capability of parameterizing the strings.

Downloads

13

Readme

i18n-web

i18n-web is a simple tool helps in externalizing the strings in a JavaScript based Application such that, Internationalization(i18n) can be achieved easily. It has the additional capability of parameterizing the strings to get the dynamic content Internationalized.

Install

  • Using yarn: yarn add i18n-web
  • Using npm: npm install i18n-web

What is String Externalization?

String Externalization means, instead of writing the user(or customer) facing strings in source files(.html, .js, .java etc), we keep them in an external file like .properties, .json etc and load from there. This is to help Internationalization (i18n).

What is Internationalization (i18n)?

In Software, Internationalization (i18n) is the process to support various local languages like, English(en), Spanish(es), German(de) etc.

All the browsers come with the in-built support of languages which can be used to identify the local language to support for the application.

How String Externalization help in Internationalization (i18n) of the Web Applications?

A Web Application may have the need of supporting multiple languages based on the targeted users. If the Application Strings are Externalized outside of the source files, it is easy and flexible to support i18n.

Lets consider, all the application strings are in a file called en.json and this file can be loaded into the application to retrieve the strings when the app is running in English Language.

{
    'username': 'User Name',
    'password': 'Password',
    'hasBlog': '{0} has a blog named, {1}. This is on {2}.'
}

Now there could be equivalent es.json file which can be loaded into the application when browser supported language is Spanish instead of English.

{
    'username': 'Nombre de usuario',
    'password': 'Contraseña',
    'hasBlog': '{0} tiene un blog llamado {1}. Esto está en {2}.'
}

i18n-web Usage

Basic Setup and Structure

The tool i18n-web helps in externalizing the string and thus, internationalizing your web app with few quick and easy steps.

  • Create a folder called i18n at the same level of node_modules folder of your app.
  • Create en.js, es.js, de.js etc file to contain your application specific strings externalized. You must add all required language .js files that your app would support.

Here is an example of the en.js and es.js file.

// en.js
const en = {
    'username': 'User Name',
    'password': 'Password',
    'hasBlog': '{0} has a blog named, {1}. This is on {2}.'
}

export { en };
// es.js
const es = {
    'username': 'Nombre de usuario',
    'password': 'Contraseña',
    'hasBlog': '{0} tiene un blog llamado {1}. Esto está en {2}.'
}

export { es };
  • Create another file called, index.js where you can aggregate the all modules and export together like this:
export { en } from './en.js';
export { es } from './es.js';

Example Directory Structure:

myapp                         
    └── i18n
        └── en.js
        └── es.js
        └── de.js
        └── fr.js
        └── index.js                
    └── node_modules                    

Using it in UI Code

  • In your UI Code, import it as,
import i18n from 'i18n-web';
  • Use it like:
// When no parameters. Just Key is passed
console.log(i18n('usename'));

// Output: 

// 'User Name' for English 

// 'Nombre de usuario' for Spanish 
// With parameters.
const params = ['Tapas', 'greenroos', 'JavaScript'];
let hasBlog = i18n('hasBlog', ...params);
console.log(hasBlog);

// Output: 

// 'Tapas has a blog named, greenroots. This is on JavaScript.' for English and 

// 'Tapas tiene un blog llamado greenroots. Esto está en JavaScript.' for Spanish 

Tested with