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-resx-2-structured-json

v0.4.1

Published

Changing resx files to structured, nested json files

Downloads

3

Readme

grunt-resx-2-structured-json

Converts a set of localization files in the resx file format to a set of JSON dictionaries

Getting Started

This plugin requires Grunt ~0.4.0

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 git+https://github.com/jrnt30/grunt-resx2json.git --save-dev

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

grunt.loadNpmTasks('grunt-resx2json');

resx2json task

Run this task with the grunt resx2json command.

Task targets, files and options may be specified according to the grunt Configuring tasks guide.

Options

namespaceFrom

Type: 'String' Default: ''

In creating the output, each underlying folder from the 'namespaceFrom' root will be treated as a namespace for the sake of JSON generation.

For example:

Given a folder structure like so:

├── Localization/
│   ├── base-de.resx
│   ├── base-fr.resx
│   ├── base.resx
|   ├── Home/
|   |   ├── stuff.resx
|   |   ├── stuff-de.resx
|   |   └── stuff-fr.resx

Where namespace from is set to Localization\

Then an object like so would be created:

{
  //keys from base.resx would be here
  Home: {
    //keys from Home/stuff.resx would be here
  }
}

defaultLocale

Type: String Default: en

The locale that a file will be assumed to represent should the languagePattern not parse appropriately.

concat

Type: Boolean Default: false

Set concat to true to have all of the different locales be concated into a single output file, with their respective locale being the key and the value being the set of all corresponding values.

The default is false, which will then output a file per locale with the file format dest-locale``ext

dest

Type: String Default: dist/

The output folder for the processed files.

prefix

Type: String Defaut: output

When concat is false, this serves as the base name for the output, which will have the pattern prefix-locale``ext.

When concat is true, the output will be in the format prefix``ext.

ext

Type: 'String' Default: '.json'

The default extension for the output files to have.

languagePattern

Type: RegExp Default: /^.+-(\w+).resx$/

A regular expression with a single capture group that extracts the appropriate locale

localeExtractor

Type: Function Default: function(src, options){return dest}

A function given with arguments (src,options) that is responsible for providing the locale for the given file.

This is used by the plugin to group all the files of a single locale.

Usage examples

Src file declaration

In this example, simply using the common src attribute from standard Grunt configuration to specify the set of Resx files to process. This will result in a different file per locale in the dest location with ext extension.

// Project configuration.
grunt.initConfig({
  resx2json: {
    src: ['templates/**/*.resx']
  }
});

File Structure:

$ tree -I templates
.
├── baseLocalization/
│   ├── base-de.resx
│   ├── base-fr.resx
│   └── base.resx
└── extended/
    ├── extended-de.resx
    ├── extended-fr.resx
    └── extended.resx

2 directories, 6 files

File Output Structure:

$ tree -I dist
.
└── dist/
    |── output-de.json
    |── output-en.json
    └── output-fr.json

Custom prefix attribute

In this example, remove the prefix attribute from standard Grunt configuration to customize file output to be locale``ext

// Project configuration.
grunt.initConfig({
  resx2json: {
    src: ['templates/**/*.resx'],
    prefix: ''
  }
});

File Structure:

$ tree -I templates
.
├── baseLocalization/
│   ├── base-de.resx
│   ├── base-fr.resx
│   └── base.resx
└── extended/
    ├── extended-de.resx
    ├── extended-fr.resx
    └── extended.resx

2 directories, 6 files

File Output Structure:

$ tree -I dist
.
└── dist/
    |── de.json
    |── en.json
    └── fr.json

Concat

In this example, running grunt resx2json will result in a single json file, where there is a top level attribtue for each locale.

// Project configuration.
grunt.initConfig({
  resx2json: {
    src: ['templates/**/*.resx'],
    options: {
      concat: true
    }
  }
});

File Structure:

$ tree -I templates
.
├── baseLocalization/
│   ├── base-de.resx
│   ├── base-fr.resx
│   └── base.resx
└── extended/
    ├── extended-de.resx
    ├── extended-fr.resx
    └── extended.resx

2 directories, 6 files

File Output Structure:

$ tree -I dist
.
└── dist/
    └── output.json

Specifying custom locale pattern

In this example, we use a custom pattern to extract the locale of the files we are parsing. The will result in a file per parsed locale being generated.

// Project configuration.
grunt.initConfig({
  resx2json: {
    src: ['templates/**/*.resx'],
    options: {
      localePattern: /([a-z]{2,2})-.*$/
    }
  }
});

File Structure:

$ tree -I templates
.
├── baseLocalization/
│   ├── de-base.resx
│   ├── fr-base.resx
│   └── base.resx
└── extended/
    ├── de-extended.resx
    ├── fr-extended.resx
    └── extended.resx

2 directories, 6 files

File Output Structure:

$ tree -I dist
.
└── dist/
    |── output-de.json
    |── output-en.json
    └── output-fr.json