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

@ecomplus/i18n

v1.32.2

Published

Tree shakable dictionary for e-commerce JS apps

Downloads

2,341

Readme

i18n

Publish npm version License MIT

:brazil: :us:

Tree shakable dictionary focused on eCommerce JS applications.

i18n ~ i19 ~ Internationalization

Getting started

npm i --save @ecomplus/i18n

Usage

import { i19hello, i19visitor } from '@ecomplus/i18n'
console.log(`${i19hello.en_us} ${i19visitor.pt_br}`)
// Hello Visitor
console.log(`${i19hello.pt_br} ${i19visitor.pt_br}`)
// Olá Visitante

We recommend using it with ecomUtils.i18n:

import { i18n } from '@ecomplus/utils'
import { i19hello, i19visitor } from '@ecomplus/i18n'
console.log(`${i18n(i19hello)} ${i18n(i19visitor)}`)
// Hello Visitor

Change current language with ecomUtils._config:

import { _config, i18n } from '@ecomplus/utils'
import { i19hello, i19visitor } from '@ecomplus/i18n'
_config.set('lang', 'pt_br')
console.log(`${i18n(i19hello)} ${i18n(i19visitor)}`)
// Olá Visitante

Import entire dictionary object

It'll output large size bundle, not good for frontend apps.

import dictionary from '@ecomplus/i18n'
console.log(`${dictionary.i19hello.en_us} ${dictionary.i19visitor.en_us}`)
// Hello Visitor

Webpack alias

You can import only one language variation using Webpack resolve.alias as following:

// webpack.config.js
module.exports = {
  //...
  resolve: {
    alias: {
      '@ecomplus/i18n$': `@ecomplus/i18n/src/${lang}/`
    }
  }
}

By this way you'll import only strings instead of objects:

import { i19hello, i19visitor } from '@ecomplus/i18n'
console.log(`${i19hello} ${i19visitor}`)
// Hello Visitor

You can still use ecomUtils.i18n the same way:

import { i18n } from '@ecomplus/utils'
import { i19hello, i19visitor } from '@ecomplus/i18n'
console.log(`${i18n(i19hello)} ${i18n(i19visitor)}`)
// Hello Visitor

Conventions

  1. String values always with uppercased first letter (eg.: 'Hello');
  2. Variable (const) names always in English;
  3. Prefix i19 for all variable names;
  4. String variables must be camelCased (eg.: i19helloWorld);
  5. Object (enums) variables must be PascalCased (eg.: i19OrderStatus);
  6. All language options must have same variables;
  7. For long messages: variable name should be suffixed with Msg;
  8. For questions: variable name should be suffixed with Qn;

Code style

  1. Exported constants must be alphabetically ordered;
  2. Additional line break before objects (not for strings);