Skip to content

Commit

Permalink
docs: update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Tienisto committed Dec 16, 2023
1 parent 830a330 commit b0e5a90
Showing 1 changed file with 35 additions and 7 deletions.
42 changes: 35 additions & 7 deletions slang/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
![ci](https://github.com/slang-i18n/slang/actions/workflows/ci.yml/badge.svg)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

Type-safe i18n solution using JSON, YAML or CSV files.
Type-safe i18n solution using JSON, YAML, CSV, or ARB files.

The official successor of [fast_i18n](https://pub.dev/packages/fast_i18n).

Expand Down Expand Up @@ -415,7 +415,7 @@ targets:
| `base_locale` | `String` | locale of default json | `en` |
| `fallback_strategy` | `none`, `base_locale` | handle missing translations [(i)](#-fallback) | `none` |
| `input_directory` | `String` | path to input directory | `null` |
| `input_file_pattern` | `String` | input file pattern, must end with .json, .yaml or .csv | `.i18n.json` |
| `input_file_pattern` | `String` | input file pattern, must end with .json, .yaml, .csv, .arb | `.i18n.json` |
| `output_directory` | `String` | path to output directory | `null` |
| `output_file_name` | `String` | output file name | `null` |
| `output_format` | `single_file`, `multiple_files` | split output files [(i)](#-output-format) | `single_file` |
Expand Down Expand Up @@ -452,17 +452,20 @@ targets:

### ➤ File Types

Supported file types: `JSON (default)`, `YAML` and `CSV`.
Supported file types: `JSON (default)`, `YAML`, `CSV`, and `ARB`.

To change to YAML or CSV, please modify `input_file_pattern`.
Update `input_file_pattern` to change the file type.

```yaml
# Config
input_directory: assets/i18n
input_file_pattern: .i18n.yaml # must end with .json, .yaml or .csv
input_file_pattern: .i18n.yaml # must end with .json, .yaml, .csv, or .arb
```

**JSON Example**

The default file type.

```json
{
"welcome": {
Expand All @@ -472,6 +475,9 @@ input_file_pattern: .i18n.yaml # must end with .json, .yaml or .csv
```

**YAML Example**

YAML offers a more compact syntax. It provides native support for multiline strings and comments.

```yaml
welcome:
title: Welcome $name # some comment
Expand All @@ -482,13 +488,35 @@ welcome:
You may also combine multiple locales into one CSV (see [Compact CSV](#-compact-csv)).

```csv
# Format: <key>, <translation>
welcome.title,Welcome $name
pages.0.title,First Page
pages.1.title,Second Page
```

**ARB Example**

ARB is the default format for Flutter projects.
However, it doesn't support [lists](#-lists) or [maps](#-maps).
String interpolation is fixed to `braces` mode.

```json
{
"@@locale": "en",
"welcomeTitle": "Welcome {name}",
"@welcomeTitle": {
"placeholders": {
"name": {}
}
},
"inboxPageCount": "You have {count, plural, one {1 message} other {{count} messages}}",
"@inboxPageCount": {
"placeholders": {
"count": {}
}
}
}
```

### ➤ String Interpolation

Translations often have a dynamic parameter. There are multiple ways to define them.
Expand Down

0 comments on commit b0e5a90

Please sign in to comment.