From e1b2d91e1c51417aca1144e16164b108ab245664 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Marie=20De=20Mey?= Date: Tue, 30 Apr 2024 10:49:30 +0300 Subject: [PATCH] prettier --- docs/README.md | 2 +- docs/client.md | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/docs/README.md b/docs/README.md index 5456c93..01991cc 100644 --- a/docs/README.md +++ b/docs/README.md @@ -5,8 +5,8 @@ > :warning: **Work in progress!** Projects using OmnI18n use it in 4 layers + 1. [The `client`](./client.md): The client manages the cache and download along with text retrieval and interpolation 2. (optional) The HTTP or any other layer. This part is implemented by the user 3. The `server`: The server exposes functions to interact with the languages 4. The `database`: A class implementing some interface that interacts directly with a database - diff --git a/docs/client.md b/docs/client.md index 95a5cbc..0548022 100644 --- a/docs/client.md +++ b/docs/client.md @@ -31,6 +31,7 @@ import { reports, formats, processors } from 'omni18n' #### `reports` Reporting mechanism in case of problem. They both take an argument of type `TContext` describing mainly the client and the key where the problem occurred + ```ts export interface TContext { key: string @@ -42,31 +43,35 @@ export interface TContext { > If texts might be displayed before loading is complete, make sure `onModification` has been specified as it will be called when the translations will be provided These reports will: + - have any side effect, like logging or making a request that will log - return a string that will be used instead of the expected translation `reports` contain: - A missing key report + ```ts -reports.missing = ({ key, client }: TContext, fallback?: string)=> { +reports.missing = ({ key, client }: TContext, fallback?: string) => { // report return fallback ?? `[${key}]` } ``` - A "missing key while loading" report -This one is called only when the client is in a loading state. If `onModification` was specified, it will be called once loaded. If not, the client will automatically check all the keys that went through this error to check them again. + This one is called only when the client is in a loading state. If `onModification` was specified, it will be called once loaded. If not, the client will automatically check all the keys that went through this error to check them again. + ```ts -reports.loading = ({ client }: TContext)=> '...' +reports.loading = ({ client }: TContext) => '...' ``` - An interpolation error -When interpolating, an error calls this report with a textual description and some specifications depending on the error. + When interpolating, an error calls this report with a textual description and some specifications depending on the error. + +> The specification is json-able _except_ in the case of `error: "Error in processor"`, in which case `spec.error` is whatever had been thrown and might be an `Error` or `Exception` -> The specification is json-able *except* in the case of `error: "Error in processor"`, in which case `spec.error` is whatever had been thrown and might be an `Error` or `Exception` ```ts -reports.error = ({ key, client }: TContext, error: string, spec: object)=> { +reports.error = ({ key, client }: TContext, error: string, spec: object) => { // report return '[!error!]' } @@ -74,4 +79,4 @@ reports.error = ({ key, client }: TContext, error: string, spec: object)=> { #### `formats` -#### `processors` \ No newline at end of file +#### `processors`