0.1.1 • Published 8 years ago

grunt-skyscanner-i18n v0.1.1

Weekly downloads
7
License
-
Repository
github
Last release
8 years ago

grunt-skyscanner-i18n

A grunt plugin that takes a collection of translation files and will traverse a collection of templated files and replaces the keys with the translated text.

Getting Started

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-skyscanner-i18n --save-dev

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

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

skyscanner-i18n task

Run this task with the grunt skyscanner-i18n command.

Settings

templates

Type: String|Array

The file patterns used to define where the task can find the templated files. It can be a string or an array of files and/or minimatch patterns.

translations

Type: String|Array

The file patterns used to define where the task can find the translation files. These files can be a .json, or .resx files.

options.outdir

Type: String Default: dist

The directory to output the generated files.

Example:

skyscanner-i18n: {
  scripts: {
    templates: ['**/*.js'],
    translations: ['**/*.resx'],
    options: {
      outputDir: 'release',
    },
  },
},

For backwards compatibility the option nospawn is still available and will do the opposite of spawn.

options.outputFormat

Type: String Default: {filename}.{locale}

The format string describing the file outputted by the plugin.

Example:

skyscanner-i18n: {
  scripts: {
    templates: ['**/*.js'],
    translations: ['**/*.resx'],
    options: {
      outputFormat: '{locale}/{filename}',
    },
  },
},

options.defaultLocale

Type: String Default: en-gb

The locale to use if the locale cannot be ascertained by the filename of the translation file i.e English translations are usually stored in a Resource.resx file.

Example:

skyscanner-i18n: {
  scripts: {
    templates: ['**/*.js'],
    translations: ['**/*.resx'],
    options: {
      defaultLocale: 'en-us',
    },
  },
},

options.success

Type: Function

A function that is called when the task has produced a file for template

Example:

skyscanner-i18n: {
  scripts: {
    templates: ['**/*.js'],
    translations: ['**/*.resx'],
    options: {
      success: function(result) {
        grunt.log.ok('file for locale ' + result.locale + ' created: ' + result.file);
      }
  },
},

options.finished

Type: Function

Example:

skyscanner-i18n: {
  scripts: {
    templates: ['**/*.js'],
    translations: ['**/*.resx'],
    options: {
      finish: function(result) {
        grunt.log.ok('finished generating files!!');
      }
  },
},