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(string::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.hpp:49
Represents a window or dialog box that makes up an application's user interface.
Definition form.hpp:54
Represents a standard Windows label.
Definition label.hpp:38
static std::locale locale()
Gets the global locale.
static basic_string format(const basic_string< char > &fmt, args_t &&... args)
Writes the text representation of the specified arguments list, to string using the specified format ...
@ e
The E key.
The xtd::forms namespace contains classes for creating Windows-based applications that take full adva...
Definition xtd_about_box.hpp:12
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.hpp: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::string language ()
 Gets the current application language.
 
static void language (const xtd::string &language)
 Sets the current application language.
 
static std::locale locale ()
 Gets the global locale.
 
static void locale (const xtd::string &value)
 Sets the global locale.
 
static void locale (const std::locale &value)
 Sets the global locale.
 
static std::vector< 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 void parse_locale (const xtd::string &locale_path)
 Parses a specified path that contains translations.
 
static void 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/2]

static xtd::string 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::string 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().

◆ 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 xtd::string value)
static

Sets the global locale.

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

◆ locale() [3/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);

◆ languages()

static std::vector< xtd::string > xtd::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::translator::system_language ( )
static

Gets the current system language.

Returns
The current system language.

◆ add_value()

static void xtd::translator::add_value ( const xtd::string language,
const xtd::string key,
const xtd::string 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.

◆ parse_locale()

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

Parses a specified path that contains translations.

Parameters
locale_pathPath that contains translations.

◆ parse_file()

static void xtd::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.

◆ translate() [1/2]

static xtd::string xtd::translator::translate ( const xtd::string 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.

◆ translate() [2/2]

static xtd::string xtd::translator::translate ( const xtd::string language,
const xtd::string 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.

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