mirror of
https://github.com/sern-handler/website
synced 2026-06-06 01:16:47 +00:00
fix: fix setup for tools documentation
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -21,4 +21,4 @@ pnpm-debug.log*
|
||||
.DS_Store
|
||||
|
||||
sern-handler-*
|
||||
tools/
|
||||
/tools/
|
||||
|
||||
75
src/content/docs/v4/tools/localizer.mdx
Normal file
75
src/content/docs/v4/tools/localizer.mdx
Normal file
@@ -0,0 +1,75 @@
|
||||
---
|
||||
title: Localizer
|
||||
description: Translate your bot for the world
|
||||
sidebar:
|
||||
order: 1
|
||||
---
|
||||
|
||||
|
||||
# @sern/localizer
|
||||
|
||||
A localization module for managing translations and providing localized content in your application.
|
||||
|
||||
## Installation
|
||||
|
||||
```
|
||||
npm i @sern/localizer
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
**Initializing the Localizer**
|
||||
```ts
|
||||
import { makeDependencies } from '@sern/handler';
|
||||
import { Localization } from '@sern/localizer';
|
||||
|
||||
await makeDependencies(({ add }) => {
|
||||
add('localizer', Localization());
|
||||
});
|
||||
```
|
||||
This localizer is **FILE BASED**.
|
||||
Create the directory `assets/locals`. Each json file in here must be named after the `locale`
|
||||
|
||||
import { Tabs, TabItem } from "@astrojs/starlight/components";
|
||||
|
||||
<Tabs>
|
||||
<TabItem label="Spanish">
|
||||
```json title=~/assets/locals/es.json
|
||||
{
|
||||
"salute": {
|
||||
"hello": "hola"
|
||||
}
|
||||
}
|
||||
```
|
||||
</TabItem>
|
||||
<TabItem label="English">
|
||||
```json title=~/assets/locals/en-US.json
|
||||
{
|
||||
"salute": {
|
||||
"hello": "hello"
|
||||
}
|
||||
}
|
||||
```
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
|
||||
|
||||
**Accessing translations**
|
||||
- If you are in a command execute callback, use `deps` from SDT.
|
||||
```ts
|
||||
execute : (ctx, { deps }) => {
|
||||
//the localizer object from makeDependencies
|
||||
deps.localizer
|
||||
// Returns the Spanish translation for 'salute.hello'
|
||||
deps.localizer.translate("salute.hello", "es");
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
```ts
|
||||
import { local } from '@sern/localizer';
|
||||
|
||||
// Returns the Spanish translation for 'salute.hello'
|
||||
const greeting = local('salute.hello', 'es');
|
||||
```
|
||||
Reference in New Issue
Block a user