language selector and localization fixes

This commit is contained in:
SpikeHD 2022-04-22 22:10:09 -07:00
parent f5506a4c85
commit 7ddc39ad2c
5 changed files with 45 additions and 2 deletions

View File

@ -1,4 +1,5 @@
{
"fullLangName": "English",
"appName": "GrassClipper",
"playOfficial": "Play Official",

View File

@ -62,6 +62,16 @@
Enable to server launcher tile for launcher a local Grasscutter instance.
</span>
</div>
<div class="settingsRow">
<div class="settingSection">
<span class="settingLabel", id="languageTitle">Language</span>
<select id="languageSelect" onchange="handleLanguageChange(this)">
</select>
</div>
<span class="settingSubtitle" id="languageSubtitle">
Select your language!
</span>
</div>
</div>
</div>
<div id="controlBar">

View File

@ -410,6 +410,9 @@ async function openSettings() {
killSwitch.checked = config.enableKillswitch
serverLaunch.checked = config.serverLaunchPanel
// Load languages
getLanguages()
// Check for updates
//checkForUpdatesAndShow()
}
@ -492,6 +495,35 @@ async function toggleServerLaunchSection() {
Neutralino.storage.setData('config', JSON.stringify(config))
}
async function getLanguages() {
const languageFiles = (await filesystem.readDirectory(`${NL_CWD}/languages`)).filter(file => file.entry.endsWith('.json'))
// Load all languages as options
for (const file of languageFiles) {
const fullLanguageName = JSON.parse(await filesystem.readFile(`${NL_CWD}/languages/${file.entry}`)).fullLangName
const lang = file.entry.split('.json')[0]
const option = document.createElement('option')
option.value = lang
option.innerHTML = fullLanguageName
document.querySelector('#languageSelect').appendChild(option)
}
}
async function handleLanguageChange(elm) {
const list = elm
const config = await getCfg()
// Set language in config
config.language = list.value
Neutralino.storage.setData('config', JSON.stringify(config))
// Force refresh of application, no need for restart!
window.location.reload()
}
/**
* Set the game folder by opening a folder picker
*/

View File

@ -15,7 +15,7 @@ async function doTranslation() {
const localization = await filesystem.readFile(`${NL_CWD}/languages/${config.language}.json`)
localeObj = JSON.parse(localization)
const set = (id, localeString) => document.getElementById(id).innerHTML = localeString
const set = (id, localeString) => document.getElementById(id).innerHTML = localeString || 'UNKNOWN'
// Begin filling in values
set('titleSection', localeObj.appName)

View File

@ -51,7 +51,7 @@ body {
#settingsPanel {
width: 35%;
height: 60%;
height: 70%;
}
#fullSettingsTitle {