diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 08c5e8b..2bce1d5 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -13,6 +13,7 @@ generator client { model Guild { id String @id prefix String @default(">") + locale String @default("en") isEnabled Boolean @default(true) MembershipScreening_Enabled Boolean @default(false) @@ -22,3 +23,8 @@ model Guild { ServiceAnnouncement_Enabled Boolean @default(false) ServiceAnnouncement_Channel String? } + +model User { + id String @id + locale String @default("en") +} \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 00bddf0..39f61b1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,7 +6,9 @@ NativeException.process(); App.loadConfig(); App.loadENV(); App.loadPrisma(); +App.loadLocale(); App.loadDiscord(); App.load_osu(); + export default App; diff --git a/src/providers/App.ts b/src/providers/App.ts index 7cd4d8f..116ffd4 100644 --- a/src/providers/App.ts +++ b/src/providers/App.ts @@ -5,6 +5,7 @@ import Discord from './Discord'; import osu from './osuAPI'; import Logger from '../libs/Logger'; +import Locale from './Locale'; class App { public readonly versionNumber = `0.09`; public readonly version = `${this.versionNumber}${ @@ -31,6 +32,11 @@ class App { Discord.init(); } + public loadLocale(): void { + Logger.log('info', 'Loading Locale'); + Locale.init(); + } + public load_osu(): void { Logger.log('info', 'Loading osu! Client'); osu.init(); diff --git a/src/providers/Locale.ts b/src/providers/Locale.ts new file mode 100644 index 0000000..b5e2aa5 --- /dev/null +++ b/src/providers/Locale.ts @@ -0,0 +1,27 @@ +import { I18n } from 'i18n'; +import * as path from 'path'; +import Logger from '../libs/Logger'; + +class Locale { + public localePath: string; + + constructor() { + this.localePath = path.join(process.cwd(), 'locales/'); + } + + public init(): void { + Logger.log('info', 'Loaded locales: ' + this.getLocaleProvider("en").getLocales().join(', ')); + } + + public getLocaleProvider(locale: string) { + const i18n = new I18n(); + i18n.configure({ + directory: this.localePath + }) + i18n.setLocale(locale); + return i18n; + } + +} + +export default new Locale(); \ No newline at end of file