Skip to content
This repository has been archived by the owner on Jun 25, 2024. It is now read-only.

Commit

Permalink
Missed a few files.
Browse files Browse the repository at this point in the history
  • Loading branch information
jtsage committed May 27, 2021
1 parent 9151ba9 commit 03af804
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 58 deletions.
72 changes: 36 additions & 36 deletions lib/translate.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,28 @@ const path = require('path')
module.exports.getSystemLocale = function () {
const systemLocale = Intl.DateTimeFormat().resolvedOptions().locale
switch ( systemLocale ) {
case "pt-BR" :
return "br"
case "zh-CHT":
case "zh-Hant":
case "zh-HK":
case "zh-MO":
case "zh-TW":
return "ct"
case "zh":
case "zh-CHS":
case "zh-Hans":
case "zh-CN":
case "zh-SG":
return "cs"
case "cs":
return "cz"
case "ja":
return "jp"
case "ko":
return "kr"
case 'pt-BR' :
return 'br'
case 'zh-CHT':
case 'zh-Hant':
case 'zh-HK':
case 'zh-MO':
case 'zh-TW':
return 'ct'
case 'zh':
case 'zh-CHS':
case 'zh-Hans':
case 'zh-CN':
case 'zh-SG':
return 'cs'
case 'cs':
return 'cz'
case 'ja':
return 'jp'
case 'ko':
return 'kr'
default :
return systemLocale.slice(0,2)
return systemLocale.slice(0, 2)
}
}
module.exports.translator = class translator {
Expand All @@ -49,34 +49,34 @@ module.exports.translator = class translator {
#langPromise = null
mcVersion = null

constructor(locale = "en") {
constructor(locale = 'en') {
this.#currentLocale = locale

this.#langPromise = this.loadLanguages()
}

deferCurrentLocale = () => { return this.#currentLocale }
get currentLocale() { return this.#currentLocale }
set currentLocale(value) {
set currentLocale(value) {
if ( value in this.#translatorStrings ) {
this.#currentLocale = value
}
}

async loadLanguages() {

const langJSON = fs.readdirSync(path.join(__dirname, "..", "translations"))
const langJSON = fs.readdirSync(path.join(__dirname, '..', 'translations'))

langJSON.forEach( (thisFile) => {
if ( path.extname(thisFile) === ".json" ) {
const thisLang = JSON.parse(fs.readFileSync(path.join(__dirname, "..", "translations", thisFile)))
langJSON.forEach( (thisFile) => {
if ( path.extname(thisFile) === '.json' ) {
const thisLang = JSON.parse(fs.readFileSync(path.join(__dirname, '..', 'translations', thisFile)))
this.#translatorStrings[thisLang.language_code] = thisLang
}
})
}

async getLangList() {
return await this.#langPromise.then(() => {
return this.#langPromise.then(() => {
const returnArray = []
Object.keys(this.#translatorStrings).forEach((key) => {
returnArray.push([key, this.#translatorStrings[key].language_name])
Expand All @@ -86,20 +86,20 @@ module.exports.translator = class translator {
}

async stringLookup(stringID) {
return await this.#langPromise.then(() => {
return this.#langPromise.then(() => {
if ( stringID === null ) { return null }

stringID = stringID.toLowerCase()
const lcStringID = stringID.toLowerCase()

if ( stringID === "mc_ver_string" ) { return this.mcVersion }
if ( lcStringID === 'mc_ver_string' ) { return this.mcVersion }

if ( this.#currentLocale in this.#translatorStrings && stringID in this.#translatorStrings[this.#currentLocale] ) {
return this.#translatorStrings[this.#currentLocale][stringID]
if ( this.#currentLocale in this.#translatorStrings && lcStringID in this.#translatorStrings[this.#currentLocale] ) {
return this.#translatorStrings[this.#currentLocale][lcStringID]
}
if ( stringID in this.#translatorStrings.en ) {
return this.#translatorStrings.en[stringID]
if ( lcStringID in this.#translatorStrings.en ) {
return this.#translatorStrings.en[lcStringID]
}
return stringID
return lcStringID
})
}
}
45 changes: 23 additions & 22 deletions renderer/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,57 +10,57 @@
const byId = function( id ) { return document.getElementById( id ) }

function toggleHideFolderOnlyError() {
const folderOnly = byId("broken_list").querySelectorAll(".just-folder-error")
const status = byId("zip_folder_switch").checked
const folderOnly = byId('broken_list').querySelectorAll('.just-folder-error')
const status = byId('zip_folder_switch').checked

folderOnly.forEach((thisBroken) => {
if ( status ) {
thisBroken.classList.add("d-none")
thisBroken.classList.add('d-none')
} else {
thisBroken.classList.remove("d-none")
thisBroken.classList.remove('d-none')
}
})
}

function toggleExploreColumns () {
const columns = [
"mod_name",
"mod_title",
"mod_version",
"mod_size",
"mod_is_active",
"mod_active_games",
"mod_is_used",
"mod_used_games",
"mod_full_path",
"mod_has_scripts",
'mod_name',
'mod_title',
'mod_version',
'mod_size',
'mod_is_active',
'mod_active_games',
'mod_is_used',
'mod_used_games',
'mod_full_path',
'mod_has_scripts',
]
columns.forEach((thisCol) => {
const theseItems = byId("table_explore_parent").querySelectorAll(".col_"+thisCol)
const colStatus = byId("col_"+thisCol+"_switch").checked
const theseItems = byId('table_explore_parent').querySelectorAll(`.col_${thisCol}`)
const colStatus = byId(`col_${thisCol}_switch`).checked

theseItems.forEach((thisRow) => {
if ( colStatus === true ) {
thisRow.classList.remove("d-none")
thisRow.classList.remove('d-none')
} else {
thisRow.classList.add("d-none")
thisRow.classList.add('d-none')
}
})
})
}

function searchExploreClear() {
byId("explore-search").value = ""
byId('explore-search').value = ''
searchExploreTable()
}
function searchExploreTable() {
const exploreTable = byId("table_explore").querySelectorAll("tbody>tr")
const searchTerm = byId("explore-search").value.toLowerCase()
const exploreTable = byId('table_explore').querySelectorAll('tbody>tr')
const searchTerm = byId('explore-search').value.toLowerCase()

// BUG: wont-fix - zebra stripes get screwed up when searching. We'd have to remove them from the table.

exploreTable.forEach((thisTD) => {
const testString = (thisTD.childNodes[0].innerText + " " + thisTD.childNodes[1].innerText).toLowerCase()
const testString = (thisTD.childNodes[0].innerText + thisTD.childNodes[1].innerText).toLowerCase()

if ( testString.indexOf(searchTerm) > -1 ) {
thisTD.classList.remove('d-none')
Expand All @@ -73,4 +73,5 @@ function searchExploreTable() {
window.addEventListener('DOMContentLoaded', () => {
toggleExploreColumns()
toggleHideFolderOnlyError()
searchExploreClear()
})

0 comments on commit 03af804

Please sign in to comment.