Game localization (i18n) module. 更多...
#include <I18n.h>
Public 成员函数 | |
| Module_REG (I18n) | |
| I18n ()=default | |
| I 18 n. | |
| ~I18n () override=default | |
| I 18 n. | |
| eve::Result< void > | replaceLocaleFromJson (const std::string &lang, const std::string &json) |
| Atomically replace one locale from JSON with structured failure details. | |
| eve::Result< void > | replaceLocaleFromFile (const std::string &lang, const std::string &path) |
| Atomically replace one locale from a VFS file with structured failure details. | |
| bool | loadFromJson (const std::string &lang, const std::string &json) |
| Compatibility-only bool projection of replaceLocaleFromJson. | |
| bool | loadFromFile (const std::string &lang, const std::string &path) |
| Compatibility-only bool projection of replaceLocaleFromFile. | |
| eve::Result< int > | replaceBundleFromJson (const std::string &json) |
| Atomically replace every locale from one strictly validated product bundle. | |
| void | unload (const std::string &lang) |
| 卸载 / 清空语言表。 | |
| void | clear () |
| Clears . | |
| eve::Result< void > | selectLanguage (const std::string &lang) |
| Select an admitted language with a structured missing-locale diagnostic. | |
| bool | setLanguage (const std::string &lang) |
| Compatibility-only bool projection of selectLanguage. | |
| std::string | getLanguage () const |
| Returns the language. | |
| void | setDefaultLanguage (const std::string &lang) |
| Sets the default language. | |
| std::string | getDefaultLanguage () const |
| Returns the default language. | |
| int | getLanguageCount () const |
| Returns the language count. | |
| std::string | getLanguageAt (int index) const |
| Returns the language at. | |
| bool | hasLanguage (const std::string &lang) const |
| True when language. | |
| bool | hasInLanguage (const std::string &lang, const std::string &key) const |
Return whether one exact locale owns key, without default-language substitution. | |
| eve::Result< int > | validateKeyCoverage (const std::string &key) const |
| Validate that every admitted locale owns one exact product key. | |
| int | getKeyCount (const std::string &lang) const |
| Return the number of singular and plural keys owned by one locale, or zero if absent. | |
| bool | has (const std::string &key) const |
| 翻译查找:按键(点号命名空间)取字符串。 | |
| std::string | get (const std::string &key) const |
| Returns the value. | |
| std::string | getWithParams (const std::string &key, const std::unordered_map< std::string, std::string > ¶ms) const |
| Returns the with params. | |
| std::string | getPlural (const std::string &key, int n) const |
| Returns the plural. | |
| std::string | getPluralWithParams (const std::string &key, int n, const std::unordered_map< std::string, std::string > ¶ms) const |
| Returns the plural with params. | |
| void | setAutoReload (bool enable) |
| Sets the auto reload. | |
| bool | isAutoReload () const |
| True when auto reload. | |
| int | update (float dt) |
| Re-read changed locale files; returns the number of reloads performed. | |
Public 成员函数 继承自 eve::Module | |
| virtual | ~Module () |
| Module. | |
| virtual std::string | getName () const =0 |
| Returns the name. | |
详细描述
Game localization (i18n) module.
Locale tables map a translation key to a string (or a set of plural forms). Keys use dot notation for namespacing, e.g. menu.start resolves the JSON path menu -> start. Lookup falls back to the default language and finally to the raw key so untranslated keys stay visible during development.
Locale JSON shape:
An object whose keys are all plural categories (zero/one/two/few/many/other) is treated as a plural form table for its key. {name} placeholders are substituted from the params table; {n} is filled by getPlural.
Script: i18n <- eve.I18n();
构造及析构函数说明
◆ I18n()
|
default |
I 18 n.
◆ ~I18n()
|
overridedefault |
I 18 n.
成员函数说明
◆ clear()
◆ get()
| std::string eve::i18n::I18n::get | ( | const std::string & | key | ) | const |
◆ getDefaultLanguage()
|
inline |
◆ getKeyCount()
| int eve::i18n::I18n::getKeyCount | ( | const std::string & | lang | ) | const |
◆ getLanguage()
|
inline |
◆ getLanguageAt()
| std::string eve::i18n::I18n::getLanguageAt | ( | int | index | ) | const |
◆ getLanguageCount()
|
inline |
◆ getPlural()
| std::string eve::i18n::I18n::getPlural | ( | const std::string & | key, |
| int | n | ||
| ) | const |
◆ getPluralWithParams()
| std::string eve::i18n::I18n::getPluralWithParams | ( | const std::string & | key, |
| int | n, | ||
| const std::unordered_map< std::string, std::string > & | params | ||
| ) | const |
◆ getWithParams()
| std::string eve::i18n::I18n::getWithParams | ( | const std::string & | key, |
| const std::unordered_map< std::string, std::string > & | params | ||
| ) | const |
◆ has()
| bool eve::i18n::I18n::has | ( | const std::string & | key | ) | const |
◆ hasInLanguage()
| bool eve::i18n::I18n::hasInLanguage | ( | const std::string & | lang, |
| const std::string & | key | ||
| ) | const |
Return whether one exact locale owns key, without default-language substitution.
引用了 key.
被这些函数引用 validateKeyCoverage() , 以及 eve::dialogue::DialogueFlow::validateLocalization().
◆ hasLanguage()
| bool eve::i18n::I18n::hasLanguage | ( | const std::string & | lang | ) | const |
True when language.
被这些函数引用 selectLanguage() , 以及 eve::dialogue::DialogueFlow::validateLocalization().
◆ isAutoReload()
◆ loadFromFile()
| bool eve::i18n::I18n::loadFromFile | ( | const std::string & | lang, |
| const std::string & | path | ||
| ) |
Compatibility-only bool projection of replaceLocaleFromFile.
引用了 eve::Result< void >::ok(), path , 以及 replaceLocaleFromFile().
◆ loadFromJson()
| bool eve::i18n::I18n::loadFromJson | ( | const std::string & | lang, |
| const std::string & | json | ||
| ) |
Compatibility-only bool projection of replaceLocaleFromJson.
◆ Module_REG()
| eve::i18n::I18n::Module_REG | ( | I18n | ) |
◆ replaceBundleFromJson()
| eve::Result< int > eve::i18n::I18n::replaceBundleFromJson | ( | const std::string & | json | ) |
Atomically replace every locale from one strictly validated product bundle.
- 参数
-
json UTF-8 JSON using schema eve.i18n.bundle, version 1.
- 返回
- Number of admitted locales, or a path-scoped diagnostic. Failure leaves the current locales, current language and default language unchanged.
- @ownership The module copies all admitted text; it does not retain
json. @thread Main-thread only. Concurrent lookup or mutation is unsupported. @reentrancy Does not invoke script or user callbacks.
引用了 eve::Applied, error, eve::Diagnostic::error(), eve::Result< T >::failure(), eve::InvalidArgument, key, eve::NotFound, eve::json::Document::parse(), eve::ParseError, root, source, eve::Status::success(), eve::Result< T >::success() , 以及 eve::UnknownVersion.
◆ replaceLocaleFromFile()
| eve::Result< void > eve::i18n::I18n::replaceLocaleFromFile | ( | const std::string & | lang, |
| const std::string & | path | ||
| ) |
Atomically replace one locale from a VFS file with structured failure details.
- 参数
-
lang Stable locale identifier copied by the module. path VFS path read synchronously and retained only for hot-reload observation.
- 返回
- Applied on success; read and parse failures leave the locale unchanged. @thread Main-thread only. @reentrancy Does not invoke callbacks.
引用了 eve::Applied, error, eve::Diagnostic::error(), eve::Result< T >::failure(), eve::filesystem::FileData::getData(), eve::filesystem::FileData::getSize(), eve::InvalidArgument, eve::NotFound, eve::ParseError, path, eve::Status::success(), eve::Result< T >::success() , 以及 text.
被这些函数引用 loadFromFile() , 以及 update().
◆ replaceLocaleFromJson()
| eve::Result< void > eve::i18n::I18n::replaceLocaleFromJson | ( | const std::string & | lang, |
| const std::string & | json | ||
| ) |
Atomically replace one locale from JSON with structured failure details.
- 参数
-
lang Stable locale identifier copied by the module. json UTF-8 locale object copied and parsed synchronously.
- 返回
- Applied on success; parse and argument failures do not mutate the locale. @thread Main-thread only. @reentrancy Does not invoke callbacks.
引用了 eve::Applied, error, eve::Diagnostic::error(), eve::Result< T >::failure(), eve::InvalidArgument, eve::ParseError, eve::Status::success() , 以及 eve::Result< T >::success().
被这些函数引用 loadFromJson().
◆ selectLanguage()
| eve::Result< void > eve::i18n::I18n::selectLanguage | ( | const std::string & | lang | ) |
Select an admitted language with a structured missing-locale diagnostic.
- 返回
- Applied on success; failure leaves the selected language unchanged. @thread Main-thread only. @reentrancy Does not invoke callbacks.
引用了 eve::Applied, eve::Diagnostic::error(), eve::Result< T >::failure(), hasLanguage(), eve::NotFound, eve::Status::success() , 以及 eve::Result< T >::success().
被这些函数引用 setLanguage().
◆ setAutoReload()
|
inline |
◆ setDefaultLanguage()
|
inline |
◆ setLanguage()
| bool eve::i18n::I18n::setLanguage | ( | const std::string & | lang | ) |
Compatibility-only bool projection of selectLanguage.
引用了 eve::Result< void >::ok() , 以及 selectLanguage().
◆ unload()
◆ update()
| int eve::i18n::I18n::update | ( | float | dt | ) |
Re-read changed locale files; returns the number of reloads performed.
引用了 dirty, eve::Result< void >::ok(), path , 以及 replaceLocaleFromFile().
◆ validateKeyCoverage()
| eve::Result< int > eve::i18n::I18n::validateKeyCoverage | ( | const std::string & | key | ) | const |
Validate that every admitted locale owns one exact product key.
- 参数
-
key Dot-separated stable key whose segments use ASCII letters, digits, _or-.
- 返回
- Number of covered locales, or a locale/key-scoped diagnostic. Default-language substitution is never used. @ownership The key is inspected synchronously and is not retained. @thread Main-thread only; concurrent locale mutation is unsupported. @reentrancy Does not invoke callbacks.
引用了 eve::Diagnostic::error(), eve::Result< T >::failure(), hasInLanguage(), eve::InvalidArgument, key, eve::NotFound, offset , 以及 eve::Result< T >::success().
该类的文档由以下文件生成:
Public 成员函数 继承自