VR-Forces Development_Version 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 
21 class DtOutputStream;
22 
27 {
28 public:
30 
32  parentRegistry = 0);
33 
35  DtReaderWriterRegistry* parentRegistry = 0);
36 
38  DtReaderWriterRegistry* parentRegistry = 0);
39 
41 
45  virtual bool operator==(const DtRwTranslatableStringObject& orig) const;
46  virtual bool operator!=(const DtRwTranslatableStringObject& orig) const;
47 
49 
53  virtual const char* readerWriterType() const;
54 
56  static const char* theXmlType();
57 
58  virtual const char* xmlType() const
59  {
60  return theXmlType();
61  }
62 
64  virtual void printTo(DtOutputStream&) const;
65 
66  virtual void addTranslatableString(const DtString&, const DtString& module = "DtDefaultTranslation",
67  const DtString& originalString = "");
68  virtual void addArgument(const DtString&);
69 
70  virtual void clear();
71 
72  virtual std::string toFormattedString() const;
73 
80  virtual std::vector<int> typesFrom(const std::string& fmt, std::string& reformatted) const;
81 
82  template <typename QStringType, typename QCoreApp>
83  QStringType translate(bool finalCR = true) const
84  {
85  DtIteratorBase<DtRwString> iterator(myStringQueue);
86  QStringType result;
87  unsigned int argsTranslated = 0;
88 
89  while (iterator.current())
90  {
91  std::vector<std::string> results;
92  std::string source(iterator.current()->name().c_str());
93 
94  oldBoostSplit(results, source, boost::algorithm::is_any_of("="));
95 
96  if (results.size())
97  {
98  if (results[0] == "translate")
99  {
100  std::string module;
101  std::string toTranslate = (*iterator.current()).c_str();
102  if (results.size() >= 2)
103  {
104  module = results[1];
105 
106  if (results.size() == 3)
107  {
108  toTranslate = results[2];
109  }
110  }
111 
116  QStringType translated = QCoreApp::translate(module.c_str(), toTranslate.c_str(),
117  0, QCoreApp::UnicodeUTF8);
118 
119  if (translated == toTranslate.c_str())
120  {
121  translated = (*iterator.current()).c_str();
122  }
123 
124  result += translated;
125  }
126  else if (results[0] == "argument")
127  {
128  result = result.arg(iterator.current()->c_str());
129 
130  argsTranslated++;
131 
132  result = result.replace("%" + QStringType::number(argsTranslated + 1), "%" + QStringType::number(argsTranslated));
133  }
134  }
135  else
136  {
137  result += *iterator.current();
138  }
139 
140  ++iterator;
141  }
142 
143  if (finalCR && (!result.length() || result[result.length() - 1] != '\n'))
144  {
145  result += "\n";
146  }
147 
148  return result;
149  }
150 
151 protected:
153 };

Document ID: Generated on Mon Jul 4 01:00:18 EDT 2016 from SVN revision 166489
Copyright © 2005-2015 VT MÄK. All Rights Reserved (www.mak.com)