lxgui
|
Utility class to translate strings for display in GUI. More...
#include <gui_localizer.hpp>
Public Member Functions | |
localizer () | |
Default constructor. | |
localizer (const localizer &)=delete | |
localizer (localizer &&)=delete | |
localizer & | operator= (const localizer &)=delete |
localizer & | operator= (localizer &&)=delete |
void | set_locale (const std::locale &locale) |
Changes the current locale (used to format numbers). | |
void | set_preferred_languages (const std::vector< std::string > &languages) |
Changes the current language (used to translate messages and strings). | |
void | auto_detect_preferred_languages () |
Attempts to automatically detect the current language (used to translate messages and. | |
const std::locale & | get_locale () const |
Returns the current locale (used to format numbers). | |
const std::vector< std::string > & | get_preferred_languages () const |
Returns the list of code names of the preferred languages (used to translate messages and. | |
void | clear_allowed_code_points () |
Removes all allowed code points. | |
void | add_allowed_code_points (const code_point_range &range) |
Adds a new range to the set of allowed code points. | |
void | add_allowed_code_points_for_group (const std::string &unicode_group) |
Adds a new range to the set of allowed code points from a Unicode group. | |
void | add_allowed_code_points_for_language (const std::string &language_code) |
Adds a new range to the set of allowed code points for a given language. | |
void | auto_detect_allowed_code_points () |
Attempts to automatically detect the set of allowed code points based on preferred. | |
const std::vector< code_point_range > & | get_allowed_code_points () const |
Returns the list of allowed code points (Unicode characters), for text rendering. | |
void | set_fallback_code_point (char32_t code_point) |
Sets the default character to display if a character is missing from a font. | |
char32_t | get_fallback_code_point () const |
Returns the default character to display if a character is missing from a font. | |
void | load_translations (const std::string &folder_path) |
Loads new translations from a folder, selecting the language automatically. | |
void | load_translation_file (const std::string &file_name) |
Loads new translations from a file. | |
void | clear_translations () |
Removes all previously loaded translations. | |
std::string | format_string (std::string_view message, sol::variadic_args args) const |
Translates a string with a certain number of arguments from Lua (zero or many). | |
template<typename... Args> | |
std::string | format_string (std::string_view message, Args &&... args) const |
Translates a string with a certain number of arguments from C++ (zero or many). | |
std::string | localize (std::string_view key, sol::variadic_args args) const |
Translates a string with a certain number of arguments from Lua (zero or many). | |
template<typename... Args> | |
std::string | localize (std::string_view key, Args &&... args) const |
Translates a string with a certain number of arguments from C++ (zero or many). | |
void | register_on_lua (sol::state &lua) |
Registers this localizer on a Lua state. | |
Utility class to translate strings for display in GUI.
Definition at line 20 of file gui_localizer.hpp.
lxgui::gui::localizer::localizer | ( | ) |
Default constructor.
Definition at line 79 of file gui_localizer.cpp.
|
delete |
|
delete |
void lxgui::gui::localizer::add_allowed_code_points | ( | const code_point_range & | range | ) |
Adds a new range to the set of allowed code points.
range | The new range to allow |
Definition at line 149 of file gui_localizer.cpp.
void lxgui::gui::localizer::add_allowed_code_points_for_group | ( | const std::string & | unicode_group | ) |
Adds a new range to the set of allowed code points from a Unicode group.
unicode_group | The name of the Unicode code group to allow |
Definition at line 184 of file gui_localizer.cpp.
void lxgui::gui::localizer::add_allowed_code_points_for_language | ( | const std::string & | language_code | ) |
Adds a new range to the set of allowed code points for a given language.
language_code | The language code (e.g., "en", "ru", etc.) |
Definition at line 464 of file gui_localizer.cpp.
void lxgui::gui::localizer::auto_detect_allowed_code_points | ( | ) |
Attempts to automatically detect the set of allowed code points based on preferred.
languages.
Definition at line 670 of file gui_localizer.cpp.
void lxgui::gui::localizer::auto_detect_preferred_languages | ( | ) |
Attempts to automatically detect the current language (used to translate messages and.
strings).
Definition at line 133 of file gui_localizer.cpp.
void lxgui::gui::localizer::clear_allowed_code_points | ( | ) |
Removes all allowed code points.
Definition at line 145 of file gui_localizer.cpp.
void lxgui::gui::localizer::clear_translations | ( | ) |
Removes all previously loaded translations.
Definition at line 769 of file gui_localizer.cpp.
|
inline |
Translates a string with a certain number of arguments from C++ (zero or many).
message | The string to format (e.g., "Player {0} has {1} HP."). |
args | A variadic list of formatting input arguments. |
The string to format must follow the rules of libfmt format strings.
Definition at line 197 of file gui_localizer.hpp.
std::string lxgui::gui::localizer::format_string | ( | std::string_view | message, |
sol::variadic_args | args | ||
) | const |
Translates a string with a certain number of arguments from Lua (zero or many).
message | The string to format (e.g., "Player {0} has {1} HP."). |
args | A variadic list of formatting input arguments from a Sol Lua state. |
The string to format must follow the rules of libfmt format strings.
Definition at line 782 of file gui_localizer.cpp.
const std::vector< code_point_range > & lxgui::gui::localizer::get_allowed_code_points | ( | ) | const |
Returns the list of allowed code points (Unicode characters), for text rendering.
Definition at line 691 of file gui_localizer.cpp.
char32_t lxgui::gui::localizer::get_fallback_code_point | ( | ) | const |
Returns the default character to display if a character is missing from a font.
Definition at line 699 of file gui_localizer.cpp.
const std::locale & lxgui::gui::localizer::get_locale | ( | ) | const |
Returns the current locale (used to format numbers).
Definition at line 137 of file gui_localizer.cpp.
const std::vector< std::string > & lxgui::gui::localizer::get_preferred_languages | ( | ) | const |
Returns the list of code names of the preferred languages (used to translate messages and.
strings).
Definition at line 141 of file gui_localizer.cpp.
void lxgui::gui::localizer::load_translation_file | ( | const std::string & | file_name | ) |
Loads new translations from a file.
file_name | The path to the file to load translations from |
Definition at line 736 of file gui_localizer.cpp.
void lxgui::gui::localizer::load_translations | ( | const std::string & | folder_path | ) |
Loads new translations from a folder, selecting the language automatically.
folder_path | The path to the folder to load translations from |
Definition at line 703 of file gui_localizer.cpp.
|
inline |
Translates a string with a certain number of arguments from C++ (zero or many).
key | The key identifying the sentence / text to translate (e.g., "{player_health}"). Must start with '{' and end with '}'. |
args | A variadic list of translation input arguments. |
This function will search the translation database (created from loading translations with load_translations() or load_translation_file()) for a string matching key. If one is found, it will forward the supplied arguments to the translated formatting function, which will insert the arguments at the proper place for the selected language.
Definition at line 224 of file gui_localizer.hpp.
std::string lxgui::gui::localizer::localize | ( | std::string_view | key, |
sol::variadic_args | args | ||
) | const |
Translates a string with a certain number of arguments from Lua (zero or many).
key | The key identifying the sentence / text to translate (e.g., "{player_health}"). Must start with '{' and end with '}'. |
args | A variadic list of translation input arguments from a Sol Lua state. |
Definition at line 803 of file gui_localizer.cpp.
void lxgui::gui::localizer::register_on_lua | ( | sol::state & | lua | ) |
Registers this localizer on a Lua state.
lua | The Lua lua to register on |
void lxgui::gui::localizer::set_fallback_code_point | ( | char32_t | code_point | ) |
Sets the default character to display if a character is missing from a font.
code_point | The Unicode UTF-32 code point of the character to display |
Definition at line 695 of file gui_localizer.cpp.
void lxgui::gui::localizer::set_locale | ( | const std::locale & | locale | ) |
Changes the current locale (used to format numbers).
locale | The new locale |
Definition at line 110 of file gui_localizer.cpp.
void lxgui::gui::localizer::set_preferred_languages | ( | const std::vector< std::string > & | languages | ) |
Changes the current language (used to translate messages and strings).
languages | A list of languages |
This function specifies which languages to use for translating messages. The languages listed in the supplied array will be tried one after the other, until a translation is found. Each language in the list must be formatted as "{language}{REGION}" with "{language}" a two-letter lower case word, and "{REGION}" a two-letter upper case word. For example: "enUS" for United State English, and "enGB" for British English, "frFR" for mainland French, etc. The default value is {"enUS"}.
Definition at line 118 of file gui_localizer.cpp.