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

grunt-i18n-properties

v0.1.0

Published

grunt task to convert java i18n property files to json

Downloads

7

Readme

grunt-i18n-properties

grunt plugin for converting java property i18n and l10n files to javascript source or json

Getting Started

This plugin requires Grunt ~0.4.5

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install grunt-i18n-properties --save-dev

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks('grunt-i18n-properties');

The "i18n" task

Overview

i18n converts a bunch of java i18n property files into locale specific json files. A bundle of i18n files have a three level hierarchy:

  1. specific localisations for regional language variations ( eg en_AU, pt_BR ) - usually only some keys are localised
  2. a file for each supported language ( eg es, it, jp, zh) - most keys are translated
  3. the primary development (fallback) language (often English en) - all keys are available in the development language

Project_en.properties

Project.Name = grunt-i18n-properties
Project.Description = A great little project

Project_es.properties

Project.Description = Un pequeño gran proyecto

Project_en_AU.properties

Project.Description = A little ripper of a project

grunt-i18n-properties provides the best available translation from any of the three levels that are available

for example

generating an en_AU file will produce

Project.Name = grunt-i18n-properties
Project.Description = A little ripper of a project

selecting the Project.Name from the generic en file, and the Project.Description from the region specific en_AU file.

generating a pt_BR file will produce results just from the en file ( providing Brazilian portuguese users with english ), since neither pt nor br_BR files are available.

Options

options.process

Type: Function( properties, language )

Default value: JSON.stringify

A function that transforms the final properties map into the string that is written to the language file.

convert to json

function( prop ) { return JSON.stringify( prop ); }

push the properties into a javascript object with the language as a key

function( prop, lang ) { return "strings['" + lang + "'] = " + JSON.stringify( prop ) + ";"}

pretty print json

function( prop ) { return JSON.stringify( prop, null, "  " ); }

options.primary

Type: String or false

Default value: "en"

The primary development language. Eg the fallback language used when a key has not been translated yet if primary is false, no fallback is used, so untranslated keys will be missing

options.langs

Type: Array of Strings

Default value: ["en_AU"]

An array of all the languages you wish to support. Typically you would provide languages with the regional component, though this is not required.

a typical example might look like ["en_US", "en_UK", "en_AU", "fr_FR", "de_DE", "it_IT", "es_ES" "pt_PT", "zh_CN", "ja_JP", "ko_KR", "ar_EG"]

options.dest

Type: String

Default value: "strings/{lang}/{bundle}.json"

A path pattern for writing out the i18n json files.

{lang} is replaced with one of the codes from options.langs

{bundle} is replaced with the name of the language bundle. In the example above this would be Project

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style.

Release History

0.1.0 Initial Publish