xtd 0.2.0
Loading...
Searching...
No Matches
xtd::translator Class Referencefinal
Inheritance diagram for xtd::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/forms/application>
#include <xtd/forms/button>
#include <xtd/forms/form>
#include <xtd/forms/label>
#include <xtd/forms/message_box>
#include <xtd/translator>
#include <locale>
using namespace xtd;
using namespace xtd::forms;
class form1 : public form {
public:
form1() {
text("Translator example"_t);
client_size({500, 300});
controls().push_back_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 {
try {
//translator::locale("ar_MA");
//translator::locale("es_ES");
//translator::locale("fr_FR");
} catch (const std::exception& e) {
message_box::show(ustring::format("Make sure specified locale is installed on your system :\n\n{}", e.what()), "Exception");
return -1;
}
application::run(form1 {});
}
Represents a Windows button control.
Definition button.h:47
Represents a window or dialog box that makes up an application's user interface.
Definition form.h:52
Represents a standard Windows label.
Definition label.h:36
static std::locale locale()
Gets the global locale.
static ustring format(const ustring &fmt, args_t &&... args)
Writes the text representation of the specified arguments list, to string using the specified format ...
Definition ustring.h:1131
@ e
The E key.
The xtd::forms namespace contains classes for creating Windows-based applications that take full adva...
Definition xtd_about_box.h:12
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h:10
# 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::ustring language ()
 Gets the current application language.
 
static void language (const xtd::ustring &language)
 Sets the current application language.
 
static std::locale locale ()
 Gets the global locale.
 
static void locale (const xtd::ustring &value)
 Sets the global locale.
 
static void locale (const std::locale &value)
 Sets the global locale.
 
static std::vector< xtd::ustringlanguages ()
 Gets an array of languages supported by the application.
 
static xtd::ustring system_language ()
 Gets the current system language.
 

Public Static Methods

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

Member Function Documentation

◆ add_value()

static void xtd::translator::add_value ( const xtd::ustring language,
const xtd::ustring key,
const xtd::ustring value 
)
static

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.

◆ language() [1/2]

static xtd::ustring xtd::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/2]

static void xtd::translator::language ( const xtd::ustring language)
static

Sets the current application language.

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

◆ languages()

static std::vector< xtd::ustring > xtd::translator::languages ( )
static

Gets an array of languages supported by the application.

Returns
An array of languages supported by the application.

◆ locale() [1/3]

static std::locale xtd::translator::locale ( )
static

Gets the global locale.

Returns
The global locale.
Remarks
is same a call std::locale {};

◆ locale() [2/3]

static void xtd::translator::locale ( const std::locale &  value)
static

Sets the global locale.

Parameters
valueThe global locale.
Remarks
is same a call std::locale::global(value);

◆ locale() [3/3]

static void xtd::translator::locale ( const xtd::ustring value)
static

Sets the global locale.

Parameters
valueThe global locale.
Remarks
is same a call std::locale::global(std::locale {value});

◆ parse_file()

static void xtd::translator::parse_file ( const xtd::ustring file,
const xtd::ustring 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.

◆ parse_locale()

static void xtd::translator::parse_locale ( const xtd::ustring locale_path)
static

Parses a specified path that contains translations.

Parameters
locale_pathPath that contains translations.

◆ system_language()

static xtd::ustring xtd::translator::system_language ( )
static

Gets the current system language.

Returns
The current system language.

◆ translate() [1/2]

static xtd::ustring xtd::translator::translate ( const xtd::ustring language,
const xtd::ustring value 
)
staticnoexcept

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.

◆ translate() [2/2]

static xtd::ustring xtd::translator::translate ( const xtd::ustring value)
staticnoexcept

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.

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