|
3 | 3 | #include "config.h" |
4 | 4 | #include "exports.h" |
5 | 5 |
|
6 | | -#include <MRMesh/MRMeshFwd.h> |
| 6 | +#include "MRMesh/MRId.h" |
7 | 7 |
|
8 | 8 | #include <string> |
9 | 9 | #include <string_view> |
|
12 | 12 | namespace MR::Locale |
13 | 13 | { |
14 | 14 |
|
15 | | -/// Information about locale domains. Contains the only field `id`. |
16 | | -/// The purpose of the struct is to resolve an ambiguous overload `translate( "str", "str", 0 )` |
17 | | -/// which otherwise could be treated as both "context, message, domain id" and "single, plural, number". |
18 | | -struct Domain |
19 | | -{ |
20 | | - int id = 0; |
21 | | -}; |
| 15 | +/// Locale domain internal identifier for MeshLib's own translations. |
| 16 | +constexpr inline LocaleDomainId cDefaultDomainId { 0 }; |
22 | 17 |
|
23 | 18 | /// \brief Translates a message using the active locale. |
24 | | -MRVIEWER_API std::string translate( std::string_view msg, Domain domain = {} ); |
| 19 | +MRVIEWER_API std::string translate( std::string_view msg, LocaleDomainId domainId = cDefaultDomainId ); |
25 | 20 |
|
26 | 21 | /// \brief Translates a message in context using the active locale. |
27 | | -MRVIEWER_API std::string translate( std::string_view context, std::string_view msg, Domain domain = {} ); |
| 22 | +MRVIEWER_API std::string translate( std::string_view context, std::string_view msg, LocaleDomainId domainId = cDefaultDomainId ); |
28 | 23 |
|
29 | 24 | /// \brief Translates a plural message form using the active locale. |
30 | | -MRVIEWER_API std::string translate( std::string_view single, std::string_view plural, Int64 n, Domain domain = {} ); |
| 25 | +MRVIEWER_API std::string translate( std::string_view single, std::string_view plural, Int64 n, LocaleDomainId domainId = cDefaultDomainId ); |
31 | 26 |
|
32 | 27 | /// \brief Translates a plural message form in context using the active locale. |
33 | | -MRVIEWER_API std::string translate( std::string_view context, std::string_view single, std::string_view plural, Int64 n, Domain domain = {} ); |
| 28 | +MRVIEWER_API std::string translate( std::string_view context, std::string_view single, std::string_view plural, Int64 n, LocaleDomainId domainId = cDefaultDomainId ); |
34 | 29 |
|
35 | 30 | /// \brief Translates all strings in a vector using the active locale. |
36 | | -inline std::vector<std::string> translateAll( const std::vector<std::string>& items, Domain domain = {} ) |
| 31 | +inline std::vector<std::string> translateAll( const std::vector<std::string>& items, LocaleDomainId domainId = cDefaultDomainId ) |
37 | 32 | { |
38 | 33 | std::vector<std::string> result; |
39 | 34 | result.reserve( items.size() ); |
40 | 35 | for ( const auto& s : items ) |
41 | | - result.push_back( translate( s, domain ) ); |
| 36 | + result.push_back( translate( s, domainId ) ); |
42 | 37 | return result; |
43 | 38 | } |
44 | 39 |
|
45 | 40 | /// \brief Translates all strings in a vector with context using the active locale. |
46 | | -inline std::vector<std::string> translateAll( const char* context, const std::vector<std::string>& items, Domain domain = {} ) |
| 41 | +inline std::vector<std::string> translateAll( const char* context, const std::vector<std::string>& items, LocaleDomainId domainId = cDefaultDomainId ) |
47 | 42 | { |
48 | 43 | std::vector<std::string> result; |
49 | 44 | result.reserve( items.size() ); |
50 | 45 | for ( const auto& s : items ) |
51 | | - result.push_back( translate( context, s, domain ) ); |
| 46 | + result.push_back( translate( context, s, domainId ) ); |
52 | 47 | return result; |
53 | 48 | } |
54 | 49 |
|
|
0 commit comments