Skip to content

Commit a836c80

Browse files
authored
Merge branch 'main' into kh/bug-terms
2 parents 0bef7e6 + bddd700 commit a836c80

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

lib/build.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import marky from 'marky';
99
import { createRequire } from 'module';
1010
import { compile, toSafeIdentifier } from 'json-schema-to-typescript-lite';
1111

12-
import fetchTranslations, { expandTStrings } from './translations.js';
12+
import fetchTranslations, { expandTStrings, sortObject } from './translations.js';
1313

1414
const require = createRequire(import.meta.url);
1515

@@ -162,6 +162,10 @@ function processData(options, type) {
162162
shell.rm('-rf', [distDir + '/translations']);
163163
}
164164

165+
categories = sortObject(categories);
166+
fields = sortObject(fields);
167+
presets = sortObject(presets);
168+
165169
fs.writeFileSync(distDir + '/preset_categories.json', JSON.stringify(categories, null, 4));
166170
fs.writeFileSync(distDir + '/fields.json', JSON.stringify(fields, null, 4));
167171
fs.writeFileSync(distDir + '/presets.json', JSON.stringify(presets, null, 4));

lib/translations.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,18 @@ export function expandTStrings(tstrings) {
7070
}
7171
}
7272

73+
/**
74+
* Sorts the keys of an object alphabetically
75+
* @template {object} T @param {T} original @returns {T}
76+
*/
77+
export function sortObject(original) {
78+
const sorted = {};
79+
for (const k of Object.keys(original).sort()) {
80+
sorted[k] = original[k];
81+
}
82+
return sorted;
83+
}
84+
7385
function fetchTranslations(options) {
7486

7587
// Transifex doesn't allow anonymous downloading
@@ -164,9 +176,7 @@ function fetchTranslations(options) {
164176
};
165177
}
166178

167-
const keys = Object.keys(dataLocales).sort();
168-
let sortedLocales = {};
169-
keys.forEach(k => sortedLocales[k] = dataLocales[k]);
179+
const sortedLocales = sortObject(dataLocales);
170180
fs.writeFileSync(`${outDir}/index.json`, JSON.stringify(sortedLocales));
171181
fs.writeFileSync(`${outDir}/index.min.json`, JSON.stringify(sortedLocales, null, 4));
172182
}

0 commit comments

Comments
 (0)