From e540a14dd962a7aff5a086b78391d2f2cdaa3984 Mon Sep 17 00:00:00 2001 From: DuroCodes Date: Mon, 10 Jun 2024 23:53:35 -0400 Subject: [PATCH] fix: fix setup for tools documentation --- .gitignore | 2 +- src/content/docs/v4/tools/localizer.mdx | 75 +++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 src/content/docs/v4/tools/localizer.mdx diff --git a/.gitignore b/.gitignore index 998068cae..84e0f890c 100644 --- a/.gitignore +++ b/.gitignore @@ -21,4 +21,4 @@ pnpm-debug.log* .DS_Store sern-handler-* -tools/ +/tools/ diff --git a/src/content/docs/v4/tools/localizer.mdx b/src/content/docs/v4/tools/localizer.mdx new file mode 100644 index 000000000..eda90fa6f --- /dev/null +++ b/src/content/docs/v4/tools/localizer.mdx @@ -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"; + + + + ```json title=~/assets/locals/es.json + { + "salute": { + "hello": "hola" + } + } + ``` + + + ```json title=~/assets/locals/en-US.json + { + "salute": { + "hello": "hello" + } + } + ``` + + + + + +**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'); +```