1.0.5 • Published 10 years ago

es-resx-to-js v1.0.5

Weekly downloads
8
License
ISC
Repository
github
Last release
10 years ago

Resx to JS

This is a small helper module which is transforming the localization files from RESX files into JS files.

JS files are being created by template.

package.json

#!json

"devDependencies": {
  "es-resx-to-js": "^1.0.0"
}

How to setup the GULP task

#!javascript

// Import the RESX to JS module
var resxtojs = require('es-resx-to-js');

gulp.task('TAKS_NAME', function() {
  // Module Build Function
  resxtojs.build(
    {
      // Define all mappings between RESX files and JS files
      // An array of mapping objects
      mapping: [
        {
          // Relative/Absolute path to RESX files
          // RESX files for additional languages are being automatically resolved:
          // - Based on the langs param
          // - RESX files have to follow the expected filename convention, see the section Expected RESX file format
          resx: '[...]/ExampleModule.resx',
          // Relative/Absolute path to JS file
          // JS files for additional languages are being automatically resolved.
          // - Based on the langs param
          js: '[...]/example-module.js',
          // Resource base name
          // Used as the localization root object
          resName: 'ExampleModule'
        }
      ],
      // Relative/Absolute path to the JS file template
      // This file content is being used for the JS file creating 
      // See the JS File Template Section
      template: '[...]/template.txt',
      // List of all "non-default" languages
      // OPTIONAL: If there are no other languages than just delete this param
      langs: ['es']
    },
    // Callback function which contains the log messages from the module
    function(log) {
      console.log(log);
    }
  );
});

Expected RESX file format

RESX files containing additional languages should use this name convention:

  • ExampleModule.resx - Default Language RESX file
  • EmxapleModule.es.resx - Spanish RESX file

JS File Template

#!javascript

// Root namespace
var Evoke = Evoke || {};

// Localization namespace
Evoke.App.Localization = Evoke.App.Localization || {};

/*
 * Auto-generated localization file
 * Source file: {filename}
 * Lang: {lang}
*/

// Name of the localization resource
var resName = '{resname}';

// Declare all localization strings as object paramers
Evoke.App.Localization[resName] = {
  {keyValuePairs}
};
  • {filename} - This tag is being replaced with source RESX filename
  • {lang} - This tag is being replaced with language code of given RESX file. (Default language code is set to "default")
  • {resname} - This tag is being replaced with Resource Base Name
  • {keyValuePairs} - This tag is being replaced with generated Key Value pairs of localization entries
1.0.5

10 years ago

1.0.4

10 years ago

1.0.3

10 years ago

1.0.2

10 years ago

1.0.0

10 years ago