Skip to content

Commit

Permalink
feat(i18n): add i18n
Browse files Browse the repository at this point in the history
  • Loading branch information
havrydotdev committed Oct 12, 2023
1 parent b2e412e commit 5696e2f
Show file tree
Hide file tree
Showing 29 changed files with 340 additions and 144 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = {
node: true,
jest: true,
},
ignorePatterns: ['.eslintrc.js'],
ignorePatterns: ['.eslintrc.js', 'src/generated'],
rules: {
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
Expand Down
Binary file modified dev.sqlite
Binary file not shown.
2 changes: 1 addition & 1 deletion nest-cli.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"collection": "@nestjs/schematics",
"sourceRoot": "src",
"compilerOptions": {
"deleteOutDir": true
"assets": [{ "include": "i18n/**/*", "watchAssets": true }]
}
}
86 changes: 66 additions & 20 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"@telegraf/session": "^2.0.0-beta.6",
"better-sqlite3": "^8.7.0",
"kysely": "^0.23.5",
"nestjs-i18n": "^10.3.6",
"nestjs-telegraf": "^2.7.0",
"pg": "^8.11.3",
"reflect-metadata": "^0.1.13",
Expand Down
13 changes: 9 additions & 4 deletions src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { TelegramModule, UserModule } from './services';
import { AppUpdate } from './updates';
import { ReplyModule, TelegramModule, UserModule } from './services';
import { AppUpdate } from './controllers';
import { DatabaseModule } from './services';
import { UserUseCaseModule } from './use-cases/user';
import { UserUseCasesModule } from './use-cases/user';
import { ReplyUseCasesModule } from './use-cases/reply';
import { I18nModule } from './services/i18n/i18n.module';

@Module({
imports: [
Expand All @@ -13,7 +15,10 @@ import { UserUseCaseModule } from './use-cases/user';
TelegramModule,
DatabaseModule,
UserModule,
UserUseCaseModule,
UserUseCasesModule,
ReplyModule,
ReplyUseCasesModule,
I18nModule,
],
controllers: [],
providers: [AppUpdate],
Expand Down
55 changes: 55 additions & 0 deletions src/controllers/app.update.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { Command, Ctx, Hears, Help, Start, Update } from 'nestjs-telegraf';
import { Context } from 'src/core';
import { Language } from 'src/core/enums/languages.enum';
import { ReplyUseCases } from 'src/use-cases/reply';
import { UserUseCases } from 'src/use-cases/user/user.use-case';
import { Message } from 'telegraf/typings/core/types/typegram';

@Update()
export class AppUpdate {
constructor(
private readonly userUseCases: UserUseCases,
private readonly replyUseCases: ReplyUseCases,
) {}

@Start()
async onStart(@Ctx() ctx: Context) {
// if user does not exist in session, create it
if (!ctx.session.user) {
ctx.session.user = await this.userUseCases.create({
chatId: ctx.chat.id,
userId: ctx.from.id,
});
}

await this.replyUseCases.start(ctx);
}

@Hears(/🇺🇦|🇬🇧|🇷🇺/)
async onUa(@Ctx() ctx: Context) {
// convert ctx.message to Message.TextMessage so we can access text property
switch ((ctx.message as Message.TextMessage).text) {
case '🇺🇦':
ctx.session.lang = Language.UA;
break;
case '🇬🇧':
ctx.session.lang = Language.EN;
break;
case '🇷🇺':
ctx.session.lang = Language.RU;
break;
}

await this.replyUseCases.langChanged(ctx);
}

@Command('language')
async onLanguage(@Ctx() ctx: Context) {
await this.replyUseCases.updateLanguage(ctx);
}

@Help()
async onHelp(@Ctx() ctx: Context) {
await this.replyUseCases.help(ctx);
}
}
File renamed without changes.
Empty file.
Loading

0 comments on commit 5696e2f

Please sign in to comment.