add index.mdx

This commit is contained in:
Jacob Nguyen
2024-06-07 19:59:45 -05:00
parent d460185b70
commit e1a397c01f
2 changed files with 56 additions and 0 deletions

View File

@@ -0,0 +1,53 @@
---
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`
```json title="~/assets/locals/es.json
{
"salute": {
"hello": "hola"
}
}
```
**Accessing translations**
- If you are in a command execute callback, use `deps` from SDT.
```ts
execute : (ctx, { deps }) => {
deps.localizer
deps.localizer.translate("salute.hello", "es"); // Returns the Spanish translation for 'salute.hello'
}
```
import { local } from '@sern/localizer';
const greeting = local('salute.hello', 'es'); // Returns the Spanish translation for 'salute.hello'

View File

@@ -0,0 +1,3 @@
{
"type": "service"
}