@woosh/dream-tools-localization
Advanced tools
Comparing version
{ | ||
"name": "@woosh/dream-tools-localization", | ||
"type": "module", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "Localization tooling for DREAM engine", | ||
@@ -6,0 +6,0 @@ "main": "index.js", |
@@ -7,17 +7,18 @@ import XLSX from 'xlsx'; | ||
* @param {Buffer} file | ||
* @returns {{json:Object,name:string}[]} | ||
* @param {number} [worksheet_index] | ||
* @returns {{json:Object, name:string }[]} name is the name of locale, taken from first row of the XLS | ||
*/ | ||
export function parse_localization_XLS_to_JSON(file) { | ||
export function parse_localization_XLS_to_JSON({ file, worksheet_index = 0 }) { | ||
/* Call XLSX */ | ||
var workbook = XLSX.read(file, { type: "buffer" }); | ||
const workbook = XLSX.read(file, { type: "buffer" }); | ||
var worksheet = workbook.Sheets[workbook.SheetNames[0]]; | ||
const sheet = workbook.Sheets[workbook.SheetNames[worksheet_index]]; | ||
const j = XLSX.utils.sheet_to_json(worksheet, { raw: false, header: 1 }); | ||
const sheet_json = XLSX.utils.sheet_to_json(sheet, { raw: false, header: 1 }); | ||
const headerRow = j[0]; | ||
const headerRow = sheet_json[0]; | ||
const languages = headerRow.slice(1); | ||
const rowCount = j.length; | ||
const rowCount = sheet_json.length; | ||
@@ -33,3 +34,3 @@ const result = []; | ||
for (let k = 1; k < rowCount; k++) { | ||
const row = j[k]; | ||
const row = sheet_json[k]; | ||
@@ -64,3 +65,3 @@ const key = row[0]; | ||
result.push({ | ||
name: `${language}.json`, | ||
name: language, | ||
json: json | ||
@@ -67,0 +68,0 @@ }); |
9849
1.66%49
2.08%