Added new API comments (part 1)

This commit is contained in:
JasperAtSchool
2025-01-09 17:48:50 +01:00
parent abd672dd3b
commit 0615235780
10 changed files with 63 additions and 33 deletions
+28 -2
View File
@@ -6,17 +6,36 @@ import nodepath from "path"
import { ODDebugger } from "./console"
import fs from "fs"
/**## ODLanguageMetadata `interface`
* This interface contains all metadata available in the language files.
*/
export interface ODLanguageMetadata {
/**The version of Open Ticket this translation is made for. */
otversion:string,
/**The name of the language in english (with capital letter). */
language:string,
/**A list of translators (discord/github username) who've contributed to this language. */
translators:string[],
/**The last date that this translation has been modified (format: DD/MM/YYYY) */
lastedited:string,
/**When `true`, the translator made use of some sort of automation while creating the translation. (e.g. ChatGPT, Google Translate, DeepL, ...) */
automated:boolean
}
/**## ODLanguageManager `class`
* This is an open ticket language manager.
*
* It manages all languages in the bot and manages translation for you!
* Get a translation via the `getTranslation()` or `getTranslationWithParams()` methods.
*
* Add new languages using the `ODlanguage` class in your plugin!
*/
export class ODLanguageManager extends ODManager<ODLanguage> {
/**The currently selected language. */
current: ODLanguage|null = null
/**The currently selected backup language. (used when translation missing in current language) */
backup: ODLanguage|null = null
/**An alias to Open Ticket debugger. */
#debug: ODDebugger
constructor(debug:ODDebugger, presets:boolean){
@@ -27,6 +46,7 @@ export class ODLanguageManager extends ODManager<ODLanguage> {
this.#debug = debug
}
/**Set the current language by providing the ID of a language which is registered in this manager. */
setCurrentLanguage(id:ODValidId){
this.current = this.get(id)
const languageId = this.current?.id.value ?? "<unknown-id>"
@@ -36,9 +56,11 @@ export class ODLanguageManager extends ODManager<ODLanguage> {
{key:"automated",value:languageAutomated},
])
}
/**Get the current language (same as `this.current`) */
getCurrentLanguage(){
return (this.current) ? this.current : null
}
/**Set the backup language by providing the ID of a language which is registered in this manager. */
setBackupLanguage(id:ODValidId){
this.backup = this.get(id)
const languageId = this.backup?.id.value ?? "<unknown-id>"
@@ -48,16 +70,20 @@ export class ODLanguageManager extends ODManager<ODLanguage> {
{key:"automated",value:languageAutomated},
])
}
/**Get the backup language (same as `this.backup`) */
getBackupLanguage(){
return (this.backup) ? this.backup : null
}
/**Get the metadata of the current/backup language. */
getLanguageMetadata(frombackup?:boolean): ODLanguageMetadata|null {
if (frombackup) return (this.backup) ? this.backup.metadata : null
return (this.current) ? this.current.metadata : null
}
/**Get the ID (string) of the current language. (Not backup language) */
getCurrentLanguageId(){
return (this.current) ? this.current.id.value : ""
}
/**Get a translation string by JSON location. (e.g. `"checker.system.typeError"`) */
getTranslation(id:string): string|null {
if (!this.current) return this.#getBackupTranslation(id)
@@ -75,7 +101,7 @@ export class ODLanguageManager extends ODManager<ODLanguage> {
if (typeof result == "string") return result
else return this.#getBackupTranslation(id)
}
/**Get a backup translation string by JSON location. (system only) */
#getBackupTranslation(id:string): string|null {
if (!this.backup) return null
@@ -93,7 +119,7 @@ export class ODLanguageManager extends ODManager<ODLanguage> {
if (typeof result == "string") return result
else return null
}
/**Get a backup translation string by JSON location and replace `{0}`,`{1}`,`{2}`,... with the provided parameters. */
getTranslationWithParams(id:string, params:string[]): string|null {
let translation = this.getTranslation(id)
if (!translation) return translation