• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdesdk API Reference
  • KDE Home
  • Contact Us
 

lokalize

  • sources
  • kde-4.14
  • kdesdk
  • lokalize
  • src
  • catalog
catalogstring.cpp
Go to the documentation of this file.
1 /* ****************************************************************************
2  This file is part of Lokalize
3 
4  Copyright (C) 2008-2009 by Nick Shaforostoff <shafff@ukr.net>
5 
6  This program is free software; you can redistribute it and/or
7  modify it under the terms of the GNU General Public License as
8  published by the Free Software Foundation; either version 2 of
9  the License or (at your option) version 3 or any later version
10  accepted by the membership of KDE e.V. (or its successor approved
11  by the membership of KDE e.V.), which shall act as a proxy
12  defined in Section 14 of version 3 of the license.
13 
14  This program is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with this program. If not, see <http://www.gnu.org/licenses/>.
21 
22 **************************************************************************** */
23 
24 #include "catalogstring.h"
25 #include <kdebug.h>
26 #include <klocale.h>
27 
28 
29 const char* InlineTag::getElementName(InlineElement type)
30 {
31  static const char* inlineElementNames[(int)InlineElementCount]={
32  "_unknown",
33  "bpt",
34  "ept",
35  "ph",
36  "it",
37  //"_NEVERSHOULDBECHOSEN",
38  "mrk",
39  "g",
40  "sub",
41  "_NEVERSHOULDBECHOSEN",
42  "x",
43  "bx",
44  "ex"
45  };
46 
47  return inlineElementNames[(int)type];
48 }
49 
50 InlineTag InlineTag::getPlaceholder() const
51 {
52  InlineTag tagRange=*this;
53  tagRange.start=-1;
54  tagRange.end=-1;
55  return tagRange;
56 }
57 
58 InlineTag::InlineElement InlineTag::getElementType(const QByteArray& tag)
59 {
60  int i=InlineTag::InlineElementCount;
61  while(--i>0)
62  if (getElementName(InlineElement(i))==tag)
63  break;
64  return InlineElement(i);
65 }
66 
67 
68 QString InlineTag::displayName() const
69 {
70  static const char* inlineElementNames[(int)InlineElementCount]={
71  "_unknown",
72  I18N_NOOP2("XLIFF inline tag name", "Start of paired tag"),
73  I18N_NOOP2("XLIFF inline tag name", "End of paired tag"),
74  I18N_NOOP2("XLIFF inline tag name", "Stand-alone tag"),
75  I18N_NOOP2("XLIFF inline tag name", "Isolated tag"),
76  //"_NEVERSHOULDBECHOSEN",
77  I18N_NOOP2("XLIFF inline tag name", "Marker"),
78  I18N_NOOP2("XLIFF inline tag name", "Generic group placeholder"),
79  I18N_NOOP2("XLIFF inline tag name", "Sub-flow"),
80  "_NEVERSHOULDBECHOSEN",
81  I18N_NOOP2("XLIFF inline tag name", "Generic placeholder"),
82  I18N_NOOP2("XLIFF inline tag name", "Start of paired placeholder"),
83  I18N_NOOP2("XLIFF inline tag name", "End of paired placeholder")
84  };
85 
86  QString result=i18nc("XLIFF inline tag name", inlineElementNames[type]);
87 
88  if (type==mrk)
89  {
90  static const char* mrkTypes[]={
91  "abbrev",
92  "abbreviated-form",
93  "abbreviation",
94  "acronym",
95  "appellation",
96  "collocation",
97  "common-name",
98  "datetime",
99  "equation",
100  "expanded-form",
101  "formula",
102  "head-term",
103  "initialism",
104  "international-scientific-term",
105  "internationalism",
106  "logical-expression",
107  "materials-management-unit",
108  "name",
109  "near-synonym",
110  "part-number",
111  "phrase",
112  "phraseological-unit",
113  "protected",
114  "romanized-form",
115  "seg",
116  "set-phrase",
117  "short-form",
118  "sku",
119  "standard-text",
120  "symbol",
121  "synonym",
122  "synonymous-phrase",
123  "term",
124  "transcribed-form",
125  "transliterated-form",
126  "truncated-term",
127  "variant"
128  };
129 
130  static const char* mrkTypeNames[]={
131  I18N_NOOP2("XLIFF mark type", "abbreviation"),
132  I18N_NOOP2("XLIFF mark type", "abbreviated form: a term resulting from the omission of any part of the full term while designating the same concept"),
133  I18N_NOOP2("XLIFF mark type", "abbreviation: an abbreviated form of a simple term resulting from the omission of some of its letters (e.g. 'adj.' for 'adjective')"),
134  I18N_NOOP2("XLIFF mark type", "acronym: an abbreviated form of a term made up of letters from the full form of a multiword term strung together into a sequence pronounced only syllabically (e.g. 'radar' for 'radio detecting and ranging')"),
135  I18N_NOOP2("XLIFF mark type", "appellation: a proper-name term, such as the name of an agency or other proper entity"),
136  I18N_NOOP2("XLIFF mark type", "collocation: a recurrent word combination characterized by cohesion in that the components of the collocation must co-occur within an utterance or series of utterances, even though they do not necessarily have to maintain immediate proximity to one another"),
137  I18N_NOOP2("XLIFF mark type", "common name: a synonym for an international scientific term that is used in general discourse in a given language"),
138  I18N_NOOP2("XLIFF mark type", "date and/or time"),
139  I18N_NOOP2("XLIFF mark type", "equation: an expression used to represent a concept based on a statement that two mathematical expressions are, for instance, equal as identified by the equal sign (=), or assigned to one another by a similar sign"),
140  I18N_NOOP2("XLIFF mark type", "expanded form: The complete representation of a term for which there is an abbreviated form"),
141  I18N_NOOP2("XLIFF mark type", "formula: figures, symbols or the like used to express a concept briefly, such as a mathematical or chemical formula"),
142  I18N_NOOP2("XLIFF mark type", "head term: the concept designation that has been chosen to head a terminological record"),
143  I18N_NOOP2("XLIFF mark type", "initialism: an abbreviated form of a term consisting of some of the initial letters of the words making up a multiword term or the term elements making up a compound term when these letters are pronounced individually (e.g. 'BSE' for 'bovine spongiform encephalopathy')"),
144  I18N_NOOP2("XLIFF mark type", "international scientific term: a term that is part of an international scientific nomenclature as adopted by an appropriate scientific body"),
145  I18N_NOOP2("XLIFF mark type", "internationalism: a term that has the same or nearly identical orthographic or phonemic form in many languages"),
146  I18N_NOOP2("XLIFF mark type", "logical expression: an expression used to represent a concept based on mathematical or logical relations, such as statements of inequality, set relationships, Boolean operations, and the like"),
147  I18N_NOOP2("XLIFF mark type", "materials management unit: a unit to track object"),
148  I18N_NOOP2("XLIFF mark type", "name"),
149  I18N_NOOP2("XLIFF mark type", "near synonym: a term that represents the same or a very similar concept as another term in the same language, but for which interchangeability is limited to some contexts and inapplicable in others"),
150  I18N_NOOP2("XLIFF mark type", "part number: a unique alphanumeric designation assigned to an object in a manufacturing system"),
151  I18N_NOOP2("XLIFF mark type", "phrase"),
152  I18N_NOOP2("XLIFF mark type", "phraseological: a group of two or more words that form a unit, the meaning of which frequently cannot be deduced based on the combined sense of the words making up the phrase"),
153  I18N_NOOP2("XLIFF mark type", "protected: the marked text should not be translated"),
154  I18N_NOOP2("XLIFF mark type", "romanized form: a form of a term resulting from an operation whereby non-Latin writing systems are converted to the Latin alphabet"),
155  I18N_NOOP2("XLIFF mark type", "segment: the marked text represents a segment"),
156  I18N_NOOP2("XLIFF mark type", "set phrase: a fixed, lexicalized phrase"),
157  I18N_NOOP2("XLIFF mark type", "short form: a variant of a multiword term that includes fewer words than the full form of the term (e.g. 'Group of Twenty-four' for 'Intergovernmental Group of Twenty-four on International Monetary Affairs')"),
158  I18N_NOOP2("XLIFF mark type", "stock keeping unit: an inventory item identified by a unique alphanumeric designation assigned to an object in an inventory control system"),
159  I18N_NOOP2("XLIFF mark type", "standard text: a fixed chunk of recurring text"),
160  I18N_NOOP2("XLIFF mark type", "symbol: a designation of a concept by letters, numerals, pictograms or any combination thereof"),
161  I18N_NOOP2("XLIFF mark type", "synonym: a term that represents the same or a very similar concept as the main entry term in a term entry"),
162  I18N_NOOP2("XLIFF mark type", "synonymous phrase: phraseological unit in a language that expresses the same semantic content as another phrase in that same language"),
163  I18N_NOOP2("XLIFF mark type", "term"),
164  I18N_NOOP2("XLIFF mark type", "transcribed form: a form of a term resulting from an operation whereby the characters of one writing system are represented by characters from another writing system, taking into account the pronunciation of the characters converted"),
165  I18N_NOOP2("XLIFF mark type", "transliterated form: a form of a term resulting from an operation whereby the characters of an alphabetic writing system are represented by characters from another alphabetic writing system"),
166  I18N_NOOP2("XLIFF mark type", "truncated term: an abbreviated form of a term resulting from the omission of one or more term elements or syllables (e.g. 'flu' for 'influenza')"),
167  I18N_NOOP2("XLIFF mark type", "variant: one of the alternate forms of a term")
168  };
169  int i=sizeof(mrkTypes)/sizeof(char*);
170  while(--i>=0 && mrkTypes[i]!=id)
171  ;
172  if (i!=-1)
173  {
174  result=i18nc("XLIFF mark type", mrkTypeNames[i]);
175  if (!result.isEmpty())
176  result[0]=result.at(0).toUpper();
177  }
178  }
179 
180  if (!ctype.isEmpty())
181  result+=" ("+ctype+")";
182 
183  return result;
184 }
185 
186 
187 QMap<QString,int> CatalogString::tagIdToIndex() const
188 {
189  QMap<QString,int> result;
190  int index=0;
191  int count=tags.size();
192  for (int i=0;i<count;++i)
193  {
194  if (!result.contains(tags.at(i).id))
195  result.insert(tags.at(i).id, index++);
196  }
197  return result;
198 }
199 
200 QByteArray CatalogString::tagsAsByteArray()const
201 {
202  QByteArray result;
203  if (tags.size())
204  {
205  QDataStream stream(&result,QIODevice::WriteOnly);
206  stream<<tags;
207  }
208  return result;
209 }
210 
211 CatalogString::CatalogString(QString str, QByteArray tagsByteArray)
212  : string(str)
213 {
214  if (tagsByteArray.size())
215  {
216  QDataStream stream(tagsByteArray);
217  stream>>tags;
218  }
219 }
220 
221 static void adjustTags(QList<InlineTag>& tags, int position, int value)
222 {
223  int i=tags.size();
224  while(--i>=0)
225  {
226  InlineTag& t=tags[i];
227  if (t.start>position)
228  t.start+=value;
229  if (t.end>=position) //cases when strict > is needed?
230  t.end+=value;
231  }
232 }
233 
234 void CatalogString::remove(int position, int len)
235 {
236  string.remove(position,len);
237  adjustTags(tags,position,-len);
238 }
239 
240 void CatalogString::insert(int position, const QString& str)
241 {
242  string.insert(position, str);
243  adjustTags(tags,position,str.size());
244 }
245 
246 
247 QDataStream &operator<<(QDataStream &out, const InlineTag &t)
248 {
249  return out<<int(t.type)<<t.start<<t.end<<t.id;
250 }
251 
252 QDataStream &operator>>(QDataStream &in, InlineTag &t)
253 {
254  int type;
255  in>>type>>t.start>>t.end>>t.id;
256  t.type=InlineTag::InlineElement(type);
257  return in;
258 }
259 
260 QDataStream &operator<<(QDataStream &out, const CatalogString &myObj)
261 {
262  return out<<myObj.string<<myObj.tags;
263 }
264 QDataStream &operator>>(QDataStream &in, CatalogString &myObj)
265 {
266  return in>>myObj.string>>myObj.tags;
267 }
268 
269 
270 
271 void adaptCatalogString(CatalogString& target, const CatalogString& ref)
272 {
273  kWarning()<<"HERE"<<target.string;
274  QHash<QString,int> id2tagIndex;
275  QMultiMap<InlineTag::InlineElement,int> tagType2tagIndex;
276  int i=ref.tags.size();
277  while(--i>=0)
278  {
279  const InlineTag& t=ref.tags.at(i);
280  id2tagIndex.insert(t.id,i);
281  tagType2tagIndex.insert(t.type,i);
282  kWarning()<<"inserting"<<t.id<<t.type<<i;
283  }
284 
285  QList<InlineTag> oldTags=target.tags;
286  target.tags.clear();
287  //we actually walking from beginning to end:
288  qSort(oldTags.begin(), oldTags.end(), qGreater<InlineTag>());
289  i=oldTags.size();
290  while(--i>=0)
291  {
292  const InlineTag& targetTag=oldTags.at(i);
293  if (id2tagIndex.contains(targetTag.id))
294  {
295  kWarning()<<"matched"<<targetTag.id<<i;
296  target.tags.append(targetTag);
297  tagType2tagIndex.remove(targetTag.type, id2tagIndex.take(targetTag.id));
298  oldTags.removeAt(i);
299  }
300  }
301  kWarning()<<"HERE 0"<<target.string;
302 
303  //now all the tags left have to ID (exact) matches
304  i=oldTags.size();
305  while(--i>=0)
306  {
307  InlineTag targetTag=oldTags.at(i);
308  if (tagType2tagIndex.contains(targetTag.type))
309  {
310  //try to match by position
311  //we're _taking_ first so the next one becomes new 'first' for the next time.
312  QList<InlineTag> possibleRefMatches;
313  foreach(int i, tagType2tagIndex.values(targetTag.type))
314  possibleRefMatches<<ref.tags.at(i);
315  qSort(possibleRefMatches);
316  kWarning()<<"setting id:"<<targetTag.id<<possibleRefMatches.first().id;
317  targetTag.id=possibleRefMatches.first().id;
318 
319  target.tags.append(targetTag);
320  kWarning()<<"id??:"<<targetTag.id<<target.tags.first().id;
321  tagType2tagIndex.remove(targetTag.type, id2tagIndex.take(targetTag.id));
322  oldTags.removeAt(i);
323  }
324  }
325  kWarning()<<"HERE 1"<<target.string;
326  //now walk through unmatched tags and properly remove them.
327  foreach(const InlineTag& tag, oldTags)
328  {
329  if (tag.isPaired())
330  target.remove(tag.end, 1);
331  target.remove(tag.start, 1);
332  }
333  kWarning()<<"HERE 2"<<target.string;
334 }
335 
QList::clear
void clear()
catalogstring.h
QHash::insert
iterator insert(const Key &key, const T &value)
QMap::contains
bool contains(const Key &key) const
InlineTag::isPaired
static bool isPaired(InlineElement type)
Definition: catalogstring.h:105
CatalogString::CatalogString
CatalogString()
Definition: catalogstring.h:133
QMap::values
QList< T > values() const
QByteArray
QDataStream
QList::at
const T & at(int i) const
QMap< QString, int >
QString::size
int size() const
QList::removeAt
void removeAt(int i)
CatalogString::string
QString string
Definition: catalogstring.h:130
CatalogString::insert
void insert(int position, const QString &str)
Definition: catalogstring.cpp:240
QList::size
int size() const
InlineTag::getElementType
static InlineElement getElementType(const QByteArray &)
Definition: catalogstring.cpp:58
InlineTag::InlineElementCount
Definition: catalogstring.h:64
QList::append
void append(const T &value)
CatalogString::tagIdToIndex
QMap< QString, int > tagIdToIndex() const
Definition: catalogstring.cpp:187
InlineTag::displayName
QString displayName() const
Definition: catalogstring.cpp:68
QHash
InlineTag::InlineElement
InlineElement
Definition: catalogstring.h:49
InlineTag::type
InlineElement type
Definition: catalogstring.h:70
QString::isEmpty
bool isEmpty() const
InlineTag::start
int start
Definition: catalogstring.h:68
adjustTags
static void adjustTags(QList< InlineTag > &tags, int position, int value)
Definition: catalogstring.cpp:221
InlineTag::id
QString id
Definition: catalogstring.h:71
QMultiMap::insert
QMap< Key, T >::iterator insert(const Key &key, const T &value)
QList::first
T & first()
QString
QList< InlineTag >
adaptCatalogString
void adaptCatalogString(CatalogString &target, const CatalogString &ref)
prepares
Definition: catalogstring.cpp:271
QList::end
iterator end()
CatalogString
data structure used to pass info about inline elements a XLIFF tag is represented by a TAGRANGE_IMAGE...
Definition: catalogstring.h:128
InlineTag::getElementName
const char * getElementName() const
Definition: catalogstring.h:103
QHash::take
T take(const Key &key)
QChar::toUpper
QChar toUpper() const
CatalogString::tagsAsByteArray
QByteArray tagsAsByteArray() const
Definition: catalogstring.cpp:200
CatalogString::tags
QList< InlineTag > tags
Definition: catalogstring.h:131
QString::at
const QChar at(int position) const
operator>>
QDataStream & operator>>(QDataStream &in, InlineTag &t)
Definition: catalogstring.cpp:252
InlineTag::ctype
QString ctype
Definition: catalogstring.h:74
InlineTag::mrk
Definition: catalogstring.h:57
QMap::insert
iterator insert(const Key &key, const T &value)
QHash::contains
bool contains(const Key &key) const
CatalogString::remove
void remove(int position, int len)
Definition: catalogstring.cpp:234
QMultiMap
QMultiMap::remove
int remove(const Key &key)
QMultiMap::contains
bool contains(const Key &key) const
operator<<
QDataStream & operator<<(QDataStream &out, const InlineTag &t)
Definition: catalogstring.cpp:247
QByteArray::size
int size() const
InlineTag::end
int end
Definition: catalogstring.h:69
QList::begin
iterator begin()
InlineTag
data structure used to pass info about inline elements a XLIFF tag is represented by a TAGRANGE_IMAGE...
Definition: catalogstring.h:44
InlineTag::getPlaceholder
InlineTag getPlaceholder() const
used to denote tag that doesn't present in target, to have parallel numbering in view ...
Definition: catalogstring.cpp:50
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:40:06 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

lokalize

Skip menu "lokalize"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdesdk API Reference

Skip menu "kdesdk API Reference"
  • kapptemplate
  • kcachegrind
  • kompare
  • lokalize
  • umbrello
  •   umbrello

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal