Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

grunt-i18n-gspreadsheet

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

grunt-i18n-gspreadsheet - npm Package Compare versions

Comparing version 0.1.3 to 0.1.4

1

Gruntfile.js

@@ -35,2 +35,3 @@ /*

options: {
key_column: 'key',
output_dir: 'tmp',

@@ -37,0 +38,0 @@ // this document key points to the test file -- see readme for more info

4

package.json
{
"name": "grunt-i18n-gspreadsheet",
"description": "Grunt plugin to generate i18n locale files from a google spreadsheet",
"version": "0.1.3",
"version": "0.1.4",
"homepage": "https://github.com/theoephraim/grunt-i18n-gspreadsheet",

@@ -43,3 +43,3 @@ "author": {

"dependencies": {
"google-spreadsheet": "~0.2.4",
"google-spreadsheet": "~0.2.5",
"step": "0.0.5",

@@ -46,0 +46,0 @@ "underscore": "~1.5.2",

@@ -59,9 +59,9 @@ # grunt-i18n-gspreadsheet

#### options.key_column
Type: `String` -- Default: `'key'`
Type: `String`
The column header for the translation keys.
The column header for special translation keys. Some explanation:
When using i18n plugins, usually one writes `__('Thing to translate')`. In your spreadsheet, one of your columns will hold all of these translation keys. This option allows you to override the name of this column.
When using i18n plugins, usually one writes `__('Thing to translate')`. The key in this case is the thing to be translated in the default language. But sometimes for longer items of text, you may want to use a special string. For example, `__('!ABOUT.BIO')`. In your spreadsheet, you can have one column that is used to hold these special keys. This option allows you to enable this feature and set the name the column to use.
**NOTE** Google spreadsheets API alters column headers slightly. It will force all lower case and remove all spaces. It is recommended to just use a column name in this format already, but if you cannot, you may need to debug a little to figure out the column name that the api is using.
**NOTE** Google spreadsheets API alters column headers slightly. It will force all lower case and remove all spaces/special characters. For example "My Column Header!" would become "mycolumnheader". It is recommended to just use a column name in this format already, but if you cannot, you may need to debug a little to figure out the column name that the api is using.

@@ -74,5 +74,5 @@ #### options.default_locale

#### options.write_default_translations
Type: `Boolean` -- Default: `true`
Type: `Boolean` -- Default: `false`
Whether to write default translations or not. This is useful because most of the time, the default language translation is used as the translation key. But occasionally for some longer text items, you may wish to keep the key as key instead of text. This option lets you leave the default locale column (`en` by default) blank, but the translations will still end up in your `en.js` translation file. Most i18n plugins will default to use the translation key if no translation is found, but this may be useful in some cases.
Whether to include default translations or not. Normally the default language translations are used as the translation keys, and most i18n plugins will display this translation key if no translation is found - making it unnecessary to have a file full of redundant pairs like `"About us": "About us"`. This option tells the plugin to write these redundant pairs to the default language file anyway. Might be useful for someone.

@@ -79,0 +79,0 @@ #### options.sort_keys

@@ -20,2 +20,13 @@ /*

function sortObjectByKeys(map) {
var keys = _.sortBy(_.keys(map), function(a) { return a; });
var newmap = {};
_.each(keys, function(k) {
newmap[k] = map[k];
});
return newmap;
}
grunt.registerMultiTask('i18n_gspreadsheet', 'Grunt plugin to generate i18n locale files from a google spreadsheet', function() {

@@ -25,3 +36,2 @@

var options = this.options({
key_column: 'key',
output_dir: 'locales',

@@ -80,9 +90,15 @@ default_locale: 'en',

_(rows).each(function(row){
var translation_key = row[options.key_column];
// if an key override column is set, check that first, then use the default locale
var use_key_override = options.key_column && row[options.key_column];
var translation_key = use_key_override ? row[options.key_column] : row[options.default_locale];
if ( !translation_key ) return;
_(locales).each(function(locale){
if ( row[locale] ){
if ( locale == options.default_locale ){
if ( use_key_override || options.write_default_translations ){
translations[locale][translation_key] = row[locale];
}
} else if ( row[locale] ) {
translations[locale][translation_key] = row[locale];
} else if ( locale == options.default_locale && options.write_default_translations ){
translations[locale][translation_key] = translation_key;
}

@@ -114,3 +130,3 @@ });

flags: 'w+'
}
};
fs.writeFile( file_path, translation_json, write_options, step.parallel() );

@@ -131,13 +147,2 @@ });

};
function sortObjectByKeys(map) {
var keys = _.sortBy(_.keys(map), function(a) { return a; });
var newmap = {};
_.each(keys, function(k) {
newmap[k] = map[k];
});
return newmap;
}
};

@@ -23,3 +23,3 @@ 'use strict';

var translations = JSON.parse( grunt.file.read('tmp/'+locale+'.js') );
test.equal( translations.test, locale, locale+'.js file should have correct translation from google doc');
test.equal( translations['!test'], locale, locale+'.js file should have correct translation from google doc');
});

@@ -26,0 +26,0 @@ test.done();

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc