Skip to content

Commit

Permalink
fix: fix setup for tools documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
DuroCodes committed Jun 11, 2024
1 parent c13abec commit e540a14
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ pnpm-debug.log*
.DS_Store

sern-handler-*
tools/
/tools/
75 changes: 75 additions & 0 deletions src/content/docs/v4/tools/localizer.mdx
Original file line number Diff line number Diff line change
@@ -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');
```

0 comments on commit e540a14

Please sign in to comment.