refactor(i18n): move list of locales out of options

This commit is contained in:
Elian Doran
2025-02-20 12:27:33 +02:00
parent 6b5d905ebe
commit 4e01534d76
2 changed files with 36 additions and 32 deletions

View File

@@ -5,7 +5,7 @@ import log from "../../services/log.js";
import searchService from "../../services/search/services/search.js";
import ValidationError from "../../errors/validation_error.js";
import type { Request } from "express";
import { changeLanguage } from "../../services/i18n.js";
import { changeLanguage, getLocales } from "../../services/i18n.js";
import { listSyntaxHighlightingThemes } from "../../services/code_block_theme.js";
import type { OptionNames } from "../../services/options_interface.js";
@@ -154,37 +154,7 @@ function getSyntaxHighlightingThemes() {
}
function getSupportedLocales() {
// TODO: Currently hardcoded, needs to read the list of available languages.
return [
{
id: "en",
name: "English"
},
{
id: "de",
name: "Deutsch"
},
{
id: "es",
name: "Español"
},
{
id: "fr",
name: "Français"
},
{
id: "cn",
name: "简体中文"
},
{
id: "tw",
name: "繁體中文"
},
{
id: "ro",
name: "Română"
}
];
return getLocales();
}
function isAllowed(name: string) {

View File

@@ -20,6 +20,40 @@ export async function initializeTranslations() {
});
}
export function getLocales() {
// TODO: Currently hardcoded, needs to read the list of available languages.
return [
{
id: "en",
name: "English"
},
{
id: "de",
name: "Deutsch"
},
{
id: "es",
name: "Español"
},
{
id: "fr",
name: "Français"
},
{
id: "cn",
name: "简体中文"
},
{
id: "tw",
name: "繁體中文"
},
{
id: "ro",
name: "Română"
}
];
}
function getCurrentLanguage() {
let language;
if (sql_init.isDbInitialized()) {