Skip to content

Commit

Permalink
Implemented theoephraim#2
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurentGoderre committed Nov 1, 2013
1 parent 1bbc942 commit d7830d9
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 189 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
node_modules
npm-debug.log
tmp
tmp_*
locales
48 changes: 39 additions & 9 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* grunt-i18n-gspreadsheet
* https://github.com/theoephraim/grunt-i18n-gspreadsheet
* grunt-i18n-spreadsheet
* https://github.com/theoephraim/grunt-i18n-spreadsheet
*
* Copyright (c) 2013 Theo Ephraim
* Licensed under the MIT license.
Expand All @@ -25,17 +25,46 @@ module.exports = function(grunt) {

// Before generating any new files, remove any previously-created files.
clean: {
tests: ['tmp'],
tests: ['tmp_*'],
},

connect: {
server: {
options: {
port: 8080,
base: "server"
}
}
},

// Configuration to be run (and then tested).
i18n_gspreadsheet: {
test_config: {
i18n_spreadsheet: {
gdocs_test_config: {
options: {
key_column: 'key',
output_dir: 'tmp_gdocs',
google_docs: {
// this document key points to the test file -- see readme for more info
document_key: '0Araic6gTol6SdEtwb1Badl92c2tlek45OUxJZDlyN2c'
}
}
},
http_test_config: {
options: {
key_column: 'key',
output_dir: 'tmp_http',
http: {
url: 'http://localhost:8080/grunt-i18n-spreadsheet.csv'
}
}
},
local_test_config: {
options: {
key_column: 'key',
output_dir: 'tmp',
// this document key points to the test file -- see readme for more info
document_key: '0Araic6gTol6SdEtwb1Badl92c2tlek45OUxJZDlyN2c'
output_dir: 'tmp_local',
local: {
src: 'server/grunt-i18n-spreadsheet.csv'
}
}
}
},
Expand All @@ -53,11 +82,12 @@ module.exports = function(grunt) {
// These plugins provide necessary tasks.
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-contrib-nodeunit');

// Whenever the "test" task is run, first clean the "tmp" dir, then run this
// plugin's task(s), then test the result.
grunt.registerTask('test', ['clean', 'i18n_gspreadsheet', 'nodeunit']);
grunt.registerTask('test', ['clean', 'connect', 'i18n_spreadsheet', 'nodeunit']);

// By default, lint and run all tests.
grunt.registerTask('default', ['jshint', 'test']);
Expand Down
15 changes: 12 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,27 @@
"grunt-contrib-jshint": "~0.6.0",
"grunt-contrib-clean": "~0.4.0",
"grunt-contrib-nodeunit": "~0.2.0",
"grunt": "~0.4.1"
"grunt": "~0.4.1",
"grunt-contrib-connect": "~0.5.0"
},
"peerDependencies": {
"grunt": "~0.4.1"
},
"keywords": [
"gruntplugin", "grunt", "i18n", "google", "spreadsheet", "gdocs", "locale"
"gruntplugin",
"grunt",
"i18n",
"google",
"spreadsheet",
"gdocs",
"locale"
],
"dependencies": {
"google-spreadsheet": "~0.2.5",
"step": "0.0.5",
"underscore": "~1.5.2",
"mkdirp": "~0.3.5"
"mkdirp": "~0.3.5",
"request": "~2.27.0",
"csv": "~0.3.6"
}
}
Binary file added server/Thumbs.db
Binary file not shown.
9 changes: 9 additions & 0 deletions server/grunt-i18n-spreadsheet.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
key,en,fr,es,comments
!test,en,fr,es,Must be the same as locale -- used for testing
,hello,bonjour,hola,default (en) is empty for testing
,goodbye,Au revoir,Adios,
!newlineTest1,"This item
has a newline in it.",,,
!newlineTest2,"This item

has 2 newlines in it.",,,
143 changes: 0 additions & 143 deletions tasks/i18n_gspreadsheet.js

This file was deleted.

34 changes: 0 additions & 34 deletions test/i18n_gspreadsheet_test.js

This file was deleted.

40 changes: 40 additions & 0 deletions test/i18n_spreadsheet_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
'use strict';

var grunt = require('grunt');
var _ = require('underscore');


/*
These tests use the test spreadsheet accessible at https://docs.google.com/spreadsheet/ccc?key=0Araic6gTol6SdEtwb1Badl92c2tlek45OUxJZDlyN2c#gid=0
It is read-only to the public.
If you need to add something to it in order to test new features, please contact [email protected] to get write access to the doc.
*/

exports.i18n_spreadsheet = {
test_files: function(test) {
// the "test" row of each spreadsheet has the key of each locale (en.test = "en")
var test_locales = ['en','es','fr'];
var types = ['gdocs', 'http', 'local'];
test.expect( types.length * test_locales.length );
_(types).each(function(type){
_(test_locales).each(function(locale){
var translations = JSON.parse( grunt.file.read('tmp_' + type + '/'+locale+'.js') );
test.equal( translations['!test'], locale, locale+'.js file should have correct translation from google doc');
});
});
test.done();
},
test_default_translations: function(test){
// the spreasheet has en.hello as empty, but the default translation option should fill it anyway
var types = ['gdocs', 'http', 'local'];
test.expect(types.length);
_(types).each(function(type){
var translations = JSON.parse( grunt.file.read('tmp_' + type + '/en.js') );
test.equal( translations.hello, 'hello', 'default translation should get filled from key column');
});
test.done();
}
};

0 comments on commit d7830d9

Please sign in to comment.