-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fix setup for tools documentation
- Loading branch information
Showing
2 changed files
with
76 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,4 +21,4 @@ pnpm-debug.log* | |
.DS_Store | ||
|
||
sern-handler-* | ||
tools/ | ||
/tools/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
``` |