VR-Forces 4.5 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
rwTranslatableStringObject.h
Go to the documentation of this file.
1 /*******************************************************************************
2 ** Copyright (c) 2014 MaK Technologies, Inc.
3 ** All rights reserved.
4 *******************************************************************************/
5 
6 #pragma once
7 
10 
12 
13 #include "vrfutil/vrfutilDefines.h"
14 #include "vrfutil/readerWriter.h"
16 #include "vrfutil/iteratorBase.h"
17 #include "vrfutil/rwString.h"
18 #include "vrfutil/kinematicTools.h"
20 #include <boost/function.hpp>
21 #include <vlutil/vlStringUtil.h>
22 
23 class DtOutputStream;
24 
29 {
30 public:
31  typedef boost::function<std::string (const char* module, const char* stringToTranslate)> TranslationFunction;
32 
34 
36  parentRegistry = 0);
37 
39  DtReaderWriterRegistry* parentRegistry = 0);
40 
42  DtReaderWriterRegistry* parentRegistry = 0);
43 
45 
49  virtual bool operator==(const DtRwTranslatableStringObject& orig) const;
50  virtual bool operator!=(const DtRwTranslatableStringObject& orig) const;
51 
53 
57  virtual const char* readerWriterType() const;
58 
60  static const char* theXmlType();
61 
62  virtual const char* xmlType() const
63  {
64  return theXmlType();
65  }
66 
68  virtual void printTo(DtOutputStream&) const;
69 
70  virtual void addTranslatableString(const DtString&, const DtString& module = "DtRwTranslatableStringObject",
71  const DtString& originalString = "");
72  virtual void addArgument(const DtString&);
73 
74  virtual void clear();
75 
76  virtual std::string toFormattedString(bool finalCR = true) const;
77 
84  virtual std::vector<int> typesFrom(const std::string& fmt, std::string& reformatted) const;
85 
87  static DtRwTranslatableStringObject trUtf8(const DtString& string);
88 
89  DtString translate(bool finalCR = true) const
90  {
91  DtIteratorBase<DtRwString> iterator(myStringQueue);
92  DtString result;
93  unsigned int argsTranslated = 0;
94 
95  while (iterator.current())
96  {
97  std::vector<std::string> results;
98  std::string source(iterator.current()->name().c_str());
99 
100  oldBoostSplit(results, source, boost::algorithm::is_any_of("="));
101 
102  if (results.size())
103  {
104  if (results[0] == "translate")
105  {
106  std::string module;
107  std::string toTranslate = (*iterator.current()).c_str();
108  if (results.size() >= 2)
109  {
110  module = results[1];
111 
112  if (results.size() == 3)
113  {
114  toTranslate = results[2];
115  }
116  }
117 
122  std::string translated = (theTranslatorFunction)(module.c_str(), toTranslate.c_str()).c_str();
123 
124  if (translated == toTranslate.c_str())
125  {
126  translated = (*iterator.current()).c_str();
127  }
128 
129  result += translated;
130  }
131  else if (results[0] == "argument")
132  {
133  result = DtReplaceSubstring(result, "%1", iterator.current()->c_str());
134 
135  argsTranslated++;
136 
137  result = DtReplaceSubstring(result, "%" + DtString(argsTranslated + 1), "%1");
138  }
139  }
140  else
141  {
142  result += *iterator.current();
143  }
144 
145  ++iterator;
146  }
147 
148  if (finalCR && (!result.length() || result[result.length() - 1] != '\n'))
149  {
150  result += "\n";
151  }
152 
153  return result;
154  }
155 
156  static void setTranslationFunction(TranslationFunction f) { theTranslatorFunction = f; };
157  TranslationFunction translationFunction() const { return theTranslatorFunction; };
158 
159  static std::string defaultTranslationFunction(const char* module, const char* toTranslate) { return toTranslate; };
160 
161 protected:
164 };

Document ID: Generated on Thu Mar 23 18:54:12 EDT 2017 from SVN revision 174804
Copyright © 2005-2017 VT MÄK. All Rights Reserved (www.mak.com)