载入中...
搜索中...
未找到
eve::i18n::I18n类 参考

Game localization (i18n) module. 更多...

#include <I18n.h>

类 eve::i18n::I18n 继承关系图:
eve::Module

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 > &params) 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 > &params) 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:

{
"menu": { "start": "Start", "quit": "Quit" },
"items": { "one": "{n} item", "other": "{n} items" },
"greeting": "Hello, {name}!"
}

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.h 第 38 行定义.

构造及析构函数说明

◆ I18n()

eve::i18n::I18n::I18n ( )
default

I 18 n.

◆ ~I18n()

eve::i18n::I18n::~I18n ( )
overridedefault

I 18 n.

成员函数说明

◆ clear()

void eve::i18n::I18n::clear ( )

Clears .

在文件 I18n.cpp 第 461 行定义.

◆ get()

std::string eve::i18n::I18n::get ( const std::string &  key) const

Returns the value.

在文件 I18n.cpp 第 538 行定义.

引用了 key.

被这些函数引用 getWithParams().

◆ getDefaultLanguage()

std::string eve::i18n::I18n::getDefaultLanguage ( ) const
inline

Returns the default language.

在文件 I18n.h 第 106 行定义.

◆ getKeyCount()

int eve::i18n::I18n::getKeyCount ( const std::string &  lang) const

Return the number of singular and plural keys owned by one locale, or zero if absent.

在文件 I18n.cpp 第 521 行定义.

◆ getLanguage()

std::string eve::i18n::I18n::getLanguage ( ) const
inline

Returns the language.

在文件 I18n.h 第 102 行定义.

◆ getLanguageAt()

std::string eve::i18n::I18n::getLanguageAt ( int  index) const

Returns the language at.

在文件 I18n.cpp 第 473 行定义.

引用了 index.

◆ getLanguageCount()

int eve::i18n::I18n::getLanguageCount ( ) const
inline

Returns the language count.

在文件 I18n.h 第 108 行定义.

◆ getPlural()

std::string eve::i18n::I18n::getPlural ( const std::string &  key,
int  n 
) const

Returns the plural.

在文件 I18n.cpp 第 579 行定义.

引用了 getPluralWithParams(), key , 以及 n.

◆ getPluralWithParams()

std::string eve::i18n::I18n::getPluralWithParams ( const std::string &  key,
int  n,
const std::unordered_map< std::string, std::string > &  params 
) const

Returns the plural with params.

在文件 I18n.cpp 第 581 行定义.

引用了 current, key, n , 以及 params.

被这些函数引用 getPlural().

◆ getWithParams()

std::string eve::i18n::I18n::getWithParams ( const std::string &  key,
const std::unordered_map< std::string, std::string > &  params 
) const

Returns the with params.

在文件 I18n.cpp 第 574 行定义.

引用了 get(), key , 以及 params.

◆ has()

bool eve::i18n::I18n::has ( const std::string &  key) const

翻译查找:按键(点号命名空间)取字符串。

在文件 I18n.cpp 第 526 行定义.

引用了 key.

◆ 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.

在文件 I18n.cpp 第 484 行定义.

引用了 key.

被这些函数引用 validateKeyCoverage() , 以及 eve::dialogue::DialogueFlow::validateLocalization().

◆ hasLanguage()

bool eve::i18n::I18n::hasLanguage ( const std::string &  lang) const

True when language.

在文件 I18n.cpp 第 482 行定义.

被这些函数引用 selectLanguage() , 以及 eve::dialogue::DialogueFlow::validateLocalization().

◆ isAutoReload()

bool eve::i18n::I18n::isAutoReload ( ) const
inline

True when auto reload.

在文件 I18n.h 第 143 行定义.

◆ loadFromFile()

bool eve::i18n::I18n::loadFromFile ( const std::string &  lang,
const std::string &  path 
)

Compatibility-only bool projection of replaceLocaleFromFile.

在文件 I18n.cpp 第 455 行定义.

引用了 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.

在文件 I18n.cpp 第 278 行定义.

引用了 eve::Result< void >::ok() , 以及 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.

参数
jsonUTF-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.

在文件 I18n.cpp 第 282 行定义.

引用了 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.

参数
langStable locale identifier copied by the module.
pathVFS 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.

在文件 I18n.cpp 第 416 行定义.

引用了 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.

参数
langStable locale identifier copied by the module.
jsonUTF-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.

在文件 I18n.cpp 第 262 行定义.

引用了 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.

在文件 I18n.cpp 第 463 行定义.

引用了 eve::Applied, eve::Diagnostic::error(), eve::Result< T >::failure(), hasLanguage(), eve::NotFound, eve::Status::success() , 以及 eve::Result< T >::success().

被这些函数引用 setLanguage().

◆ setAutoReload()

void eve::i18n::I18n::setAutoReload ( bool  enable)
inline

Sets the auto reload.

在文件 I18n.h 第 141 行定义.

◆ setDefaultLanguage()

void eve::i18n::I18n::setDefaultLanguage ( const std::string &  lang)
inline

Sets the default language.

在文件 I18n.h 第 104 行定义.

◆ setLanguage()

bool eve::i18n::I18n::setLanguage ( const std::string &  lang)

Compatibility-only bool projection of selectLanguage.

在文件 I18n.cpp 第 471 行定义.

引用了 eve::Result< void >::ok() , 以及 selectLanguage().

◆ unload()

void eve::i18n::I18n::unload ( const std::string &  lang)

卸载 / 清空语言表。

在文件 I18n.cpp 第 459 行定义.

◆ update()

int eve::i18n::I18n::update ( float  dt)

Re-read changed locale files; returns the number of reloads performed.

在文件 I18n.cpp 第 657 行定义.

引用了 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.

参数
keyDot-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.

在文件 I18n.cpp 第 489 行定义.

引用了 eve::Diagnostic::error(), eve::Result< T >::failure(), hasInLanguage(), eve::InvalidArgument, key, eve::NotFound, offset , 以及 eve::Result< T >::success().


该类的文档由以下文件生成: