1 | import fs from "fs"
|
2 | import _ from "lodash"
|
3 | import { importXlsx } from "./utils"
|
4 | import { updateLocalizedStrings } from "./utils"
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | export default function importLocalizationFileFromXlsx(oldDataFile: string, xlsxFile: string, newDataFile: string): void {
|
13 |
|
14 | const base64File = fs.readFileSync(xlsxFile, "base64")
|
15 |
|
16 | const localizations = JSON.parse(fs.readFileSync(oldDataFile, "utf-8"))
|
17 |
|
18 | const updates = importXlsx(localizations.locales, base64File)
|
19 | updateLocalizedStrings(localizations.strings, updates)
|
20 |
|
21 |
|
22 | localizations.strings = _.sortBy(localizations.strings, function (l: any) {
|
23 | if (l._unused) {
|
24 | return 1
|
25 | } else {
|
26 | return 0
|
27 | }
|
28 | })
|
29 |
|
30 |
|
31 | fs.writeFileSync(newDataFile, JSON.stringify(localizations, null, 2), "utf-8")
|
32 | return localizations
|
33 | }
|