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-resxtoi18n

v0.1.8

Published

Convert resx files to requireJS i18n resource files.

Downloads

5

Readme

grunt-resxtoi18n

Convert ASP.NET resx files to requireJS i18n resource files. The structure of ASP.NET resx resources is typically MyResource.resx for the main (default) resource file and then e.g. MyResource.no.resx for the norwegian resource file, MyResource.da.resx for the danish and so on. RequireJS i18n files is normally saved in a structured hierarchy with the main file at the root and then specific language files in sub directories below. Like (for the sample above): nls/myresources.js nls/nb-no/myresources.js nls/da-dk/myresources.js

Sample contents of main file:

define({
'nb-no': true,
'da-dk': true,
root:{"WindowTitle_Contacts":"Contacts","PageTitle_Address":"Address"}
});

Sample contents of language specific file:

define(
{"WindowTitle_Contacts":"Kontakter"}
);

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-resxtoi18n --save-dev

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

grunt.loadNpmTasks('grunt-resxtoi18n');

The "resxtoi18n" task

Overview

In your project's Gruntfile, add a section named resxtoi18n to the data object passed into grunt.initConfig().

grunt.initConfig({
  resxtoi18n: {
    options: {
      // Task-specific options go here.
    },
    your_target: {
      // Target-specific file lists and/or options go here.
    },
  },
});

Options

options.requireSyntax

Type: Boolean Default value: false

If set to true the output will be created with requireJS syntax (using define). If set to false, the output is a plain json conversion of the resx file.

options.languageCodes

Type: Object Default value: undefined

Only to be specified when requireSyntax is true. Defines how the language code from the resx file should be translated into the i18n notation. If the languagecodes should be used as they are (no conversion), specify an empty object (languageCodes: {}). As long as languageCodes are specified the requireJs hierarchy will be created as in the sample. E.g languageCodes: {no:'nb-no'} would cause a Common.no.resx to be converted into dest/nb-no/common.js and the attribute 'nb-no': true to be added to the main i18n file.

options.useLowerCaseLang

Type: Boolean Default value: false

Only to be specified when requireSyntax is true. Ensure that languageCodes and destination directories are in lowercase.

options.preDefinedLanguageCodes

Type: Array Default value: undefined

Only to be specified when requireSyntax is true. Defines language codes that are manually handled and that should be added to the main i18n file. E:g preDefinedLanguageCodes = ['nn'] would cause attribute "'nn': true" to be added to the main file.

options.sorted

Type: Boolean Default value: false

If set to false the resources in the resulting js files will be in the same order as the original resx file. If set to true the resources will be sorted on the key value.

options.breakLines

Type: Boolean Default value: false

If set to true the a line break will be inserted between each resource, making it easier to read.

options.extendWithBaseTranslation

Type: Boolean Default value: false

If set to false any missing resources in sub language files will still be missing in the result files. If set to true the value from the base resx will be inserted.

options.matchPattern

Type: String Default value: undefined

A regular expression which is used to match against resource keys.

The "resxtoi18n" task

Overview

In your project's Gruntfile, add a section named resxtoi18n to the data object passed into grunt.initConfig().

grunt.initConfig({
  resxtoi18n: {
    options: {
      // Task-specific options go here.
    },
    your_target: {
      // Target-specific file lists and/or options go here.
    },
  },
});

Usage Examples

grunt.initConfig({
  resxtoi18n: {
    options: {
        requireSyntax: true,
		languageCodes: {
			no: 'nb-no',
			da: 'da-dk'
		}
    }
    common: {
      src: '../App_GlobalResources/Common.resx',
      dest: '/jsbuild/i18n/nls/',
    }
    default: {
      src: '../App_GlobalResources/Default.resx',
      dest: '/jsbuild/i18n/nls/',
    }
  },
  },
});

src

Please note that the source file should point to the main resx file. This language resources from this file will be used as a fallback, when a specific translation does not exist.

dest

Destination top directory

Release History

0.1.0 First version, based on resxtojson by Eric Beragg 0.1.1 Added option sorted 0.1.2 Added option breakLines 0.1.3 Added option extendWithBaseTranslation 0.1.4 Documentation changes 0.1.5 Sorting do no longer use localeCompare. No compares binary lowercase values. 0.1.6 Allow grunt 1.0. 0.1.7 Added option preDefinedLanguageCodes