Compare commits

...

9 Commits

Author SHA1 Message Date
Lio Young eb4dea0bf6 update 2021-07-09 16:23:22 +02:00
Lio Young 8d7df1812e remove deps since it's built into thaldrin 2021-07-09 15:43:13 +02:00
Lio Young 4ee62f5786 rewrite lingua entirely lmao 2021-07-09 15:35:13 +02:00
Lio Young c7b9a90931 Merge branch 'master' of github.com:thaldrin/lingua 2021-07-09 12:53:41 +02:00
Lio Young 13c76c4dd2 delete LanguageFiles.yml workflow, moved to GitLocalize 2021-07-09 12:53:24 +02:00
Lio Young edd7049e60
Merge pull request #1 from thaldrin/gitlocalize-16349
Start with German Translation
2021-07-09 03:52:13 -07:00
Lio Young 5b76b77efc Translate de.yml via GitLocalize 2021-07-09 10:51:52 +00:00
Lio Young d80faeb526 rename en_US to en.yml 2021-07-09 12:50:25 +02:00
Lio Young dc7c00d505 rewrite everything with yaml 2021-07-09 11:46:45 +02:00
9 changed files with 514 additions and 149 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
node_modules

View File

@ -1,3 +1,5 @@
# Lingua
Language Module for [Thaldrin](https://thaldr.in)
You can help translate Thaldrin on [GitLocalize](https://gitlocalize.com/repo/6258)

View File

@ -1,7 +1,22 @@
import en_US from "./src/en_US";
import de_DE from "./src/de_DE";
import yaml from 'js-yaml'
import { readdirSync as readdir, readFileSync as readfile } from "fs";
import path from "path";
import { Language } from './src/types';
export default class Lingua {
#path = './langs'
#langs?: void | string[]
#data?: Language[] = []
export default {
en_US,
de_DE
}
constructor() {
this.#langs = readdir(path.join(__dirname, this.#path)).filter(f => f.endsWith('.yml')) ?? []
// @ts-ignores
this.#langs.forEach(file => this.#data.push(yaml.load(readfile(path.join(__dirname, this.#path, file)))))
}
// @ts-ignore
get(lang: string): Language {
// @ts-ignore
let result: Language = this.#data.find(d => d.meta.locale === lang)
return result
}
}

78
langs/en.yml Normal file
View File

@ -0,0 +1,78 @@
meta:
name: ":flag_us: English (US)"
locale: en
translators:
- 318044130796109825 # Lio
missing:
tags:
name: Not enough tags
desc: You need to provide a few Tags for me to search for.
values:
prefix: No Prefix given
country: No country code was given
setting: No Settings value was given
title: "Missing title. Separate the title and description with a pipe (`|`)."
mention: You need to mention another User
error:
nsfw: This Channel is not marked as NSFW, please mark it as such and rerun this Command
permissions: You need `PERMISSIONS` Permissions to run this Command
error: COMMAND encountered an error
cooldown:
name: COMMAND is on COOLDOWN
desc: "COMMAND has a cooldown of COOLDOWN\nWait TIME before trying to run it again"
developer: This Command can only be run by Devs
categories:
info:
name: Info
desc: Information about the Bot, among other things.
nsfw:
name: ":underage: NSFW"
desc: Horny stuff, obviously.
animals:
name: Animals
desc: Cute Pictures of Animals to brighten your Day
misc:
name: Misc
desc: Miscellaneous Commands
fun:
name: Fun
desc: Fun Commands
developer:
name: Developer
desc: Developer only commands, duh.
locale:
language: Language
translators: AMOUNT Translator(s)
title: LANGUAGE by TRANSLATOR
amount: "BOT is available in AMOUNT Languages, you can easily change BOT's current Language by running `PREFIX locale set <country_code>`\n\n[Translations](https://t8.pm/lingua) are provided by the Community "
updated: Successfully updated SETTING
unsupported: BOT does not support VALUE at this time.
misc:
invite: You can invite BOT using this Link
roll: ":game_die: Rolling AMOUNT DICE"
sent: VALUE sent.
enabled: Enabled
disabled: Disabled
user:
info: Info on User
status: "Status | STATE"
roles: "Roles [AMOUNT]"
username: Username
id: User ID
created: Created
joined: Joined
states:
online: Online
dnd: Do not Disturb
idle: Idle
offline: Offline
rp:
client: Don't ACTION me! ACTION someone else.
self: Don't you want to ACTION someone other than yourself?

View File

@ -1,4 +1,4 @@
// Base File for translations
import Lingua from ".";
let lang = new Lingua()
// TODO: Enter all strings here
console.log(lang.get("en").missing.mention)

View File

@ -1,62 +0,0 @@
export default {
META: {
name: ":flag_de: Deutsch (Deutschland)",
locale: "de_DE",
tranlators: [
"318044130796109825" // Lio
]
},
CHANNEL_NOT_NSFW: "Dieser Channel ist nicht als NSFW markiert, schalte diese Einstellung ein und probier es nochmal.",
INSUFFICIENT_PERMISSIONS: `You need \`PERMISSIONS\` Permissions to run this Command `,
ON_COOLDOWN: `\`COMMAND\` ist grade auf Cooldown.`,
ON_COOLDOWN_DESCRIPTION: `\`COMMAND\` hat einen Cooldown von \`COOLDOWN\` \n Warte \`TIME\` bevor du es noch einmal versuchst.`,
ON_ERROR: `\`COMMAND\` ist ein Fehler unterlaufen.`,
MISSING: {
NOT_ENOUGH_TAGS: `Nicht genug Tags`,
NOT_ENOUGH_TAGS_DESC: "Du musst mir Tags zum suchen geben.",
RP_REQUIRE_MENTION: `Du musst einen anderen Benutzer erwähnen.`,
MISSING_TITLE: `Fehlender Titel. Separiere den Titel und die Beschreibung mit einer "Pipe" (\`|\`)`,
VALUE: {
PREFIX: "Es wurde kein Prefix gegeben.",
COUNTRY: "Kein Länder Code wurde gegeben"
}
},
NOT_ENOUGH_TAGS: `Nicht genug Tags`,
NOT_ENOUGH_TAGS_DESC: "Du musst mir Tags zum suchen geben.",
RP_REQUIRE_MENTION: `Du musst einen anderen Benutzer erwähnen.`,
// TODO: change the way the stuff below works or just remove it entirely
RP_SELF: `Don't you want to ACTION someone other than yourself?`,
RP_ME: `Don't ACTION me! ACTION someone else.`,
MISSING_TITLE: `Fehlender Titel. Separiere den Titel und die Beschreibung mit einer "Pipe" (\`|\`).`,
SUGGESTION_SENT: "Vorschlag abgeschickt.",
INVITE_STRING: "Du kannst BOT mit diesem Link einladen",
ROLL: ":game_die: Werfe AMOUNT DICE Würfel...",
CATEGORIES: {
INFO: { name: "Info", desc: "" },
NSFW: { name: ":underage: NSFW", desc: "Horny Stuff, natürlich." },
ANIMALS: { name: "Tiere", desc: "Süße Tierbilder um dir den Tag zu verschönern!" },
MISC: { name: "Misc", desc: "Miscellaneous Commands" },
FUN: { name: "Spaß", desc: "" },
DEVELOPER: { name: "Entwickler", desc: "Developer only Commands, duh" },
},
DEVELOPER_ONLY: "Dieser Befehl ist nur für Entwickler.",
MISC: {
ENABLED: "An",
DISABLED: "Aus",
},
LOCALE: {
LANGUAGE: "Sprache",
CONTRIBUTORS: "AMOUNT Übersetzer",
TITLE: "LANGUAGE von TRANSLATOR",
COMMAND_DESC: "BOT ist in AMOUNT Sprachen verfügbar, du kannst ganz einfach BOT's Sprache ändern indem du `PREFIX locale set <country_code>` in den Chat schickst\n\n[Übersetzungen](https://t8.pm/lingua) wird durch Hilfe der Community bereitgestellt.",
UPDATED_SETTING: 'Updated SETTING to VALUE',
UNSUPPORTED: "BOT unterstützt VALUE grade nicht.",
DEFAULT: {
LANGUAGES: "Sprachen",
LOCALIZATION: "Lokalisierung",
CURRENT: `Jetzige Sprache`,
SUB: `• Benutz \`PREFIX locale set <country_code>\` um die Sprache des Server's zu ändern`
}
}
}

View File

@ -1,78 +0,0 @@
export default {
META: {
name: ":flag_us: English (US)",
locale: "en_US",
tranlators: [
"318044130796109825" // Lio
]
},
CHANNEL_NOT_NSFW: "This Channel is not marked as NSFW, please mark it as such and rerun this Command.",
INSUFFICIENT_PERMISSIONS: `You need \`PERMISSIONS\` Permissions to run this Command `,
ON_COOLDOWN: `\`COMMAND\` is on Cooldown.`,
ON_COOLDOWN_DESCRIPTION: `\`COMMAND\` has a cooldown of \`COOLDOWN\` \n Wait \`TIME\` before trying to use it again.`,
ON_ERROR: `\`COMMAND\` encountered an Error.`,
MISSING: {
NOT_ENOUGH_TAGS: `Not Enough Tags`,
NOT_ENOUGH_TAGS_DESC: "You need to provide Tags for me to search for.",
RP_REQUIRE_MENTION: `You need to mention another user.`,
MISSING_TITLE: `Missing title. Separate the title and description with a pipe (\`|\`).`,
VALUE: {
PREFIX: "No Prefix was given.",
COUNTRY: "No Country code was given",
SETTING: "No Setting was given."
}
},
USER_INFO: {
INFO_ON: "Info on USER",
STATUS: "Status | STATE",
ROLES: "Roles [AMOUNT]",
USERNAME: "Username",
USERID: "User ID",
CREATED_DATE: "Created",
JOINED_AT: "Joined",
STATES: {
ONLINE: "Online",
DND: "Do not Disturb",
IDLE: "Idle",
OFFLINE: "Offline"
}
},
NOT_ENOUGH_TAGS_DESC: "You need to provide Tags for me to search for.",
NOT_ENOUGH_TAGS: `Not Enough Tags`,
RP_REQUIRE_MENTION: `You need to mention another user.`,
RP_SELF: `Don't you want to ACTION someone other than yourself?`,
RP_ME: `Don't ACTION me! ACTION someone else.`,
MISSING_TITLE: `Missing title. Separate the title and description with a pipe (\`|\`).`,
VALUE_SENT: "VALUE sent.",
INVITE_STRING: "You can invite BOT using this Link",
ROLL: ":game_die: Rolling AMOUNT DICE...",
CATEGORIES: {
INFO: { name: "Info", desc: "" },
NSFW: { name: ":underage: NSFW", desc: "Horny Stuff, obviously." },
ANIMALS: { name: "Animals", desc: "Cute Pictures of Animals to brighten your Day!" },
MISC: { name: "Misc", desc: "Miscellaneous Commands" },
FUN: { name: "Fun", desc: "" },
DEVELOPER: { name: "Developer", desc: "Developer only Commands, duh" },
},
DEVELOPER_ONLY: "This Command is only for Developers.",
MISC: {
ENABLED: "Enabled",
DISABLED: "Disabled",
},
LOCALE: {
LANGUAGE: "Language",
CONTRIBUTORS: "AMOUNT Translator(s)",
TITLE: "LANGUAGE by TRANSLATOR",
COMMAND_DESC: "BOT is available in AMOUNT Languages, you can easily change BOT's current Language by running `PREFIX locale set <country_code>`\n\n[Translations](https://t8.pm/lingua) are provided by the Community",
UPDATED_SETTING: 'Updated SETTING to VALUE',
UNSUPPORTED: "BOT does not support VALUE at this Time.",
DEFAULT: {
LANGUAGES: "Languages",
LOCALIZATION: "Localization",
CURRENT: `Current Language`,
SUB: `• Use \`PREFIX locale set <country_code>\` to set the Guild's Language`
}
}
}

331
src/types.ts Normal file
View File

@ -0,0 +1,331 @@
// To parse this data:
//
// import { Convert, Language } from "./file";
//
// const language = Convert.toLanguage(json);
//
// These functions will throw an error if the JSON doesn't
// match the expected interface, even if the JSON is valid.
export interface Language {
meta: Meta;
missing: Missing;
error: Error;
categories: Categories;
locale: Locale;
misc: Misc;
user: User;
rp: Rp;
}
export interface Categories {
info: Command;
nsfw: Command;
animals: Command;
misc: Command;
fun: Command;
developer: Command;
}
export interface Command {
name: string;
desc: string;
}
export interface Error {
nsfw: string;
permissions: string;
error: string;
cooldown: Command;
developer: string;
}
export interface Locale {
language: string;
translators: string;
title: string;
amount: string;
updated: string;
unsupported: string;
}
export interface Meta {
name: string;
locale: string;
translators: number[];
}
export interface Misc {
invite: string;
roll: string;
sent: string;
enabled: string;
disabled: string;
}
export interface Missing {
tags: Command;
values: Values;
title: string;
mention: string;
}
export interface Values {
prefix: string;
country: string;
setting: string;
}
export interface Rp {
client: string;
self: string;
}
export interface User {
info: string;
status: string;
roles: string;
username: string;
id: string;
created: string;
joined: string;
states: States;
}
export interface States {
online: string;
dnd: string;
idle: string;
offline: string;
}
// Converts JSON strings to/from your types
// and asserts the results of JSON.parse at runtime
export class Convert {
public static toLanguage(json: string): Language {
return cast(JSON.parse(json), r("Language"));
}
public static languageToJson(value: Language): string {
return JSON.stringify(uncast(value, r("Language")), null, 2);
}
}
function invalidValue(typ: any, val: any, key: any = ''): never {
if (key) {
throw Error(`Invalid value for key "${key}". Expected type ${JSON.stringify(typ)} but got ${JSON.stringify(val)}`);
}
throw Error(`Invalid value ${JSON.stringify(val)} for type ${JSON.stringify(typ)}`,);
}
function jsonToJSProps(typ: any): any {
if (typ.jsonToJS === undefined) {
const map: any = {};
typ.props.forEach((p: any) => map[p.json] = { key: p.js, typ: p.typ });
typ.jsonToJS = map;
}
return typ.jsonToJS;
}
function jsToJSONProps(typ: any): any {
if (typ.jsToJSON === undefined) {
const map: any = {};
typ.props.forEach((p: any) => map[p.js] = { key: p.json, typ: p.typ });
typ.jsToJSON = map;
}
return typ.jsToJSON;
}
function transform(val: any, typ: any, getProps: any, key: any = ''): any {
function transformPrimitive(typ: string, val: any): any {
if (typeof typ === typeof val) return val;
return invalidValue(typ, val, key);
}
function transformUnion(typs: any[], val: any): any {
// val must validate against one typ in typs
const l = typs.length;
for (let i = 0; i < l; i++) {
const typ = typs[i];
try {
return transform(val, typ, getProps);
} catch (_) { }
}
return invalidValue(typs, val);
}
function transformEnum(cases: string[], val: any): any {
if (cases.indexOf(val) !== -1) return val;
return invalidValue(cases, val);
}
function transformArray(typ: any, val: any): any {
// val must be an array with no invalid elements
if (!Array.isArray(val)) return invalidValue("array", val);
return val.map(el => transform(el, typ, getProps));
}
function transformDate(val: any): any {
if (val === null) {
return null;
}
const d = new Date(val);
if (isNaN(d.valueOf())) {
return invalidValue("Date", val);
}
return d;
}
function transformObject(props: { [k: string]: any }, additional: any, val: any): any {
if (val === null || typeof val !== "object" || Array.isArray(val)) {
return invalidValue("object", val);
}
const result: any = {};
Object.getOwnPropertyNames(props).forEach(key => {
const prop = props[key];
const v = Object.prototype.hasOwnProperty.call(val, key) ? val[key] : undefined;
result[prop.key] = transform(v, prop.typ, getProps, prop.key);
});
Object.getOwnPropertyNames(val).forEach(key => {
if (!Object.prototype.hasOwnProperty.call(props, key)) {
result[key] = transform(val[key], additional, getProps, key);
}
});
return result;
}
if (typ === "any") return val;
if (typ === null) {
if (val === null) return val;
return invalidValue(typ, val);
}
if (typ === false) return invalidValue(typ, val);
while (typeof typ === "object" && typ.ref !== undefined) {
typ = typeMap[typ.ref];
}
if (Array.isArray(typ)) return transformEnum(typ, val);
if (typeof typ === "object") {
return typ.hasOwnProperty("unionMembers") ? transformUnion(typ.unionMembers, val)
: typ.hasOwnProperty("arrayItems") ? transformArray(typ.arrayItems, val)
: typ.hasOwnProperty("props") ? transformObject(getProps(typ), typ.additional, val)
: invalidValue(typ, val);
}
// Numbers can be parsed by Date but shouldn't be.
if (typ === Date && typeof val !== "number") return transformDate(val);
return transformPrimitive(typ, val);
}
function cast<T>(val: any, typ: any): T {
return transform(val, typ, jsonToJSProps);
}
function uncast<T>(val: T, typ: any): any {
return transform(val, typ, jsToJSONProps);
}
function a(typ: any) {
return { arrayItems: typ };
}
function u(...typs: any[]) {
return { unionMembers: typs };
}
function o(props: any[], additional: any) {
return { props, additional };
}
function m(additional: any) {
return { props: [], additional };
}
function r(name: string) {
return { ref: name };
}
const typeMap: any = {
"Language": o([
{ json: "meta", js: "meta", typ: r("Meta") },
{ json: "missing", js: "missing", typ: r("Missing") },
{ json: "error", js: "error", typ: r("Error") },
{ json: "categories", js: "categories", typ: r("Categories") },
{ json: "locale", js: "locale", typ: r("Locale") },
{ json: "misc", js: "misc", typ: r("Misc") },
{ json: "user", js: "user", typ: r("User") },
{ json: "rp", js: "rp", typ: r("Rp") },
], false),
"Categories": o([
{ json: "info", js: "info", typ: r("Command") },
{ json: "nsfw", js: "nsfw", typ: r("Command") },
{ json: "animals", js: "animals", typ: r("Command") },
{ json: "misc", js: "misc", typ: r("Command") },
{ json: "fun", js: "fun", typ: r("Command") },
{ json: "developer", js: "developer", typ: r("Command") },
], false),
"Command": o([
{ json: "name", js: "name", typ: "" },
{ json: "desc", js: "desc", typ: "" },
], false),
"Error": o([
{ json: "nsfw", js: "nsfw", typ: "" },
{ json: "permissions", js: "permissions", typ: "" },
{ json: "error", js: "error", typ: "" },
{ json: "Cooldown", js: "Cooldown", typ: r("Command") },
{ json: "developer", js: "developer", typ: "" },
], false),
"Cooldown": o([
{ json: "title", js: "title", typ: "" },
{ json: "desc", js: "desc", typ: "" },
], false),
"Locale": o([
{ json: "language", js: "language", typ: "" },
{ json: "translators", js: "translators", typ: "" },
{ json: "title", js: "title", typ: "" },
{ json: "amount", js: "amount", typ: "" },
{ json: "updated", js: "updated", typ: "" },
{ json: "unsupported", js: "unsupported", typ: "" },
], false),
"Meta": o([
{ json: "name", js: "name", typ: "" },
{ json: "locale", js: "locale", typ: "" },
{ json: "translators", js: "translators", typ: a(3.14) },
], false),
"Misc": o([
{ json: "invite", js: "invite", typ: "" },
{ json: "roll", js: "roll", typ: "" },
{ json: "sent", js: "sent", typ: "" },
{ json: "enabled", js: "enabled", typ: "" },
{ json: "disabled", js: "disabled", typ: "" },
], false),
"Missing": o([
{ json: "tags", js: "tags", typ: r("Command") },
{ json: "values", js: "values", typ: r("Values") },
{ json: "title", js: "title", typ: "" },
{ json: "mention", js: "mention", typ: "" },
], false),
"Values": o([
{ json: "prefix", js: "prefix", typ: "" },
{ json: "country", js: "country", typ: "" },
{ json: "setting", js: "setting", typ: "" },
], false),
"Rp": o([
{ json: "client", js: "client", typ: "" },
{ json: "self", js: "self", typ: "" },
], false),
"User": o([
{ json: "info", js: "info", typ: "" },
{ json: "status", js: "status", typ: "" },
{ json: "roles", js: "roles", typ: "" },
{ json: "username", js: "username", typ: "" },
{ json: "id", js: "id", typ: "" },
{ json: "created", js: "created", typ: "" },
{ json: "joined", js: "joined", typ: "" },
{ json: "states", js: "states", typ: r("States") },
], false),
"States": o([
{ json: "online", js: "online", typ: "" },
{ json: "dnd", js: "dnd", typ: "" },
{ json: "idle", js: "idle", typ: "" },
{ json: "offline", js: "offline", typ: "" },
], false),
};

78
template.yml Normal file
View File

@ -0,0 +1,78 @@
meta:
name:
locale:
translators:
- # Lio
missing:
tags:
title:
desc:
values:
prefix:
country:
setting:
title:
mention:
error:
nsfw:
permissions:
error:
COOLDOWN:
title:
desc:
developer:
categories:
info:
name:
desc:
nsfw:
name:
desc:
animals:
name:
desc:
misc:
name:
desc:
fun:
name:
desc:
developer:
name:
desc:
locale:
language:
translators:
title:
amount:
updated:
unsupported:
misc:
invite:
roll:
sent: .
enabled:
disabled:
user:
info:
status:
roles:
username:
id:
created:
joined:
states:
online:
dnd:
idle:
offline:
rp:
client:
self: