* A string that is already translated. * Using this class allows argument substitution in the translated strings. */
| 43 | * Using this class allows argument substitution in the translated strings. |
| 44 | */ |
| 45 | class LocalizedText |
| 46 | { |
| 47 | public: |
| 48 | /// Create from existing unicode string. |
| 49 | LocalizedText(const std::wstring &); |
| 50 | /// Create the empty string. |
| 51 | LocalizedText() : _text(L""), _nextArg(1) { /* Empty by design. */ } |
| 52 | /// Return constant wide string. |
| 53 | operator std::wstring const& () const OX_REQUIRED_RESULT; |
| 54 | /// Return the UTF-8 representation of this string. |
| 55 | std::string asUTF8() const OX_REQUIRED_RESULT; |
| 56 | /// Get a pointer to underlying wchat_t data. |
| 57 | const wchar_t *c_str() const OX_REQUIRED_RESULT { return _text.c_str(); } |
| 58 | |
| 59 | // Argument substitution. |
| 60 | /// Replace next argument. |
| 61 | LocalizedText arg(std::wstring const &) const OX_REQUIRED_RESULT; |
| 62 | /// Replace next argument. |
| 63 | LocalizedText &arg(std::wstring const &) OX_REQUIRED_RESULT; |
| 64 | /// Replace next argument. |
| 65 | template <typename T> LocalizedText arg(T) const OX_REQUIRED_RESULT; |
| 66 | /// Replace next argument. |
| 67 | template <typename T> LocalizedText &arg(T) OX_REQUIRED_RESULT; |
| 68 | private: |
| 69 | std::wstring _text; ///< The actual localized text. |
| 70 | unsigned _nextArg; ///< The next argument ID. |
| 71 | LocalizedText(const std::wstring &, unsigned); |
| 72 | }; |
| 73 | |
| 74 | /** |
| 75 | * Create a LocalizedText from a localized std::wstring. |