xtd 0.2.0
Loading...
Searching...
No Matches
xtd::globalization::translator Class Referencefinal
Inheritance diagram for xtd::globalization::translator:
xtd::static_object

Definition

Represents translator class. This class cannot be inherited.

Namespace
xtd
Library
xtd.core
Remarks
This class is used to translate an application into different languages.
For more information about internationalization, see Internationalizations.
Examples
The following shows how to use translator with std::locale method, litteral operator _t and translation files.
#include <xtd/xtd>
using namespace xtd::globalization;
class form1 : public form {
public:
form1() {
text("Translator example"_t);
client_size({500, 300});
controls().add_range({open_button, close_button, text_label});
open_button.location({10, 10});
open_button.text("Open"_t);
close_button.location({100, 10});
close_button.text("Close"_t);
text_label.location({10, 50});
text_label.auto_size(true);
text_label.text("The quick brown fox jumps over the lazy dog."_t);
}
private:
button open_button;
button close_button;
label text_label;
};
auto main() -> int {
//culture_info::current_culture(culture_info {"ar-MA"});
//culture_info::current_culture(culture_info {"es-ES"});
//culture_info::current_culture(culture_info {"ru-RU"});
application::run(form1 {});
}
Provides information about a specific culture (called a locale for unmanaged code development)....
Definition culture_info.hpp:43
static culture_info current_culture() noexcept
Gets the xtd::globalization::culture_info object that represents the culture used by the current appl...
xtd::forms::style_sheets::control label
The label data allows you to specify the box of a label control.
Definition label.hpp:25
xtd::forms::style_sheets::control button
The buttton data allows you to specify the box of a button control.
Definition button.hpp:25
Contains classes that define culture-related information, including language, country/region,...
Definition culture_info.hpp:20
Contains classes that represent ASCII and Unicode character encodings; abstract base classes for conv...
Definition basic_string_builder.hpp:17
# Main window caption
key "Translator example"
value "Пример перевода"
# Open button text
key "Open"
value "Oткрыто"
# Close button text
key "Close"
value "Закрыть"
# Label text
key "The quick brown fox jumps over the lazy dog."
value "Быстрый коричневый лис перепрыгивает через ленивого пса."

Public Static Properties

static xtd::string language ()
 Gets the current application language.
 
static void language (const xtd::string &language)
 Sets the current application language.
 
static void language (xtd::null_ptr)
 Sets the current application language.
 
static xtd::array< xtd::stringlanguages ()
 Gets an array of languages supported by the application.
 
static xtd::string system_language ()
 Gets the current system language.
 

Public Static Methods

static void add_value (const xtd::string &language, const xtd::string &key, const xtd::string &value)
 Manually adds a translation for a specified key and language.
 
static bool parse_locale (const xtd::string &locale_path)
 Parses a specified path that contains translations.
 
static bool parse_locale (const xtd::string &locale_path, const xtd::string &language)
 Parses a specified path that contains translations.
 
static bool parse_file (const xtd::string &file)
 Parses a specified file that contains translations for a specified language.
 
static bool parse_file (const xtd::string &file, const xtd::string &language)
 Parses a specified file that contains translations for a specified language.
 
static xtd::string translate (const xtd::string &value) noexcept
 Translates a string into the lganguage specified by the xtd::translate::language property.
 
static xtd::string translate (const xtd::string &language, const xtd::string &value) noexcept
 Translates a string into the specified lganguage.
 

Member Function Documentation

◆ language() [1/3]

static xtd::string xtd::globalization::translator::language ( )
static

Gets the current application language.

Returns
The current application language.
Remarks
By default language is initialized with the current system language.

◆ language() [2/3]

static void xtd::globalization::translator::language ( const xtd::string & language)
static

Sets the current application language.

Parameters
languageThe current application language.
Remarks
Normally you should use the xtd::globalization::culture_info::current_culture property. This function only exists if you have a good reason to bypass xtd::globalization::culture_info::current_culture.
Warning
If you set the language with this method, and you use the xtd::globalization::culture_info::current_culture property afterwards, translator will use the language initialized with this method and not with xtd::globalization::culture_info::current_culture.

◆ language() [3/3]

static void xtd::globalization::translator::language ( xtd::null_ptr )
static

Sets the current application language.

Parameters
languageThe current application language.
Remarks
Normally you should use the xtd::globalization::culture_info::current_culture property. This function only exists if you have a good reason to bypass xtd::globalization::culture_info::current_culture.
Warning
If you set the language with this method, and you use the xtd::globalization::culture_info::current_culture property afterwards, translator will use the language initialized with this method and not with xtd::globalization::culture_info::current_culture.

◆ languages()

static xtd::array< xtd::string > xtd::globalization::translator::languages ( )
static

Gets an array of languages supported by the application.

Returns
An array of languages supported by the application.

◆ system_language()

static xtd::string xtd::globalization::translator::system_language ( )
static

Gets the current system language.

Returns
The current system language.

◆ add_value()

static void xtd::globalization::translator::add_value ( const xtd::string & language,
const xtd::string & key,
const xtd::string & value )
inlinestatic

Manually adds a translation for a specified key and language.

Parameters
languageThe language of the key to be translated.
keyThe key to be translated. @parama value The translation of the key for the specified language.
Warning
This method should not be used. The translation is normally done automatically. This method is present only if you want to make an instant translation on a very small number of keys. It would not be wise to translate an entire application into different languages with this method.

◆ parse_locale() [1/2]

static bool xtd::globalization::translator::parse_locale ( const xtd::string & locale_path)
static

Parses a specified path that contains translations.

Parameters
locale_pathPath that contains translations.
Returns
true if parse succeed; otherwhise false.
Remarks
parse path with xtd::globalization::translator::language() language.

◆ parse_locale() [2/2]

static bool xtd::globalization::translator::parse_locale ( const xtd::string & locale_path,
const xtd::string & language )
static

Parses a specified path that contains translations.

Parameters
locale_pathPath that contains translations.
Returns
true if parse succeed; otherwhise false.

◆ parse_file() [1/2]

static bool xtd::globalization::translator::parse_file ( const xtd::string & file)
static

Parses a specified file that contains translations for a specified language.

Parameters
fileThe file that contains translations.
Returns
true if parse succeed; otherwhise false.
Remarks
parse file with xtd::globalization::translator::language() language.

◆ parse_file() [2/2]

static bool xtd::globalization::translator::parse_file ( const xtd::string & file,
const xtd::string & language )
static

Parses a specified file that contains translations for a specified language.

Parameters
fileThe file that contains translations.
languageThe language of the translation file.
Returns
true if parse succeed; otherwhise false.

◆ translate() [1/2]

static xtd::string xtd::globalization::translator::translate ( const xtd::string & value)
inlinestaticnoexcept

Translates a string into the lganguage specified by the xtd::translate::language property.

Returns
The translated string.
Remarks
If no translation is found, the result is the same as the value.

◆ translate() [2/2]

static xtd::string xtd::globalization::translator::translate ( const xtd::string & language,
const xtd::string & value )
inlinestaticnoexcept

Translates a string into the specified lganguage.

Returns
The translated string.
Parameters
languageThe language used to translate the value
Remarks
If no translation is found, the result is the same as the value.

The documentation for this class was generated from the following file: