feat: sort translation json keys alphabetically

This commit is contained in:
Nybkox
2025-02-25 16:23:23 +01:00
parent 3e6aab6b00
commit 82eabc41fe
2 changed files with 30 additions and 2 deletions

View File

@@ -2,6 +2,7 @@
const path = require('path');
const fs = require('fs');
const { defaultLanguage } = require('./constants');
const sortJsonKeysAlphabetically = require('../sortJsonKeysAlphabetically');
/**
* @param {string} file
@@ -145,7 +146,9 @@ function getLanguageTranslations(language) {
*/
function setLanguageTranslations(language, translations) {
const file = resolveFile(`translations/${language}.json`);
fs.writeFileSync(file, JSON.stringify(translations, null, 2));
const sorted = sortJsonKeysAlphabetically(translations);
fs.writeFileSync(file, JSON.stringify(sorted, null, 2));
}
/**
@@ -155,8 +158,9 @@ function setLanguageTranslations(language, translations) {
function updateLanguageTranslations(language, newTranslations) {
const translations = getLanguageTranslations(language);
const updatedTranslations = { ...translations, ...newTranslations };
const sorted = sortJsonKeysAlphabetically(updatedTranslations);
setLanguageTranslations(language, updatedTranslations);
setLanguageTranslations(language, sorted);
}
function getAllLanguages() {