This repository has been archived by the owner on Feb 15, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Kelly Selden
committed
Jan 11, 2016
1 parent
ea34bbe
commit ed7ecf0
Showing
12 changed files
with
178 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"presets": ["es2015", "stage-2"], | ||
"plugins": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
node_modules | ||
coverage | ||
dist | ||
node_modules | ||
tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
var toCsv = require('./to-csv'); | ||
var toJs = require('./to-js'); | ||
import toCsv from './to-csv'; | ||
import toJs from './to-js'; | ||
|
||
module.exports = function(direction, localesPath, csvPath, options) { | ||
export default function(direction, localesPath, csvPath, options) { | ||
switch (direction) { | ||
case 'to-csv': | ||
toCsv(localesPath, csvPath, options); | ||
break; | ||
return toCsv(localesPath, csvPath, options); | ||
case 'to-js': | ||
toJs(csvPath, localesPath, options); | ||
break; | ||
return toJs(csvPath, localesPath, options); | ||
default: | ||
return Promise.reject(); | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,69 @@ | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
var stringify = require('csv-stringify'); | ||
var eol = require('eol'); | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import csvStringify from 'csv-stringify'; | ||
import eol from 'eol'; | ||
import denodeify from 'denodeify'; | ||
require('6to5/register'); | ||
|
||
module.exports = function(localesPath, csvPath) { | ||
var locales = fs.readdirSync(localesPath); | ||
const readdir = denodeify(fs.readdir); | ||
const writeFile = denodeify(fs.writeFile); | ||
const stringify = denodeify(csvStringify); | ||
|
||
var keys = []; | ||
var rows = []; | ||
export default function(localesPath, csvPath) { | ||
return readdir(localesPath).then(locales => { | ||
let keys = []; | ||
let rows = []; | ||
|
||
function recurse(json, columnIndex, rowIndex, currentKey) { | ||
for (var key in json) { | ||
var value = json[key]; | ||
var newKey = currentKey; | ||
if (newKey) { | ||
newKey += '.'; | ||
} | ||
newKey += key; | ||
if (typeof value === 'object') { | ||
rowIndex = recurse(value, columnIndex, rowIndex, newKey); | ||
} else { | ||
var row; | ||
var index = keys.indexOf(newKey); | ||
if (index !== -1) { | ||
row = rows[index]; | ||
} else { | ||
row = []; | ||
rows.splice(rowIndex, 0, row); | ||
keys.splice(rowIndex, 0, newKey); | ||
function recurse(json, columnIndex, rowIndex, currentKey) { | ||
for (let key in json) { | ||
let value = json[key]; | ||
let newKey = currentKey; | ||
if (newKey) { | ||
newKey += '.'; | ||
} | ||
for (var i in locales) { | ||
if (i == columnIndex) { | ||
row[i] = value; | ||
} else if (!row[i]) { | ||
row[i] = ''; | ||
newKey += key; | ||
// debugger; | ||
if (typeof value === 'object') { | ||
rowIndex = recurse(value, columnIndex, rowIndex, newKey); | ||
} else { | ||
let row; | ||
let index = keys.indexOf(newKey); | ||
if (index !== -1) { | ||
row = rows[index]; | ||
} else { | ||
row = []; | ||
rows.splice(rowIndex, 0, row); | ||
keys.splice(rowIndex, 0, newKey); | ||
} | ||
for (let i in locales) { | ||
if (i == columnIndex) { | ||
row[i] = value; | ||
} else if (!row[i]) { | ||
row[i] = ''; | ||
} | ||
} | ||
rowIndex++; | ||
} | ||
rowIndex++; | ||
} | ||
return rowIndex; | ||
} | ||
return rowIndex; | ||
} | ||
|
||
for (var columnIndex in locales) { | ||
var locale = locales[columnIndex]; | ||
var filePath = path.resolve(localesPath, locale, 'translations.js'); | ||
var json = require(filePath); | ||
recurse(json, columnIndex, 0, ''); | ||
} | ||
for (let columnIndex in locales) { | ||
let locale = locales[columnIndex]; | ||
let filePath = path.resolve(localesPath, locale, 'translations.js'); | ||
let json = require(filePath); | ||
recurse(json, columnIndex, 0, ''); | ||
} | ||
|
||
var lines = []; | ||
lines.push(['key'].concat(locales.map(function(locale) { return locale.replace('.js', ''); }))); | ||
for (var i in keys) { | ||
lines.push([keys[i]].concat(rows[i])); | ||
} | ||
let lines = []; | ||
lines.push(['key'].concat(locales.map(locale => locale.replace('.js', '')))); | ||
for (let i in keys) { | ||
lines.push([keys[i]].concat(rows[i])); | ||
} | ||
|
||
stringify(lines, function(err, csv) { | ||
var normalized = eol.auto(csv); | ||
fs.writeFileSync(csvPath, normalized); | ||
return stringify(lines); | ||
}).then(csv => { | ||
let normalized = eol.auto(csv); | ||
return writeFile(csvPath, normalized); | ||
}); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.