erg/doc/EN/dev_guide/i18n_messages.md
Shunsuke Shibayama a76da9feb2 Update dev guide
2023-01-28 19:44:51 +09:00

58 lines
2 KiB
Markdown
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Multilingualization of Messages
Erg is making its messages (start, options, documentation, hints, warnings, error messages, etc.) multilingual.
You don't need detailed knowledge of Rust or Erg to participate in this project. We appreciate your cooperation.
The method for multilingualization is explained below.
## Look for `switch_lang!`
Find the entry `switch_lang!` in the Erg source code (use grep or your editor's search function).
You should find something like this:
```rust
switch_lang!(
"japanese" => format!("This feature ({name}) is not officially available yet"),
"english" => format!("this feature({name}) is not implemented yet"),
),
```
This message is currently supported in Japanese and English only. Let's try adding a simplified Chinese message.
## add a message
Add translated messages while viewing content in other languages. Don't forget the comma (`,`) at the end.
```rust
switch_lang!(
"japanese" => format!("This feature ({name}) is not officially available yet"),
"simplified_chinese" => format!("This function ({name}) has been officially provided"),
"english" => format!("this feature({name}) is not implemented yet"),
),
```
Note that English is the default and should always come last.
The `{name}` part is Rust's formatting feature that allows you to embed the contents of a variable (`name`) into a string.
## Build
Now let's build with the `--features simplified_chinese` option.
<img src="https://raw.githubusercontent.com/erg-lang/erg/main/assets/screenshot_i18n_messages.png" alt='screenshot_i18n_messages'>
You did it!
## FAQs
Q: What does a specification like `{RED}{foo}{RESET}` mean?
A: Everything after {RED} is displayed in red. {RESET} restores the color.
Q: If I want to add my own language, how do I replace the `"simplified_chinese" =>` part?
A: We currently support the following languages:
* "english" (default)
* "japanese" (Japanese)
* "simplified_chinese" (Simplified Chinese)
* "traditional_chinese" (Traditional Chinese)
If you would like to add languages other than these, please make a request.