diff --git a/languages/en.json b/languages/en.json index e09f49b..9dc3e9e 100644 --- a/languages/en.json +++ b/languages/en.json @@ -1,8 +1,8 @@ { "appName": "GrassClipper", - "officialPlay": "Play Official", - "privatePlay": "Play Private", + "playOfficial": "Play Official", + "playPrivate": "Play Private", "launchLocalServer": "Launch Local Server", "genshinFolderSet": "Set \"Genshin Impact Game\" folder", @@ -13,10 +13,13 @@ "noFavorites": "No favorites set", "settingsTitle": "Settings", + "scriptsSectionTitle": "Scripts", "killswitchOption": "Kill Switch", "killswitchSubtitle": "Only for those very paranoid about bans. Kills the game process *and your internet* if something happens to the proxy.", - "installProxyOption": "Install the proxy server via the install script", - "updateOption": "Auto updating is temporarily disabled. Check GitHub for the newest releease.", + "proxyOption": "Proxy", + "proxySubtitle": "Install the proxy server via the install script", + "updateOption": "Update", + "updateSubtitle": "Auto updating is temporarily disabled. Check GitHub for the newest releease.", "enableServerLauncherOption": "Enable Server Launcher", "enableServerLauncherSubtitle": "Enable to server launcher tile for launcher a local Grasscutter instance.", diff --git a/resources/index.html b/resources/index.html index e9637a5..9658db2 100644 --- a/resources/index.html +++ b/resources/index.html @@ -6,18 +6,15 @@ +
-
+
Scripts
- Kill Switch + Kill Switch
- + Only for those very paranoid about bans. Kills the game process *and your internet* if something happens to the proxy.
- Install Proxy Server - + Install Proxy Server +
- + Install the proxy server via the install script.
- Update + Update
@@ -58,7 +55,7 @@
- Enable Server Launcher + Enable Server Launcher
@@ -105,11 +102,11 @@
- +
- +
diff --git a/resources/js/index.js b/resources/js/index.js index 20f925b..00f9ccf 100644 --- a/resources/js/index.js +++ b/resources/js/index.js @@ -1,5 +1,6 @@ Neutralino.init(); +let localeObj; const filesystem = Neutralino.filesystem /** @@ -17,14 +18,6 @@ document.addEventListener('DOMContentLoaded', async () => { const config = await getCfg() const ipArr = await getFavIps() - if (!config.genshinImpactFolder) { - handleGenshinFolderNotSet() - } - - if (!config.serverFolder) { - handleServerNotSet() - } - if (config.serverLaunchPanel) { displayServerLaunchSection() } @@ -75,6 +68,17 @@ document.addEventListener('DOMContentLoaded', async () => { } } }); + + // Ensure we do the translation at the very end, after everything else has loaded + await doTranslation() + + if (!config.genshinImpactFolder) { + handleGenshinFolderNotSet() + } + + if (!config.serverFolder) { + handleServerNotSet() + } }) /** @@ -104,7 +108,8 @@ async function getCfg() { serverFolder: '', lastConnect: '', enableKillswitch: false, - serverLaunchPanel: false + serverLaunchPanel: false, + language: 'en' } const cfgStr = await Neutralino.storage.getData('config').catch(e => { // The data isn't set, so this is our first time opening @@ -151,7 +156,7 @@ async function enableButtons() { */ async function handleGenshinFolderNotSet() { // Set buttons to greyed out and disable - document.querySelector('#genshinPath').innerHTML = 'Not set' + document.querySelector('#genshinPath').innerHTML = localeObj.folderNotSet // Set official server background to default document.querySelector('#firstPanel').style.backgroundImage = `url("../bg/private/default.png")` @@ -170,7 +175,7 @@ async function handleGenshinFolderNotSet() { async function handleServerNotSet() { // Set buttons to greyed out and disable - document.querySelector('#serverPath').innerHTML = 'Not set' + document.querySelector('#serverPath').innerHTML = localeObj.folderNotSet // Set official server background to default // document.querySelector('#firstPanel').style.backgroundImage = `url("../bg/private/default.png")` @@ -339,7 +344,7 @@ async function handleFavoriteList() { document.createElement('li') ) - listItem.innerHTML = 'No favorites set' + listItem.innerHTML = localeObj.noFavorites } for (const ip of ipArr) { @@ -491,7 +496,7 @@ async function toggleServerLaunchSection() { * Set the game folder by opening a folder picker */ async function setGenshinImpactFolder() { - const folder = await Neutralino.os.showFolderDialog('Select Genshin Impact Game folder') + const folder = await Neutralino.os.showFolderDialog(localeObj.genshinFolderDialog) // Set the folder in our configuration const config = await getCfg() @@ -516,7 +521,7 @@ async function setGenshinImpactFolder() { } async function setGrassCutterFolder() { - const folder = await Neutralino.os.showOpenDialog('Select GrassCutter server jar', { + const folder = await Neutralino.os.showOpenDialog(localeObj.grasscutterFileDialog, { filters: [ { name: 'Jar files', extensions: ['jar'] } ] diff --git a/resources/js/translation.js b/resources/js/translation.js new file mode 100644 index 0000000..b02bf8f --- /dev/null +++ b/resources/js/translation.js @@ -0,0 +1,65 @@ +async function doTranslation() { + const config = await getCfg() + + // See if the localization file exists + const localizations = await filesystem.readDirectory(`${NL_CWD}/languages`) + + // Use english if the selected file does not exist + const selectedLanguage = localizations.find(f => f.entry === `${config.language}.json`) + + // Use english if the selected file does not exist + if (!selectedLanguage) { + config.language = 'en' + } + + const localization = await filesystem.readFile(`${NL_CWD}/languages/${config.language}.json`) + localeObj = JSON.parse(localization) + + const set = (id, localeString) => document.getElementById(id).innerHTML = localeString + + // Begin filling in values + set('titleSection', localeObj.appName) + + // Play buttons + set('playOfficial', localeObj.playOfficial) + set('playPrivate', localeObj.playPrivate) + set('serverLaunch', localeObj.launchLocalServer) + + // File select buttons + set('genshinFolderSet', localeObj.genshinFolderSet) + set('grasscutterFileSet', localeObj.grasscutterFileSet) + + // Private options + set('ip', localeObj.ipPlaceholder) + + // Settings + set('fullSettingsTitle', localeObj.settingsTitle) + set('scriptsTitle', localeObj.scriptsSectionTitle) + set('killswitchTitle', localeObj.killswitchOption) + set('killswitchSubtitle', localeObj.killswitchSubtitle) + set('proxyTitle', localeObj.proxyOption) + set('proxyInstall', localeObj.proxyInstallBtn) + set('proxySubtitle', localeObj.proxySubtitle) + set('updateBtn', localeObj.updateOption) + set('updateTitle', localeObj.updateOption) + set('updateSubtitle', localeObj.updateSubtitle) + set('serverLaunchTitle', localeObj.enableServerLauncherOption) + set('serverSubtitle', localeObj.enableServerLauncherSubtitle) + + // Intro popup + const popup = document.getElementById('firstTimeNotice') + const introSpan = popup.querySelector('span') + const boldIntroSpan = document.createElement('span') + + boldIntroSpan.innerHTML = localeObj.introSen1 + '\n' + boldIntroSpan.classList.add('boldTitle') + + introSpan.appendChild(boldIntroSpan) + + introSpan.innerHTML += localeObj.introSen2 + '
' + introSpan.innerHTML += localeObj.introSen3 + '
' + introSpan.innerHTML += localeObj.introSen4 + '
' + + set('firstTimeInstallBtn', localeObj.proxyInstallBtn) + set('firstTimeDenyBtn', localeObj.proxyInstallDeny) +} \ No newline at end of file