0ad/binaries/data/mods/public/gui/locale/locale.js
Dunedan 93ce94655d
Use @stylistic/brace-style for eslint
Up to now `eslint-plugin-brace-rules` was used to enforce a common brace
style for JavaScript code. This plugin was however updated the last time
over 9 years ago and will be incompatible with ESLint v10, as that
[removes `context.getSourceCode()`][1], the plugin relies on.

To keep the eslint config working with ESLint v10, this replaces
`eslint-plugin-brace-rules` with the [`@stylistic/brace-style`][2] rule
from `@stylistic/eslint-plugin`, a package we already use.

While `@stylistic/brace-style` doesn't offer an option to format braces
in exactly the same way as before, the "allman" style seems to be the
one closest to the existing code.

[1]: https://eslint.org/blog/2025/11/eslint-v10.0.0-alpha.0-released/#removed-deprecated-rule-context-members
[2]: https://eslint.style/rules/brace-style
2026-01-12 21:33:52 +01:00

69 lines
2.2 KiB
JavaScript

function init()
{
var languageList = Engine.GetGUIObjectByName("languageList");
const displayLanguages = Engine.GetSupportedLocaleDisplayNames();
const displayLanguagesData = Engine.GetSupportedLocaleBaseNames();
languageList.list = displayLanguages.map((name, index) =>
{
return `[locale="${displayLanguagesData[index]}"]${name}[/locale]`;
});
languageList.list_data = displayLanguagesData;
var currentLocale = Engine.GetCurrentLocale();
var currentLocaleDictName = Engine.GetFallbackToAvailableDictLocale(currentLocale);
var index = languageList.list_data.indexOf(currentLocaleDictName);
if (index != -1)
languageList.selected = index;
var localeText = Engine.GetGUIObjectByName("localeText");
localeText.caption = currentLocale;
return new Promise(closePageCallback =>
{
Engine.GetGUIObjectByName("cancelButton").onPress = closePageCallback;
});
}
function applySelectedLocale()
{
var localeText = Engine.GetGUIObjectByName("localeText");
if (!Engine.SaveLocale(localeText.caption))
{
warn("Selected locale could not be saved in the configuration!");
return;
}
Engine.ReevaluateCurrentLocaleAndReload();
Engine.SwitchGuiPage("page_pregame.xml");
}
function languageSelectionChanged()
{
var languageList = Engine.GetGUIObjectByName("languageList");
var locale = languageList.list_data[languageList.selected];
if (locale == "long")
warn("'long' is not an actual language, just a collection of all longest strings extracted from some languages");
else if (!Engine.ValidateLocale(locale))
warn("Selected locale is not valid! This is not expected, please report the issue.");
var localeText = Engine.GetGUIObjectByName("localeText");
localeText.caption = locale;
}
async function openAdvancedMenu()
{
const localeText = Engine.GetGUIObjectByName("localeText");
const locale = await Engine.OpenChildPage("page_locale_advanced.xml", { "locale": localeText.caption });
if (!locale)
return;
var languageList = Engine.GetGUIObjectByName("languageList");
var currentLocaleDictName = Engine.GetFallbackToAvailableDictLocale(locale);
const index = languageList.list_data.indexOf(currentLocaleDictName);
if (index != -1)
languageList.selected = index;
localeText.caption = locale;
}