Utils / LanguageUtil
LanguageUtil Class
Multilingual tools
Table of contents
Methods
addKey(textkey : string ): string other |
---|
Multilingual tagging |
getDefaultLocale(): string other |
Get the default language and region |
getText(textkey : string ): string other |
Retrieve translation content based on key |
getlanguage(): LanguageCodeType other |
Get the current localized language |
setLanguage(type : LanguageCodeType ): boolean other |
Game language settings |
Methods
addKey
• Static
addKey(textkey
): string
other
Multilingual tagging
Parameters
textkey string | Usage: Key range collected from user multilingual configuration table: No restrictions |
---|
Returns
string | Returns the Key. This function is only used to translate text and collect identifiers. |
---|
getDefaultLocale
• Static
getDefaultLocale(): string
other
Get the default language and region
Returns
string | Optional ISO 3166-1 country code (e.g. "CN") |
---|
Usage example: create a script named LocaleExample, place it in the object bar, open the script, modify the original content to the following, save and run the game, and the log will output the default language and region
ts
@Component
export default class LocaleExample extends Script {
protected onStart(): void {
if (!SystemUtil.isClient()) return;
this.test();
}
private async test(): Promise<void> {
const locale = LocaleUtil.getDefaultLocale();
console.log(`locale: ${locale}`);
// zh-CN
}
}
@Component
export default class LocaleExample extends Script {
protected onStart(): void {
if (!SystemUtil.isClient()) return;
this.test();
}
private async test(): Promise<void> {
const locale = LocaleUtil.getDefaultLocale();
console.log(`locale: ${locale}`);
// zh-CN
}
}
getText
• Static
getText(textkey
): string
other
Retrieve translation content based on key
Parameters
textkey string | Usage: The key range for the translation to be searched is not restricted |
---|
Returns
string | Return the translation content of the current language environment corresponding to the Key |
---|
getlanguage
• Static
getlanguage(): LanguageCodeType
other
Get the current localized language
Returns
LanguageCodeType | Language enumeration object |
---|
setLanguage
• Static
setLanguage(type
): boolean
other
Game language settings
Parameters
type LanguageCodeType | Usage: Switch game language types |
---|
Returns
boolean | True modification successful false modification failed |
---|