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

po-loader

v0.7.0

Published

PO loader module for webpack

Downloads

63,323

Readme

PO loader for webpack

Usage

Documentation: Using loaders

// Use it explicitly
var messages = require("json!po!./locale/en_US/LC_MESSAGES/messages.po");

// Or add a loader into your webpack.config.js
loaders: [
   {test: /\.po$/, loader: 'json!po'}
]

// And then require it like this
var messages = require("./locale/en_US/LC_MESSAGES/messages.po");

See po2json for a list of possible options. Use the format option to change the output format, e.g. json!po?format=jed or json!po?format=jed1.x for the latest Jed format.

Simple async simple example:

import Jed from 'jed'

// The Locale consists of a language and territory.
const language = langParts[0]
const territory = langParts[1].toUpperCase()

// Set complete
const locale = multipart ? language + '_' + territory : language

let i18n = null

export default {
  async init() {
    const langRaw = window.navigator.userLanguage || window.navigator.language
    const langParts = langRaw.replace('-', '_').split('_')

    const language = langParts[0]
    const country = langParts.length > 1 ? '_' + langParts[1].toUpperCase() : ''
    const locale = `${language}${country}`

    let localeData

    try {
      localeData = await getLocaleData(locale)
    } catch {
      localeData = await getLocaleData(LOCALE_DEFAULT)
    }

    i18n = new Jed(localeData)
  },
  gettext(message) {
    return i18n.gettext(message)
  },
  ngettext(msg1, msg2, n) {
    return i18n.ngettext(msg1, msg2, n)
  },
}

// A runtime exception will be throw every time that the requested locale file cannot be found.
// Webpack uses a regular expression to build all locales as separate bundles.
async function getLocaleData(locale) {
  return import(`${LOCALE_ROOT}/${locale}/LC_MESSAGES/messages.po`)
}

Javascript with language fallback example:

Language fallback map stored at ${LOCALE_ROOT}/config:

---
default: en_US
map:
  en: en_US
  ru: ru_RU
  uk: ru_RU
  de: de_DE
...

locale module:

import Jed from 'jed'

let i18n
let localeConfig

export default {
  async init() {
    const localeConfig = await import(`${LOCALE_ROOT}/config`)

    const localeDefault = localeConfig['default']
    const map           = localeConfig['map']

    const langRaw = window.navigator.userLanguage || window.navigator.language
    const langParts = langRaw.replace('-', '_').split('_')

    const language = langParts[0]
    const country = langParts.length > 1 ? '_' + langParts[1].toUpperCase() : ''
    const locale = `${language}${country}`

    let localeData

    try {
      localeData = await getLocaleData(locale)
    } catch {
      const localeNext = map.hasOwnProperty(language) ? map[language] : localeDefault
      localeData = await getLocaleData(localeNext)
    }

    i18n = new Jed(localeData)
  },
  gettext(message) {
    return i18n.gettext(message)
  },
  ngettext(msg1, msg2, n) {
    return i18n.ngettext(msg1, msg2, n)
  },
}

// A runtime exception will be throw every time that the requested locale file cannot be found.
// Webpack uses a regular expression to build all locales as separate bundles.
async function getLocaleData(locale) {
  return import(`${LOCALE_ROOT}/${locale}/LC_MESSAGES/messages.po`)
}

Then in your common shared code:

const localePromise = locale.init()
const documentPromise = new Promise(function(resolve, reject) {
  document.addEventListener('DOMContentLoaded', resolve, false)
})

init([localePromise, documentPromise])

Finally in your entry code:

import init from 'init'

init().then(function() {
  console.log('The locale module is now ready.')
})

License

MIT (http://www.opensource.org/licenses/mit-license.php)