Added t!() macro

This commit is contained in:
ElBe
2023-10-06 07:39:56 +02:00
parent a8fd02158b
commit 163e31bb45
9 changed files with 154 additions and 31 deletions
+3 -15
View File
@@ -39,25 +39,19 @@ To use localizer-rs, you need a directory (eg. `translations`) with your transla
1. Import the localizer-rs crate:
```rust,ignore
use localizer_rs;
```
2. Create a new config object:
```rust,ignore
let config = localizer_rs::Config::new("DIRECTORY NAME", "LANGUAGE NAME");
let config = localizer_rs::Config::new("translations", "en");
```
3. Translate your text:
```rust,ignore
config.t("key", vec!["placeholder", "value"]);
localizer_rs::t!(config, "key", "placeholder" ="value");
```
## Example
@@ -65,33 +59,27 @@ To use localizer-rs, you need a directory (eg. `translations`) with your transla
With the following `en.json` file.
```json
{
"error": "{{color.red}}{{bold}}Error:{{end}} Something went wrong: {{details}}."
}
```
And the following rust code.
```rust,ignore
use localizer_rs;
fn main() {
let config: localizer_rs::Config = localizer_rs::Config::new("translations", "en");
println!("{:}", config.t("error", vec![("details", "Path not found")]));
println!("{:}", localizer_rs::t!(config, "error", "details" = "Path not found"));
}
```
You will get the following output:
```bash
Error: Something went wrong: Path not found.
```
Where `Error:` is red and bold.
+1
View File
@@ -7,6 +7,7 @@
| `v1.0.0` | :white_check_mark: |
| `v1.1.0` | :white_check_mark: |
| `v1.1.1` | :white_check_mark: |
| `v1.2.0` | :white_check_mark: |
## Reporting a Vulnerability
+3
View File
@@ -0,0 +1,3 @@
# errors module
Module for dealing with errors.
+1
View File
@@ -6,6 +6,7 @@ on:
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3