21 #include <vlutil/vlStringUtil.h>
23 #include <boost/function.hpp>
35 typedef boost::function<std::string (const char* module, const char* stringToTranslate)>
TranslationFunction;
67 virtual const char*
xmlType()
const override
73 virtual void printTo( DtOutputStream& )
const;
75 virtual void addTranslatableString(
const DtString&,
const DtString& module =
"DtRwTranslatableStringObject",
76 const DtString& originalString =
"" );
77 virtual void addArgument(
const DtString& );
81 virtual std::string toFormattedString(
bool finalCR =
true )
const;
89 virtual std::vector<int> typesFrom(
const std::string& fmt, std::string& reformatted )
const;
98 unsigned int argsTranslated = 0;
102 std::vector<std::string> results;
109 if (results[0] ==
"translate")
112 std::string toTranslate = (*iterator.
current()).c_str();
113 if (results.size() >= 2)
117 if (results.size() == 3)
119 toTranslate = results[2];
127 std::string translated = (theTranslatorFunction)(module.c_str(), toTranslate.c_str()).c_str();
129 if (translated == toTranslate.c_str())
131 translated = (*iterator.
current()).c_str();
134 result += translated;
136 else if (results[0] ==
"argument")
140 const unsigned MaxStrSize = 511;
141 const unsigned MaxTruncated = 508;
142 if (result.length() > MaxStrSize)
144 result =
DtString(result.c_str(), MaxTruncated) +
"...";
146 else if (result.length() + iterator.
current()->length() > MaxStrSize)
148 unsigned maxSize = MaxTruncated - result.length();
150 result = DtReplaceSubstring(result,
"%1", truncated);
155 result = DtReplaceSubstring(result,
"%1", iterator.
current()->c_str());
160 result = DtReplaceSubstring(result,
"%" +
DtString(argsTranslated + 1),
"%1");
171 if (finalCR && (!result.length() || result[result.length() - 1] !=
'\n'))
182 static std::string defaultTranslationFunction(
const char* module,
const char* toTranslate) {
return toTranslate; };
bool operator==(const DtReaderWriter &) const
Equivalence operator.
virtual const char * readerWriterType() const
Used to supply a string type that this reader writer type is. This can be used in place of dynamic-ca...
static void setTranslationFunction(TranslationFunction f)
Definition: rwTranslatableStringObject.h:179
virtual const char * xmlType() const override
Definition: rwTranslatableStringObject.h:67
virtual T * current()
Definition: iteratorBase.h:330
Definition: readerWriter.h:85
Definition: readerWriterRegistry.h:39
boost::function< std::string(const char *module, const char *stringToTranslate)> TranslationFunction
Definition: rwTranslatableStringObject.h:35
DtString translate(bool finalCR=true) const
Definition: rwTranslatableStringObject.h:94
static TranslationFunction theTranslatorFunction
Definition: rwTranslatableStringObject.h:186
Description: DtIteratorBase is the base class for iterators used to iterate over a DtList...
Definition: iteratorBase.h:32
bool operator!=(const DtReaderWriter &rhs) const
Definition: readerWriter.h:121
TranslationFunction translationFunction() const
Definition: rwTranslatableStringObject.h:180
const char * source
Definition: lz4.h:442
const char * c_str() const
DtRwTranslatableStringObject is a simple class that will keep track of strings that can be translated...
Definition: rwTranslatableStringObject.h:31
#define DT_DLL_vrfutil
This file is used to determine how to build Disable inconsistent dll linkage warning Visual Studio 6...
Definition: vrfutilDefines.h:34
const DtReaderWriter & operator=(const DtReaderWriter &orig)
assignment operator
static const char * theXmlType()
The type that is used when archiving to an XML stream.
virtual DtSymbolString name() const
Accessor for name of this readable/writable object.