template<typename RootFactory, typename DefaultLanguageID, typename... SupportedLanguageIDs>
class arg_router::multi_lang::root_t< RootFactory, DefaultLanguageID, SupportedLanguageIDs >
Provides multi-language support by instantiating an arg_router::root_t for a given language ID.
This relies on the use of multi_lang::translation to provide compile-time selection of language variants for strings. The user needs to specialise multi_lang::translation for DefaultLanguageID and each supported ID in SupportedLanguageIDs.
namespace arp = ar::policy;
namespace ar::multi_lang
{
template <>
class translation<
S_("en_GB")>
{
public:
using force =
S_(
"force");
using force_description =
S_(
"Force overwrite existing files");
...
};
template <>
class translation<
S_("fr")>
{
public:
using force =
S_(
"forcer");
using force_description =
S_(
"Forcer l'écrasement des fichiers existants");
...
};
template <>
class translation<
S_("ja")>
{
public:
using force_description =
S_(
"既存のファイルを強制的に上書きする");
...
};
}
ar::multi_lang::root<
S_(
"en_GB"),
S_(
"fr"),
S_(
"ja")>(
ar::multi_lang::iso_locale(std::locale("").name()),
[&](auto tr_) {
using tr = decltype(tr_);
const auto common_args = ar::list{
ar::flag(arp::long_name<typename tr::force>,
arp::short_name<'f'>,
arp::description<typename tr::force_description>),
...
As shown by the above example, the supported translation object is given to the function object that returns the root instance. This means that each use of translation specialisation must have the same number of language-specific compile-time strings.
RootFactory is a function object used to return a given root type from a supported language ID, its signature must be equivalent to:
template <typename ID>
auto operator()(multi_lang::translation<ID> I) {
...
};
The DefaultLanguageID and SupportedLanguageIDs parameters can be any set of unique compile-time strings, but as they are compared against an input that would usually come from std::locale()
, then ISO language codes are least troublesome and easiest to read.
- Template Parameters
-
RootFactory | Function object type that accepts a multi_lang::translation specialisation and returns a root instance |
DefaultLanguageID | The default language ID as a compile time string, this is used if the runtime input code does not match this or any of SupportedLanguageIDs |
SupportedLanguageIDs | The supported language IDs as compile time strings |
Definition at line 90 of file root.hpp.
template<typename RootFactory , typename DefaultLanguageID , typename... SupportedLanguageIDs>
template<typename Container , typename = std::enable_if_t< !std::is_same_v<std::decay_t<Container>, vector<parsing::token_type>>>>
Calls the parse method on the selected root.
The first element is not expected to be the executable name.
- Note
- This does not take part in overload resolution if c is a
vector<parsing::token_type>
- Template Parameters
-
- Parameters
-
Definition at line 167 of file root.hpp.
template<typename RootFactory , typename DefaultLanguageID , typename... SupportedLanguageIDs>
template<typename Iter , typename = std::enable_if_t<!std::is_same_v<std::decay_t<Iter>, int>>>
Calls the parse method on the selected root.
The first element is not expected to be the executable name.
- Note
- The strings must out live the parse process as they are not copied.
- Template Parameters
-
Iter | Iterator type to std::string_view convertible elements |
- Parameters
-
begin | Iterator to the first element |
end | Iterator to the one-past-the-end element |
Definition at line 151 of file root.hpp.