dockfries / infernus

Node.js library for scripting Open Multiplayer.
https://dockfries.github.io/infernus/
MIT License
21 stars 2 forks source link

about i18n #29

Closed dockfries closed 1 year ago

dockfries commented 2 years ago

Principle

The current situation is that the player chooses the interface language and the system character set on his own, because for sa:mp windows the character set is ansi, depending on the different regions.

The server-side texts are all utf8, and when transmitting to the player, the utf8 is converted into an array of decimal bytes for transmission with the character set chosen by the player.

When the player transmits text data to the server, custom events are also defined by polyfill (see gamemode for details) and passed to the server as decimal byte arrays, which are decoded to utf8 by the server according to the character set chosen by the player.

By now a two-way closed-loop internationalized data transfer has been achieved.

Nickname

See gamemode and dockfries/omp-node#14 for support for multi-byte nicknames.

Note

It is worth noting that:

  1. if the player prefers not to select the correct character set, both the server and the player will receive the text as the wrong character set.
  2. even if the text entered by a player is received by the server as normal in utf8, it will still be garbled if it is sent to another player in a character set that does not support that character. For example, if a player with gbk charset sends to a player with only English charset, the other player will still see the Chinese text is still garbled like '?'.
  3. GameText and TextDraw should always be in accordance with the utf8 character set, because it depends on the character set used by the internationalization modify of the player's client, otherwise it will always display abnormally, and should always be in utf8 format if the omp client supports it in the future.
dockfries commented 11 months ago

If you using windows system and there is garbled code when the terminal displays pino logger, you can run the server with the following command.

cmd /c "chcp 65001 > nul & omp-server" in powershell or cmd, which launches a cmd window and temporarily sets the charset to utf8.

for powershell, please add $PROFILE for persistence

# $OutputEncoding = [Console]::OutputEncoding = [System.Text.Encoding]::UTF8
$OutputEncoding = [Console]::InputEncoding = [Console]::OutputEncoding = New-Object System.Text.UTF8Encoding

Usually, the dev/serve of the terminal under vscode will not garble, because the vscode sets the terminal to be utf8 encoded, so the display is normal.

Although it is more recommended to run directly on linux systems.