mirror of
https://github.com/amiayweb/Hytale-F2P.git
synced 2026-02-26 18:01:45 -03:00
* - Implemented i18n. - Updated UI elements to use localized strings for various messages and confirmations. - Added language selection functionality in settings with appropriate event handling. - Created English localization file with translations for all new strings. - Updated backend to save and load user-selected language preferences. * Add Spanish localization for the GUI * Add Portuguese (Brazil) localization for the GUI * update main branch to release/v2.0.2b (#86) * add more linux pkgs, create auto-release and pre-release feature for Github Actions * removed package-lock from gitignore * update .gitignore for local build * add package-lock.json to maintain stability development * update version to 2.0.2b also add deps for rpm and arch * update 2.0.2b: add arm64 support, product and executable name, maintainers; remove snap; * update 2.0.2b: add latest.yml for win & linux, arm64 support; remove snap * fix release build naming * Prepare release v2.0.2b * Update localization for game repair and GPU settings Added new localization entries for game repair and GPU preferences. * Update spanish localization for game repair and GPU settings * Update portuguese (brazil) for game repair and GPU settings * Update localization for system logs in English, Spanish, and Portuguese --------- Co-authored-by: Fazri Gading <fazrigading@gmail.com>
90 lines
2.1 KiB
JavaScript
90 lines
2.1 KiB
JavaScript
// Minimal i18n system - optimized async loading
|
|
const i18n = (() => {
|
|
let currentLang = 'en';
|
|
let translations = {};
|
|
const availableLanguages = [
|
|
{ code: 'en', name: 'English' },
|
|
{ code: 'es', name: 'Español' },
|
|
{ code: 'pt-BR', name: 'Português (Brasil)' }
|
|
];
|
|
|
|
// Load single language file
|
|
async function loadLanguage(lang) {
|
|
if (translations[lang]) return true;
|
|
|
|
try {
|
|
const response = await fetch(`locales/${lang}.json`);
|
|
if (response.ok) {
|
|
translations[lang] = await response.json();
|
|
return true;
|
|
}
|
|
} catch (e) {
|
|
console.warn(`Failed to load language: ${lang}`);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
// Get translation by key
|
|
function t(key) {
|
|
const keys = key.split('.');
|
|
let value = translations[currentLang];
|
|
|
|
for (const k of keys) {
|
|
if (value && value[k] !== undefined) {
|
|
value = value[k];
|
|
} else {
|
|
return key;
|
|
}
|
|
}
|
|
|
|
return value;
|
|
}
|
|
|
|
// Set language
|
|
async function setLanguage(lang) {
|
|
await loadLanguage(lang);
|
|
if (translations[lang]) {
|
|
currentLang = lang;
|
|
updateDOM();
|
|
window.electronAPI?.saveLanguage(lang);
|
|
}
|
|
}
|
|
|
|
// Update all elements with data-i18n attribute
|
|
function updateDOM() {
|
|
document.querySelectorAll('[data-i18n]').forEach(el => {
|
|
const key = el.getAttribute('data-i18n');
|
|
el.textContent = t(key);
|
|
});
|
|
|
|
document.querySelectorAll('[data-i18n-placeholder]').forEach(el => {
|
|
const key = el.getAttribute('data-i18n-placeholder');
|
|
el.placeholder = t(key);
|
|
});
|
|
|
|
document.querySelectorAll('[data-i18n-title]').forEach(el => {
|
|
const key = el.getAttribute('data-i18n-title');
|
|
el.title = t(key);
|
|
});
|
|
}
|
|
|
|
// Initialize - load saved language only
|
|
async function init(savedLang) {
|
|
const lang = savedLang || 'en';
|
|
await loadLanguage(lang);
|
|
currentLang = lang;
|
|
updateDOM();
|
|
}
|
|
|
|
return {
|
|
init,
|
|
t,
|
|
setLanguage,
|
|
getAvailableLanguages: () => availableLanguages,
|
|
getCurrentLanguage: () => currentLang
|
|
};
|
|
})();
|
|
|
|
// Make i18n globally available
|
|
window.i18n = i18n;
|