NDEVR
API Documentation
TranslatedString.h
1#pragma once
2#include "DLLInfo.h"
3#include <NDEVR/String.h>
4#include <NDEVR/Buffer.h>
5#include <NDEVR/UUID.h>
6namespace NDEVR
7{
15 class NDEVR_BASE_API TranslatedString
16 {
17 public:
40 explicit TranslatedString(const StringView& raw_string);
46 TranslatedString(const UUID& translation_id, const StringView& english);
66 String translation(const String& language) const;
71 const UUID& translationID() const;
76 const String readableID() const;
81 void replaceVals(String& value) const;
87 bool canReplaceInTranslation(const StringView& id) const;
93 static TranslatedString DirectString(const StringView& sub_string);
100 TranslatedString& replace(const StringView& sub_string, const TranslatedString& replacement);
107 TranslatedString& replace(const StringView& sub_string, const StringView& replacement);
112 bool isTranslatable() const;
117 bool hasReplacements() const;
122 bool isEmpty() const;
127 const String& englishDefine() const;
162 bool operator<(const TranslatedString& value) const;
168 bool operator>(const TranslatedString& value) const;
174 static void AppendTranslated(const StringView& raw_string, String& string);
175 private:
179 void calculateEnglishString();
180 //operator+=()
181 private:
182 Buffer<TranslatedString*> m_replacements;
183 String m_replace_buff;
184 String m_english_string;
185 mutable String m_translation;
186 UUID m_translation_id = Constant<UUID>::Invalid;
187 };
188
193 template<class t_type>
195 {
198 return s;
199 }
200
203 template<> inline const TranslatedString Constant<TranslatedString>::Invalid = TranslatedString();
204}
205
206namespace std//Define things to allow use within std libs
207{
211 template <>
212 struct hash<NDEVR::TranslatedString>
213 {
219 std::size_t operator()(const TranslatedString& s) const noexcept
220 {
221 return static_cast<size_t>(s.translationID().hash());
222 }
223 };
224};
The equivelent of std::vector but with a bit more control.
Definition Buffer.hpp:58
static void toDisplayString(const t_type &value, TranslatedString &string)
Logic for converting an object to an NDEVR API translated, user facing string.
The core String View class for the NDEVR API.
Definition StringView.h:58
The core String class for the NDEVR API.
Definition String.h:95
static TranslatedString DisplayString(const t_type &value)
Converts an object into a TranslatedString.
Any text displayed to the user should be defined as a TranslatedString which allows the program to lo...
String englishTranslation() const
Returns the English translation of this string.
void replaceVals(String &value) const
Applies all stored replacement values to the given string, substituting placeholders.
bool hasReplacements() const
Checks whether this string has any placeholder replacements applied.
String internalValue() const
Returns the internal representation of this translated string, including replacement markers.
TranslatedString(const TranslatedString &translation)
Copy constructor.
TranslatedString(TranslatedString &&translation) noexcept
Move constructor.
TranslatedString & replace(const StringView &sub_string, const StringView &replacement)
Replaces occurrences of a placeholder substring with a raw string replacement.
bool operator>(const TranslatedString &value) const
Greater-than comparison operator, compares by English translation.
TranslatedString(const StringView &raw_string)
Constructs a TranslatedString from a raw string, computing a translation ID from the content.
const String readableID() const
Returns a human-readable identifier for this translated string, useful for debugging.
bool operator==(const TranslatedString &translation) const
Equality comparison operator.
bool isTranslatable() const
Checks whether this string has a translation ID and can be translated.
String translation(const String &language) const
Returns the translation of this string for a specific language.
~TranslatedString()
Destructor.
bool isEmpty() const
Checks whether this translated string is empty (has no English text or translation).
const String & englishDefine() const
Returns the original English definition string.
bool canReplaceInTranslation(const StringView &id) const
Checks whether the given identifier exists as a replaceable placeholder in this translation.
static TranslatedString DirectString(const StringView &sub_string)
If a string does not have a translation (EG: reading from an already translated string) this operatio...
TranslatedString & operator=(const TranslatedString &translation) noexcept
Copy assignment operator.
void retranslate()
Forces a retranslation of the cached translated string using the current language setting.
StringView translation() const
Returns the translated string for the current application language.
TranslatedString & replace(const StringView &sub_string, const TranslatedString &replacement)
Replaces occurrences of a placeholder substring with a translated replacement.
TranslatedString & operator=(TranslatedString &&translation) noexcept
Move assignment operator.
const UUID & translationID() const
Returns the UUID that identifies this translatable string in the translation database.
bool operator<(const TranslatedString &value) const
Less-than comparison operator, compares by English translation.
TranslatedString(const UUID &translation_id, const StringView &english)
Constructs a TranslatedString with an explicit translation ID and English text.
bool operator!=(const TranslatedString &translation) const
Inequality comparison operator.
static void AppendTranslated(const StringView &raw_string, String &string)
Appends the translated version of a raw string to an existing string.
TranslatedString()
Constructs an empty TranslatedString with no translation or English text.
A universally unique identifier (UUID) is a 128-bit number used to identify information in computer s...
Definition UUID.h:61
The primary namespace for the NDEVR SDK.
STL namespace.