created lang file
This commit is contained in:
47
dist/lang.js
vendored
Normal file
47
dist/lang.js
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Lang = void 0;
|
||||
const LANG = {
|
||||
en: {
|
||||
discord: {
|
||||
error: {
|
||||
noActiveQueue: 'There is not an active queue in this channel, type `/open` to create one'
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
var Lang;
|
||||
(function (Lang) {
|
||||
var LANGID = 'en';
|
||||
if (!(LANGID in LANG))
|
||||
throw 'language id does not exist';
|
||||
function setLang(langid) {
|
||||
if (langid in LANG)
|
||||
LANGID = langid;
|
||||
else
|
||||
throw 'language id does not exist';
|
||||
}
|
||||
Lang.setLang = setLang;
|
||||
/**
|
||||
* reads language json
|
||||
* @param id ex: discord.error.noActiveQueue
|
||||
* @returns language value, defaults to `id` parameter
|
||||
*/
|
||||
function get(id) {
|
||||
let keySpl = id.split('.').map(k => k.trim()).filter(k => k);
|
||||
let finding = LANG[LANGID];
|
||||
for (let key of keySpl) {
|
||||
if (key in finding) {
|
||||
let found = finding[key];
|
||||
if (typeof found === 'string')
|
||||
return found;
|
||||
finding = found;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
return id;
|
||||
}
|
||||
Lang.get = get;
|
||||
})(Lang = exports.Lang || (exports.Lang = {}));
|
||||
debugger;
|
||||
57
src/lang.ts
Normal file
57
src/lang.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
type LangObj = { [keys:string]: LangObj | string }
|
||||
type LangObjWhold = { [langid:string]: LangObj }
|
||||
|
||||
const LANG: LangObjWhold = {
|
||||
en: {
|
||||
discord: {
|
||||
error: {
|
||||
noActiveQueue: 'There is not an active queue in this channel, type `/open` to create one'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export namespace Lang {
|
||||
|
||||
var LANGID = 'en';
|
||||
if (!(LANGID in LANG))
|
||||
throw 'language id does not exist';
|
||||
|
||||
export function setLang(langid: string) {
|
||||
if (langid in LANG)
|
||||
LANGID = langid;
|
||||
else
|
||||
throw 'language id does not exist';
|
||||
}
|
||||
|
||||
/**
|
||||
* reads language json
|
||||
* @param id ex: discord.error.noActiveQueue
|
||||
* @returns language value, defaults to `id` parameter
|
||||
*/
|
||||
export function get(id: string): string {//discord.error.noActiveQueue
|
||||
|
||||
let keySpl = id.split('.').map(k => k.trim()).filter(k => k);
|
||||
|
||||
let finding = LANG[LANGID];
|
||||
|
||||
for (let key of keySpl) {
|
||||
|
||||
if (key in finding) {
|
||||
|
||||
let found = finding[key];
|
||||
|
||||
if (typeof found === 'string')
|
||||
return found;
|
||||
|
||||
finding = found;
|
||||
|
||||
} else
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user