Skip to content

Commit

Permalink
prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
eddow committed Apr 30, 2024
1 parent ced6183 commit e1b2d91
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

19 changes: 12 additions & 7 deletions docs/client.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -42,36 +43,40 @@ 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!]'
}
```

#### `formats`

#### `processors`
#### `processors`

0 comments on commit e1b2d91

Please sign in to comment.