Skip to content

Internationalization i18n

Psyche edited this page Aug 22, 2024 · 3 revisions

Overview

Mainly implemented the multilingual function of printing related logs, with language files in JSON format. WebSocket Server automatically matches language files with local language information upon startup.

The language folder path is usually the current path where the program runs when it does not contain root directory information

Static property

1. I18nResourcePath

The I18nResourcePath static property is used to specify the path of the language folder, which defaults to the i18n directory under the current running directory.

2. I18nResourceFileSuffix

The I18nResourceFileSuffix static property is used to specify the suffix of the language file, which defaults to. json.

How to work

The language file name must conform to System The name conventions for Globalization. CultureInfo, such as zh CN, en US, etc.

The language file is in JSON format, and the JSON file is in the form of key value pairs.

The key in JSON is a static read-only field in Class "Cyaim.WebSocketServer.Infrastructure.I18nText" that is not marked with the [JsonIgnore]. If all or part of the language configuration has been modified, I18nText.UpdateI18nText() method updates the running language text.

I18nText.UpdateI18nText("zh-CN");
// Or
I18nText.UpdateI18nText("../i18n/zh-CN.json");

Clone this wiki locally