fix english localization and functionally replace text

This commit is contained in:
SpikeHD 2022-04-22 21:57:02 -07:00
parent 434227d9d5
commit f5506a4c85
4 changed files with 104 additions and 34 deletions

View File

@ -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.",

View File

@ -6,18 +6,15 @@
<script src="js/windowDrag.js"></script>
<script src="js/hoverEvt.js"></script>
<script src="js/index.js"></script>
<script src="js/translation.js"></script>
</head>
<body>
<div id="firstTimeNotice" style="display: none">
<span>
<span class="boldTitle">Looks like this is your first time opening GrassClipper!<br/></span>
First of all, welcome, happy to see you here! :)<br/><br/>
Would you like to run the proxy installer?<br/>
(required to connect to private servers)
</span>
<div id="firstTimeBtns">
<button class="playBtn" id="firstTimeBtn" onclick="runInstallScript()">Install</button>
<button class="altBtn" id="firstTimeBtn" onclick="closeFirstTimePopup()">No thanks</button>
<button class="playBtn" id="firstTimeInstallBtn" onclick="runInstallScript()">Install</button>
<button class="altBtn" id="firstTimeDenyBtn" onclick="closeFirstTimePopup()">No thanks</button>
</div>
</div>
<div id="settingsPanel" style="display: none;">
@ -26,30 +23,30 @@
<img src="icons/close.svg" onclick="closeSettings()" />
</div>
<div id="settingsPanelInner">
<div class="settingTitle">
<div class="settingTitle", id="scriptsTitle">
<span>Scripts</span>
</div>
<div class="settingsRow">
<div class="settingSection">
<span class="settingLabel">Kill Switch</span>
<span class="settingLabel" id="killswitchTitle">Kill Switch</span>
<input type="checkbox" id="killswitchOption" onchange="toggleKillSwitch()" />
</div>
<span class="settingSubtitle">
<span class="settingSubtitle" id="killswitchSubtitle">
Only for those very paranoid about bans. Kills the game process *and your internet* if something happens to the proxy.
</span>
</div>
<div class="settingsRow">
<div class="settingSection">
<span class="settingLabel">Install Proxy Server</span>
<button class="smolBtn" onclick="runInstallScript()">Install</button>
<span class="settingLabel" id="proxyTitle">Install Proxy Server</span>
<button class="smolBtn" onclick="runInstallScript()" id="proxyInstall">Install</button>
</div>
<span class="settingSubtitle">
<span class="settingSubtitle" id="proxySubtitle">
Install the proxy server via the install script.
</span>
</div>
<div class="settingsRow">
<div class="settingSection">
<span class="settingLabel">Update</span>
<span class="settingLabel" id="updateTitle">Update</span>
<button class="smolBtn disabled" onclick="updateResources()" id="updateBtn" disabled>Update</button>
</div>
<span class="settingSubtitle" id="updateSubtitle">
@ -58,7 +55,7 @@
</div>
<div class="settingsRow">
<div class="settingSection">
<span class="settingLabel">Enable Server Launcher</span>
<span class="settingLabel", id="serverLaunchTitle">Enable Server Launcher</span>
<input type="checkbox" id="serverLaunchOption" onchange="toggleServerLaunchSection()" />
</div>
<span class="settingSubtitle" id="serverSubtitle">
@ -105,11 +102,11 @@
<div id="bottomBar">
<div class="bottomSection">
<div>
<button class="smolBtn" onclick="setGenshinImpactFolder()">Set "Genshin Impact Game" folder</button>
<button class="smolBtn" onclick="setGenshinImpactFolder()" id="genshinFolderSet">Set "Genshin Impact Game" folder</button>
<span id="genshinPath" style="margin-top: 4px;"></span>
</div>
<div style="display: none;">
<button class="smolBtn" onclick="setGrassCutterFolder()">Set "GrassCutter" .jar file</button>
<button class="smolBtn" onclick="setGrassCutterFolder()" id="grasscutterFileSet">Set "GrassCutter" .jar file</button>
<span id="serverPath" style="margin-top: 4px;"></span>
</div>
</div>

View File

@ -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'] }
]

View File

@ -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 + '<br>'
introSpan.innerHTML += localeObj.introSen3 + '<br>'
introSpan.innerHTML += localeObj.introSen4 + '<br>'
set('firstTimeInstallBtn', localeObj.proxyInstallBtn)
set('firstTimeDenyBtn', localeObj.proxyInstallDeny)
}