langloader.js placeholder support

This commit is contained in:
Kamesuta 2023-09-02 08:39:01 +09:00
parent 10a75b9350
commit 10742f7786
3 changed files with 14 additions and 8 deletions

View File

@ -7,19 +7,25 @@ exports.loadLanguage = function(id){
lang = JSON.parse(fs.readFileSync(path.join(__dirname, '..', 'lang', `${id}.json`))) || {} lang = JSON.parse(fs.readFileSync(path.join(__dirname, '..', 'lang', `${id}.json`))) || {}
} }
exports.query = function(id){ exports.query = function(id, placeHolders){
let query = id.split('.') let query = id.split('.')
let res = lang let res = lang
for(let q of query){ for(let q of query){
res = res[q] res = res[q]
} }
return res === lang ? {} : res let text = res === lang ? '' : res
if (placeHolders) {
Object.entries(placeHolders).forEach(([key, value]) => {
text = text.replace(`{${key}}`, value)
})
}
return text
} }
exports.queryJS = function(id){ exports.queryJS = function(id, placeHolders){
return exports.query(`js.${id}`) return exports.query(`js.${id}`, placeHolders)
} }
exports.queryEJS = function(id){ exports.queryEJS = function(id, placeHolders){
return exports.query(`ejs.${id}`) return exports.query(`ejs.${id}`, placeHolders)
} }

View File

@ -122,7 +122,7 @@
"javaExecSelButtonText": "Choose File", "javaExecSelButtonText": "Choose File",
"javaExecDesc": "The Java executable is validated before game launch.", "javaExecDesc": "The Java executable is validated before game launch.",
"javaReqDesc": "Requires Java 8 x64.", "javaReqDesc": "Requires Java 8 x64.",
"javaPathDesc": "The path should end with <strong>bin<%= process.platform === 'win32' ? '\\\\javaw.exe' : '/java' %></strong>.", "javaPathDesc": "The path should end with <strong>{pathSuffix}</strong>.",
"jvmOptsTitle": "Additional JVM Options", "jvmOptsTitle": "Additional JVM Options",
"jvmOptsDesc": "Options to be provided to the JVM at runtime. <em>-Xms</em> and <em>-Xmx</em> should not be included.", "jvmOptsDesc": "Options to be provided to the JVM at runtime. <em>-Xms</em> and <em>-Xmx</em> should not be included.",
"jvmOptsLink": "https://docs.oracle.com/javase/8/docs/technotes/tools/<%= process.platform === 'win32' ? 'windows' : 'unix' %>/java.html", "jvmOptsLink": "https://docs.oracle.com/javase/8/docs/technotes/tools/<%= process.platform === 'win32' ? 'windows' : 'unix' %>/java.html",

View File

@ -245,7 +245,7 @@
<button class="settingsFileSelButton" id="settingsJavaExecSel" dialogTitle="<%- lang('settings.javaExecSelDialogTitle') %>" dialogDirectory="false"><%- lang('settings.javaExecSelButtonText') %></button> <button class="settingsFileSelButton" id="settingsJavaExecSel" dialogTitle="<%- lang('settings.javaExecSelDialogTitle') %>" dialogDirectory="false"><%- lang('settings.javaExecSelButtonText') %></button>
</div> </div>
</div> </div>
<div class="settingsFileSelDesc"><%- lang('settings.javaExecDesc') %> <strong id="settingsJavaReqDesc"><%- lang('settings.javaReqDesc') %></strong><br><%- evalEjs(lang('settings.javaPathDesc')) %></div> <div class="settingsFileSelDesc"><%- lang('settings.javaExecDesc') %> <strong id="settingsJavaReqDesc"><%- lang('settings.javaReqDesc') %></strong><br><%- lang('settings.javaPathDesc', {'pathSuffix': `bin${process.platform === 'win32' ? '\\\\javaw.exe' : '/java'}`}) %></div>
</div> </div>
<div id="settingsJVMOptsContainer"> <div id="settingsJVMOptsContainer">
<div id="settingsJVMOptsTitle"><%- lang('settings.jvmOptsTitle') %></div> <div id="settingsJVMOptsTitle"><%- lang('settings.jvmOptsTitle') %></div>