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

fra-lang-pack

v0.3.0

Published

Handle the loading and formatting of JSON language translation packages.

Downloads

36

Readme

Free-Range App Langpack Loader

This is a project to help you with two things when developing a Free-Range App:

  • Aid in loading language files, returning promises so you can delay loading the rest of your app until your translations are available
  • Providing a thin wrapper around MessageFormat for your app to use to do replacements in display strings formatted according to the ICU string formatting standard.

Language File Loader

The main function for this is loadLangPack(), which will use the provided options to fetch a JSON file of the appropriate language, with a fallback path if the requested file can't be found.

Example usage:

var fraLangPack = require( 'fra-lang-pack' );
fraLangPack.loadLangPack( {
    langTag: 'en-CA',
    languageFileRootUrl: 'https://s.brightspace.com/apps/your-app/lang',
    superagentUrl: 'https://s.brightspace.com/lib/superagent/1.2.0/superagent.js'
} ).then( function( langPack ) {
    // Start your app
} );

Language Fallback

If, for whatever reason, a language file can't be loaded, there is a fallback to other languages before giving up. Assuming you specified a lang tag of fr-CA, it would work like this:

  • Attempt to load fr-CA.json from the directory specified by languageFileRoot
  • If that fails, attempt to load fr.json
  • If that fails, attempt to load en.json (or what was specified by defaultLangTag)
  • If that fails, reject the promise

Loader Options

| Name | Required | Description | |-------------------------|------------|------------------------------------------------------------------------------------------------------------| | langTag | yes | The lang tag to load everything for (eg: 'fr-US'). The desired JSON file must match this. eg: fr-US.json | | languageFileRootUrl | yes | URL to the directory containing the JSON language files | | superagentUrl | yes | URL to fetch Superagent from. If null the NPM package will be used instead. | | defaultLangTag | no | Fall-back language if the desired one can't be loaded (defaults to en) |

Superagent

This library depends on SuperAgent (tested with ^1.2.0 and ^2.0.0), but to keep the bundle size down it does not include it directly. You are required to either pass the superagentUrl option, or someone make it available to RequireJS with the name superagent.

Formatter

The Formatter is a wrapper around MessageFormat, with the Language File Loader loading the locale files for you.

Example usage: (note: this requires that the locale files have already been loaded)

var fraLangPack = require( 'fra-lang-pack' );
var formatter = new fraLangPack.Formatter( 'fr' );

var formattedString = formatter.format(
    "Hello {name}, my name is {me}",
    { name: 'World', me: 'Sam' }
);
console.log( formattedString ); // outputs "Hello World, my name is Sam"