Converts a set of localization files in the resx file format to a set of JSON dictionaries
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');
Run this task with the grunt resx2json
command.
Task targets, files and options may be specified according to the grunt Configuring tasks guide.
Type: String
Default: en
The locale that a file will be assumed to represent should the languagePattern not parse appropriately.
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
Type: String
Default: dist/
The output folder for the processed files.
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
.
Type: 'String'
Default: '.json'
The default extension for the output files to have.
Type: RegExp
Default: /^.+-(\w+).resx$/
A regular expression with a single capture group that extracts the appropriate locale
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.
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
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
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
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