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

@aurium/i18n

v0.4.1

Published

Internationalization made simple

Downloads

1,101

Readme

Internationalization made Simple

The focus of this project is to make the i18n call to look simple, clean and obvious.

Instaling

npm install @aurium/i18n

Usage

var l10nData = {
  en: {
    some_string: 'Some string.',
    has_n_aples: ['There is one apple.', 'There are {num} apples.']
  },
  pt_br: {
    some_string: 'Algum texto.',
    has_n_aples: ['Existe uma maçã.', 'Existem {num} maçãs.']
  }
}

const i18nBuilder = require('@aurium/i18n')
var i18n = i18nBuilder(l10nData, ['pt-Br', 'es'])

console.log('>> '+ i18n.some_string)
console.log('>> '+ i18n.has_n_aples.plural(5))

Using with Typescript + Vue

/src/i18n/index.ts

import Vue from 'vue'
import i18nBuilder, { i18nProxy, LangData } from '@aurium/i18n'

const l10nData = {
  en: require('./l10n.en.js') as LangData,
  pt: require('./l10n.pt.js') as LangData
}

const i18n = i18nBuilder(l10nData)
export default i18n

// Allows Vue components to easily access localization results:
Vue.use({
  install (_Vue: typeof Vue): void {
    Object.defineProperty(_Vue.prototype, 'l10n', {
      get: () => i18n
    })
  }
})

declare module 'vue/types/vue' {
  interface Vue {
    l10n: i18nProxy;
  }
}

/src/main.ts

import Vue from 'vue'
import './i18n'
const app = new Vue({
  render: h => h(App)
}).$mount('#app')

/src/components/SomeTest.ts

<template>
  <strong>{{l10n.some_string}}</strong>
</template>

<script lang='ts'>
@Component()
export default class SomeTest extends Vue {
  ...
}
</script>

⚠ You must create localization files (like /src/i18n/l10n.en.js and /src/i18n/l10n.pt.js) to get it working. You may like to use the extract-i18n-keys command to help.

⚠ The localization file format may not fit to your code pattern. If you wont to format this files, you can tell eslint to ignore they. .eslintrc.js:

module.exports = {
  ...,
  ignorePatterns: ['l10n.*.js'],
  rules: { ... },
  ...
}

Extracting i18n keys from source code

This package provides the extract-i18n-keys cli, that can find for keys like i18n.some_string and add this to l10n files. You can run this command to add each new key you just write to the l10n files, without change current ones.

extract-i18n-keys can write js file modules with occurrences information, or clean json files. You can also change your proxy var name from i18n to any other and use the -p|--i18n-proxy-name parameter to inform that.

For more details, read extract-i18n-keys --help.

Hacking and Contributing

Please, read the contributing page.