Skip to content

Commit

Permalink
chore: update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
RozmarinUS committed Jun 2, 2024
1 parent f03089a commit 3cb2f9b
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion docs/content/recipes/localization.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export class GuildResolver implements LocaleResolver {

We can inject the `LOCALIZATION_ADAPTER` into our service and use it to localize our commands and messages:

```typescript
```typescript title="src/app.gateway.ts"
import { Injectable, Inject, OnModuleInit } from '@nestjs/common';
import { DefaultLocalizationAdapter, localizationMapByKey, LOCALIZATION_ADAPTER } from '@globalart/nestcord';
import { Context, SlashCommand, SlashCommandContext } from '@globalart/nestcord';
Expand Down Expand Up @@ -179,6 +179,36 @@ export class AppService implements OnModuleInit {
}
```

Or you can use `translate` function from the localization adapter:

```typescript title="src/app.gateway.ts"
import { Injectable, Inject, OnModuleInit } from '@nestjs/common';
import { DefaultLocalizationAdapter, localizationMapByKey, LOCALIZATION_ADAPTER } from '@globalart/nestcord';
import { Context, SlashCommand, SlashCommandContext } from '@globalart/nestcord';

@Injectable()
export class AppService implements OnModuleInit {
public constructor(
@Inject(LOCALIZATION_ADAPTER)
private readonly localizationAdapter: DefaultLocalizationAdapter
) {
}

@SlashCommand({
name: 'ping',
description: 'Pong!',
nameLocalizations: localizationMapByKey('commands.ping.name'),
descriptionLocalizations: localizationMapByKey('commands.ping.name')
})
public ping(@Context() [interaction]: SlashCommandContext) {
const message = this.localizationAdapter.translate(
'commands.ping.description',
);
return interaction.reply(message);
}
}
```

Or you can use `@CurrentTranslate` decorator to get the current translation from context:

```typescript
Expand Down

0 comments on commit 3cb2f9b

Please sign in to comment.