arg_router  1.4.0
C++ command line argument parsing and routing
arg_router::multi_lang Namespace Reference

Classes

class  root_t
 
class  root_wrapper_t
 
class  translation
 

Typedefs

template<std::size_t I, typename... S>
using string_selector = std::tuple_element_t< I, std::tuple< S... > >
 

Functions

string iso_locale (std::string_view locale_name)
 
template<typename DefaultLanguageID , typename... SupportedLanguageIDs, typename RootFactory >
auto root (std::string_view language_id, const RootFactory &f)
 
template<typename... SupportedISOLanguageCodes, typename Fn >
auto root_wrapper (std::string_view iso_language, Fn &&f)
 

Detailed Description

Namespace for types and functions relating to runtime multi-language support.

Typedef Documentation

◆ string_selector

template<std::size_t I, typename... S>
using arg_router::multi_lang::string_selector = typedef std::tuple_element_t<I, std::tuple<S...> >

A compile time string container that acts a drop-in replacement for compile_time_string by compile-time selection of an element.

Template Parameters
IString index to use
SStrings to contain

Definition at line 25 of file string_selector.hpp.

Function Documentation

◆ iso_locale()

string arg_router::multi_lang::iso_locale ( std::string_view  locale_name)
inline

Converts a locale name (i.e. a string returned by std::locale) into a standardised language code format.

The most common locale formats are:

<Lowercase ISO 639-1 language>_<Uppercase ISO 3166 country>.<encoding>
<Lowercase ISO 639-1 language>-<Uppercase ISO 3166 country>
<Lowercase ISO 639-1 language>-<Initial uppercase ISO 15924 script>-<Uppercase ISO 3166 country>

This function will strip off the encoding if present, and change the dividing character to an underscore. For example:

iso_country_code("en-US") == "en_US"
iso_country_code("en_GB.UTF-8") == "en_GB"
iso_country_code("fr.UTF-8") == "fr"
iso_country_code("uz-Latn-UZ") == "uz_Latn_UZ"

An empty string in yields an empty string out.

Typically locale_name is under the SSO string size, so allocation doesn't occur.

Parameters
locale_nameLocal name to standardise
Returns
Standardised locale name

Definition at line 35 of file iso_locale.hpp.

◆ root()

template<typename DefaultLanguageID , typename... SupportedLanguageIDs, typename RootFactory >
auto arg_router::multi_lang::root ( std::string_view  language_id,
const RootFactory &  f 
)

Convenience function that returns a root_t.

Allows the user to define the supported languages IDs in the template parameters but has Fn deduced from the input.

Template Parameters
DefaultLanguageIDThe default language ID as a compile time string, this is used if the runtime input code does not match this or any of SupportedLanguageIDs
SupportedLanguageIDsThe supported language IDs as compile time strings
RootFactoryFunction object type that accepts a multi_lang::translation specialisation and returns a root instance
Parameters
language_idThe runtime language selection, if it doesn't match any of the SupportedLanguageIDs, then DefaultLanguageID is used
fFunction object that returns the root instance for a given supported language
Returns
root_t instance

Definition at line 221 of file root.hpp.

◆ root_wrapper()

template<typename... SupportedISOLanguageCodes, typename Fn >
auto arg_router::multi_lang::root_wrapper ( std::string_view  iso_language,
Fn &&  f 
)

Convenience function that returns a root_wrapper_t.

Allows the user to define the supported ISO languages in the template parameters but has Fn deduced from the input.

Parameters
iso_languageThe runtime language selection, if it doesn't match any of SupportedISOLanguageCodes, then the first language in SupportedISOLanguageCodes is used
fFunction object that returns the root instance for a given supported language index
Returns
root_wrapper_t instance

Definition at line 153 of file root_wrapper.hpp.