fix: fix setup for tools documentation

This commit is contained in:
DuroCodes
2024-06-10 23:53:35 -04:00
parent c13abec8e0
commit e540a14dd9
2 changed files with 76 additions and 1 deletions

2
.gitignore vendored
View File

@@ -21,4 +21,4 @@ pnpm-debug.log*
.DS_Store .DS_Store
sern-handler-* sern-handler-*
tools/ /tools/

View 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');
```