MeshLib C++ Docs
Loading...
Searching...
No Matches
MRI18n.h
Go to the documentation of this file.
1#pragma once
2
3#include "config.h"
4#include "exports.h"
5
6#include "MRMesh/MRId.h"
7
8#include <string>
9#include <string_view>
10#include <vector>
11
12namespace MR::Locale
13{
14
16constexpr inline LocaleDomainId defaultDomain { 0 };
18constexpr inline LocaleDomainId genericDomain { -2 };
19
21MRVIEWER_API std::string translate( std::string_view msg, LocaleDomainId domainId = defaultDomain );
22
24MRVIEWER_API std::string translate( std::string_view context, std::string_view msg, LocaleDomainId domainId = defaultDomain );
25
27MRVIEWER_API std::string translate( std::string_view single, std::string_view plural, std::int64_t n, LocaleDomainId domainId = defaultDomain );
28
30MRVIEWER_API std::string translate( std::string_view context, std::string_view single, std::string_view plural, std::int64_t n, LocaleDomainId domainId = defaultDomain );
31
33inline std::vector<std::string> translateAll( const std::vector<std::string>& items, LocaleDomainId domainId = defaultDomain )
34{
35 std::vector<std::string> result;
36 result.reserve( items.size() );
37 for ( const auto& s : items )
38 result.push_back( translate( s, domainId ) );
39 return result;
40}
41
43inline std::vector<std::string> translateAll( const char* context, const std::vector<std::string>& items, LocaleDomainId domainId = defaultDomain )
44{
45 std::vector<std::string> result;
46 result.reserve( items.size() );
47 for ( const auto& s : items )
48 result.push_back( translate( context, s, domainId ) );
49 return result;
50}
51
52}
53
54#ifndef MR_NO_I18N_MACROS
55#define _tr( ... ) MR::Locale::translate( __VA_ARGS__ ).c_str()
56#define s_tr( ... ) MR::Locale::translate( __VA_ARGS__ )
57#define f_tr( ... ) fmt::runtime( MR::Locale::translate( __VA_ARGS__ ) )
58#endif
Definition MRMeshFwd.h:803
constexpr LocaleDomainId defaultDomain
Locale domain internal identifier for MeshLib's own translations.
Definition MRI18n.h:16
std::vector< std::string > translateAll(const std::vector< std::string > &items, LocaleDomainId domainId=defaultDomain)
Translates all strings in a vector using the active locale.
Definition MRI18n.h:33
constexpr LocaleDomainId genericDomain
Locale domain internal identifier for cross-domain translations.
Definition MRI18n.h:18
std::string translate(std::string_view msg, LocaleDomainId domainId=defaultDomain)
Translates a message using the active locale.