• 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
gettextheader.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 "gettextheader.h"
25 
26 #include "project.h"
27 
28 #include "version.h"
29 #include "prefs_lokalize.h"
30 
31 #include <QProcess>
32 #include <QString>
33 #include <QStringBuilder>
34 #include <QMap>
35 #include <QTextCodec>
36 
37 #include <kdebug.h>
38 #include <kglobal.h>
39 #include <klocale.h>
40 #include <kdatetime.h>
41 
42 #include <kio/netaccess.h>
43 #include <ktemporaryfile.h>
44 
49 #define NUM_LANG_WITH_INFO 41
50 static const char* langsWithPInfo[NUM_LANG_WITH_INFO]={
51 "ar",
52 "cs",
53 "da",
54 "de",
55 "el",
56 "en",
57 "en_GB",
58 "en_US",
59 "eo",
60 "es",
61 "et",
62 "fi",
63 "fo",
64 "fr",
65 "ga",
66 "he",
67 "hr",
68 "hu",
69 "it",
70 "ja",
71 "ko",
72 "lt",
73 "lv",
74 "nb",
75 "nl",
76 "nn",
77 "pl",
78 "pt",
79 "pt_BR",
80 "ro",
81 "ru",
82 "sk",
83 "sl",
84 "sr",
85 "sr@latin",
86 "sv",
87 "th",
88 "tr",
89 "uk",
90 "vi",
91 "zh_CN"
92 // '\0'
93 };
94 
95 static const char* pInfo[NUM_LANG_WITH_INFO]={
96 "nplurals=6; plural=n==0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 && n%100<=99 ? 4 : 5;",
97 "nplurals=3; plural=(n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2;",
98 "nplurals=2; plural=(n != 1);",
99 "nplurals=2; plural=(n != 1);",
100 "nplurals=2; plural=(n != 1);",
101 "nplurals=2; plural=(n != 1);",
102 "nplurals=2; plural=(n != 1);",
103 "nplurals=2; plural=(n != 1);",
104 "nplurals=2; plural=(n != 1);",
105 "nplurals=2; plural=(n != 1);",
106 "nplurals=2; plural=(n != 1);",
107 "nplurals=2; plural=(n != 1);",
108 "nplurals=2; plural=(n != 1);",
109 "nplurals=2; plural=(n > 1);",
110 "nplurals=3; plural=n==1 ? 0 : n==2 ? 1 : 2;",
111 "nplurals=2; plural=(n != 1);",
112 "nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);",
113 "nplurals=2; plural=(n != 1);",
114 "nplurals=2; plural=(n != 1);",
115 "nplurals=1; plural=0;",
116 "nplurals=1; plural=0;",
117 "nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && (n%100<10 || n%100>=20) ? 1 : 2);",
118 "nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n != 0 ? 1 : 2);",
119 "nplurals=2; plural=(n != 1);",
120 "nplurals=2; plural=(n != 1);",
121 "nplurals=2; plural=(n != 1);",
122 "nplurals=3; plural=(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);",
123 "nplurals=2; plural=(n != 1);",
124 "nplurals=2; plural=(n > 1);",
125 "nplurals=3; plural=n==1 ? 0 : (n==0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2;",
126 "nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);",
127 "nplurals=3; plural=(n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2;",
128 "nplurals=4; plural=(n%100==1 ? 1 : n%100==2 ? 2 : n%100==3 || n%100==4 ? 3 : 0);",
129 "nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);",
130 "nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);",
131 "nplurals=2; plural=(n != 1);",
132 "nplurals=1; plural=0;",
133 "nplurals=2; plural=(n > 1);",
134 "nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);",
135 "nplurals=1; plural=0;",
136 "nplurals=1; plural=0;"
137 };
138 
139 
140 int numberOfPluralFormsFromHeader(const QString& header)
141 {
142  QRegExp rxplural("Plural-Forms:\\s*nplurals=(.);");
143  if (rxplural.indexIn(header) == -1)
144  return 0;
145  bool ok;
146  int result=rxplural.cap(1).toShort(&ok);
147  return ok?result:0;
148 
149 }
150 
151 int numberOfPluralFormsForLangCode(const QString& langCode)
152 {
153  QString expr=GNUPluralForms(langCode);
154 
155  QRegExp rxplural("nplurals=(.);");
156  if (rxplural.indexIn(expr) == -1)
157  return 0;
158  bool ok;
159  int result=rxplural.cap(1).toShort(&ok);
160  return ok?result:0;
161 
162 }
163 
164 QString GNUPluralForms(const QString& lang)
165 {
166  QByteArray l(lang.toUtf8());
167  int i=NUM_LANG_WITH_INFO;
168  while(--i>=0 && l!=langsWithPInfo[i])
169  ;
170  //if (KDE_ISLIKELY( langsWithPInfo[i]))
171  if (KDE_ISLIKELY( i>=0 ))
172  return QString::fromLatin1(pInfo[i]);
173 
174 
175  //BEGIN alternative
176  // NOTE does this work under M$ OS?
177  qWarning()<<"gonna call msginit";
178  QString def="nplurals=2; plural=n != 1;";
179 
180  QStringList arguments;
181  arguments << "-l" << lang
182  << "-i" << "-"
183  << "-o" << "-"
184  << "--no-translator"
185  << "--no-wrap";
186  QProcess msginit;
187  msginit.start("msginit", arguments);
188 
189  msginit.waitForStarted(5000);
190  if (KDE_ISUNLIKELY( msginit.state()!=QProcess::Running ))
191  {
192  //kWarning()<<"msginit error";
193  return def;
194  }
195 
196  msginit.write(
197  "# SOME DESCRIPTIVE TITLE.\n"
198  "# Copyright (C) YEAR Free Software Foundation, Inc.\n"
199  "# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.\n"
200  "#\n"
201  "#, fuzzy\n"
202  "msgid \"\"\n"
203  "msgstr \"\"\n"
204  "\"Project-Id-Version: PACKAGE VERSION\\n\"\n"
205  "\"POT-Creation-Date: 2002-06-25 03:23+0200\\n\"\n"
206  "\"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\\n\"\n"
207  "\"Last-Translator: FULL NAME <EMAIL@ADDRESS>\\n\"\n"
208  "\"Language-Team: LANGUAGE <LL@li.org>\\n\"\n"
209  "\"Language: LL\\n\"\n"
210  "\"MIME-Version: 1.0\\n\"\n"
211  "\"Content-Type: text/plain; charset=UTF-8\\n\"\n"
212  "\"Content-Transfer-Encoding: ENCODING\\n\"\n"
213 // "\"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\\n\"\n"
214  );
215  msginit.closeWriteChannel();
216 
217  if (KDE_ISUNLIKELY( !msginit.waitForFinished(5000) ))
218  {
219  kWarning()<<"msginit error";
220  return def;
221  }
222 
223 
224  QByteArray result = msginit.readAll();
225  int pos = result.indexOf("Plural-Forms: ");
226  if (KDE_ISUNLIKELY( pos==-1 ))
227  {
228  //kWarning()<<"msginit error"<<result;
229  return def;
230  }
231  pos+=14;
232 
233  int end = result.indexOf('"',pos);
234  if (KDE_ISUNLIKELY( pos==-1 ))
235  {
236  //kWarning()<<"msginit error"<<result;
237  return def;
238  }
239 
240  return QString( result.mid(pos,end-pos-2) );
241  //END alternative
242 }
243 
244 
245 void updateHeader(QString& header,
246  QString& comment,
247  QString& langCode,
248  int& numberOfPluralForms,
249  const QString& CatalogProjectId,
250  bool generatedFromDocbook,
251  bool belongsToProject,
252  bool forSaving,
253  QTextCodec* codec)
254 {
255  QStringList headerList(header.split('\n',QString::SkipEmptyParts));
256  QStringList commentList(comment.split('\n',QString::SkipEmptyParts));
257 
258 //BEGIN header itself
259  QStringList::Iterator it,ait;
260  QString temp;
261  QString authorNameEmail;
262 
263  bool found=false;
264  authorNameEmail=Settings::authorName();
265  if (!Settings::authorEmail().isEmpty())
266  authorNameEmail+=(" <"%Settings::authorEmail()%'>');
267  temp="Last-Translator: "%authorNameEmail%"\\n";
268 
269  QRegExp lt("^ *Last-Translator:.*");
270  for ( it = headerList.begin(),found=false; it != headerList.end() && !found; ++it )
271  {
272  if (it->contains(lt))
273  {
274  if (forSaving) *it = temp;
275  found=true;
276  }
277  }
278  if (KDE_ISUNLIKELY( !found ))
279  headerList.append(temp);
280 
281  QString dateTimeString = KDateTime::currentLocalDateTime().toString("%Y-%m-%d %H:%M%z");
282  temp="PO-Revision-Date: "%dateTimeString%"\\n";
283  QRegExp poRevDate("^ *PO-Revision-Date:.*");
284  for ( it = headerList.begin(),found=false; it != headerList.end() && !found; ++it )
285  {
286  found=it->contains(poRevDate);
287  if (found && forSaving) *it = temp;
288  }
289  if (KDE_ISUNLIKELY( !found ))
290  headerList.append(temp);
291 
292  temp="Project-Id-Version: "%CatalogProjectId%"\\n";
293  //temp.replace( "@PACKAGE@", packageName());
294  QRegExp projectIdVer("^ *Project-Id-Version:.*");
295  for ( it = headerList.begin(),found=false; it != headerList.end() && !found; ++it )
296  {
297  found=it->contains(projectIdVer);
298  if (found && it->contains("PACKAGE VERSION"))
299  *it = temp;
300  }
301  if (KDE_ISUNLIKELY( !found ))
302  headerList.append(temp);
303 
304 
305  langCode=Project::instance()->isLoaded()?
306  Project::instance()->langCode():
307  Settings::defaultLangCode();
308  QString language; //initialized with preexisting value or later
309  QString mailingList; //initialized with preexisting value or later
310 
311  static KConfig* allLanguagesConfig=0;
312  if (!allLanguagesConfig)
313  {
314  allLanguagesConfig = new KConfig("all_languages", KConfig::NoGlobals, "locale");
315  allLanguagesConfig->setLocale(QString());
316  }
317  QRegExp langTeamRegExp("^ *Language-Team:.*");
318  for ( it = headerList.begin(),found=false; it != headerList.end() && !found; ++it )
319  {
320  found=it->contains(langTeamRegExp);
321  if (found)
322  {
323  //really parse header
324  QMap<QString,QString> map;
325  foreach (const QString &runningLangCode, KGlobal::locale()->allLanguagesList())
326  {
327  KConfigGroup cg(allLanguagesConfig, runningLangCode);
328  map[cg.readEntry("Name")]=runningLangCode;
329  }
330  if (map.size()<16) //may be just "en_US" and ""
331  kWarning()<<"seems that all_languages file is missing (usually located under /usr/share/locale)";
332 
333  QRegExp re("^ *Language-Team: *(.*) *<([^>]*)>");
334  if (re.indexIn(*it) != -1 )
335  {
336  if (map.contains( re.cap(1).trimmed() ))
337  {
338  language=re.cap(1).trimmed();
339  mailingList=re.cap(2).trimmed();
340  langCode=map.value(language);
341  }
342  }
343 
344  ait=it;
345  }
346  }
347 
348  if (language.isEmpty())
349  {
350  //language=locale.languageCodeToName(d->_langCode);
351  KConfigGroup cg(allLanguagesConfig, langCode);
352  language=cg.readEntry("Name");
353  if (language.isEmpty())
354  language=langCode;
355  }
356 
357  if (mailingList.isEmpty() || belongsToProject)
358  {
359  if (Project::instance()->isLoaded())
360  mailingList=Project::instance()->mailingList();
361  else //if (mailingList.isEmpty())
362  mailingList=Settings::defaultMailingList();
363  }
364 
365 
366 
367  temp="Language-Team: "%language%" <"%mailingList%'>';
368  temp+="\\n";
369  if (KDE_ISLIKELY( found ))
370  (*ait) = temp;
371  else
372  headerList.append(temp);
373 
374  QRegExp langCodeRegExp("^ *Language: *([^ \\\\]*)");
375  temp="Language: "%langCode%"\\n";
376  for ( it = headerList.begin(),found=false; it != headerList.end() && !found; ++it )
377  {
378  found=(langCodeRegExp.indexIn(*it)!=-1);
379  if (found && langCodeRegExp.cap(1).isEmpty())
380  *it=temp;
381  //if (found) qWarning()<<"got explicit lang code:"<<langCodeRegExp.cap(1);
382  }
383  if (KDE_ISUNLIKELY( !found ))
384  headerList.append(temp);
385 
386  temp="Content-Type: text/plain; charset="%codec->name()%"\\n";
387  for ( it = headerList.begin(),found=false; it != headerList.end() && !found; ++it )
388  {
389  found=it->contains(QRegExp("^ *Content-Type:.*"));
390  if (found) *it=temp;
391  }
392  if (KDE_ISUNLIKELY( !found ))
393  headerList.append(temp);
394 
395 
396  found=false;
397  temp="Content-Transfer-Encoding: 8bit\\n";
398 
399  for ( it = headerList.begin(),found=false; it != headerList.end() && !found; ++it )
400  found=it->contains(QRegExp("^ *Content-Transfer-Encoding:.*"));
401  if (!found)
402  headerList.append(temp);
403 
404  // ensure MIME-Version header
405  temp="MIME-Version: 1.0\\n";
406  for ( it = headerList.begin(),found=false; it != headerList.end()&& !found; ++it )
407  {
408  found=it->contains(QRegExp("^ *MIME-Version:"));
409  if (found) *it = temp;
410  }
411  if (KDE_ISUNLIKELY( !found ))
412  headerList.append(temp);
413 
414 
415  //kDebug()<<"testing for GNUPluralForms";
416  // update plural form header
417  for ( it = headerList.begin(),found=false; it != headerList.end()&& !found; ++it )
418  found=it->contains(QRegExp("^ *Plural-Forms:"));
419  if (found)
420  {
421  --it;
422 
423  //kDebug()<<"GNUPluralForms found";
424  int num=numberOfPluralFormsFromHeader(header);
425  if (!num)
426  {
427  if (generatedFromDocbook)
428  num=1;
429  else
430  {
431  kWarning()<<"No plural form info in header, using project-defined one"<<langCode;
432  QString t=GNUPluralForms(langCode);
433  //kWarning()<<"generated: " << t;
434  if ( !t.isEmpty() )
435  {
436  QRegExp pf("^ *Plural-Forms:\\s*nplurals.*\\\\n");
437  pf.setMinimal(true);
438  temp=QString("Plural-Forms: %1\\n").arg(t);
439  it->replace(pf,temp);
440  num=numberOfPluralFormsFromHeader(temp);
441  }
442  else
443  {
444  kWarning()<<"no... smth went wrong :(\ncheck your gettext install";
445  num=2;
446  }
447  }
448  }
449  numberOfPluralForms=num;
450 
451  }
452  else if ( !generatedFromDocbook)
453  {
454  //kDebug()<<"generating GNUPluralForms"<<langCode;
455  QString t= GNUPluralForms(langCode);
456  //kDebug()<<"here it is:";
457  if ( !t.isEmpty() ) {
458  const QString pluralFormLine=QString("Plural-Forms: %1\\n").arg(t);
459  headerList.append(pluralFormLine);
460  numberOfPluralForms=numberOfPluralFormsFromHeader(pluralFormLine);
461  }
462  }
463 
464  temp="X-Generator: Lokalize %1\\n";
465  temp=temp.arg(LOKALIZE_VERSION);
466 
467  for ( it = headerList.begin(),found=false; it != headerList.end()&& !found; ++it )
468  {
469  found=it->contains(QRegExp("^ *X-Generator:.*"));
470  if (found) *it = temp;
471  }
472  if (KDE_ISUNLIKELY( !found ))
473  headerList.append(temp);
474 
475  //m_header.setMsgstr( headerList.join( "\n" ) );
476  header=headerList.join("\n");
477 //END header itself
478 
479 //BEGIN comment = description, copyrights
480  // U+00A9 is the Copyright sign
481  QRegExp fsfc("^# *Copyright (\\(C\\)|\\x00a9).*Free Software Foundation, Inc");
482  for ( it = commentList.begin(),found=false; it != commentList.end()&&!found; ++it )
483  {
484  found=it->contains( fsfc ) ;
485  if (found)
486  it->replace("YEAR", QDate::currentDate().toString("yyyy"));
487  }
488 /*
489  if( saveOptions.FSFCopyright == ProjectSettingsBase::Update )
490  {
491  //update years
492  QString cy = QDate::currentDate().toString("yyyy");
493  if( !it->contains( QRegExp(cy)) ) // is the year already included?
494  {
495  int index = it->lastIndexOf( QRegExp("[\\d]+[\\d\\-, ]*") );
496  if( index == -1 )
497  {
498  KMessageBox::information(0,i18n("Free Software Foundation Copyright does not contain any year. "
499  "It will not be updated."));
500  } else {
501  it->insert(index+1, QString(", ")+cy);
502  }
503  }
504  }*/
505 #if 0
506  if ( ( !usePrefs || saveOptions.updateDescription )
507  && ( !saveOptions.descriptionString.isEmpty() ) )
508  {
509  temp = "# "+saveOptions.descriptionString;
510  temp.replace( "@PACKAGE@", packageName());
511  temp.replace( "@LANGUAGE@", identityOptions.languageName);
512  temp = temp.trimmed();
513 
514  // The description strings has often buggy variants already in the file, these must be removed
515  QString regexpstr = "^#\\s+" + QRegExp::escape( saveOptions.descriptionString.trimmed() ) + "\\s*$";
516  regexpstr.replace( "@PACKAGE@", ".*" );
517  regexpstr.replace( "@LANGUAGE@", ".*" );
518  //kDebug() << "REGEXPSTR: " << regexpstr;
519  QRegExp regexp ( regexpstr );
520 
521  // The buggy variants exist in English too (of a time before KBabel got a translation for the corresponding language)
522  QRegExp regexpUntranslated ( "^#\\s+translation of .* to .*\\s*$" );
523 
524 
525  kDebug () << "Temp is '" << temp << "'";
526 
527  found=false;
528  bool foundTemplate=false;
529 
530  it = commentList.begin();
531  while ( it != commentList.end() )
532  {
533  kDebug () << "testing '" << (*it) << "'";
534  bool deleteItem = false;
535 
536  if ( (*it) == temp )
537  {
538  kDebug () << "Match ";
539  if ( found )
540  deleteItem = true;
541  else
542  found=true;
543  }
544  else if ( regexp.indexIn( *it ) >= 0 )
545  {
546  // We have a similar (translated) string (from another project or another language (perhaps typos)). Remove it.
547  deleteItem = true;
548  }
549  else if ( regexpUntranslated.indexIn( *it ) >= 0 )
550  {
551  // We have a similar (untranslated) string (from another project or another language (perhaps typos)). Remove it.
552  deleteItem = true;
553  }
554  else if ( (*it) == "# SOME DESCRIPTIVE TITLE." )
555  {
556  // We have the standard title placeholder, remove it
557  deleteItem = true;
558  }
559 
560  if ( deleteItem )
561  it = commentList.erase( it );
562  else
563  ++it;
564  }
565  if (!found) commentList.prepend(temp);
566  }
567 #endif
568  // kDebug() << "HEADER COMMENT: " << commentList;
569 
570  /* if ( (!usePrefs || saveOptions.updateTranslatorCopyright)
571  && ( ! identityOptions->readEntry("authorName","").isEmpty() )
572  && ( ! identityOptions->readEntry("Email","").isEmpty() ) ) // An email address can be used as ersatz of a name
573  {*/
574 // return;
575  QStringList foundAuthors;
576 
577  temp="# "%authorNameEmail%", "%QDate::currentDate().toString("yyyy")%'.';
578 
579  // ### TODO: it would be nice if the entry could start with "COPYRIGHT" and have the "(C)" symbol (both not mandatory)
580  QRegExp regexpAuthorYear( "^#.*(<.+@.+>)?,\\s*([\\d]+[\\d\\-, ]*|YEAR)" );
581  QRegExp regexpYearAlone( "^# , \\d{4}.?\\s*$" );
582  if (commentList.isEmpty())
583  {
584  commentList.append(temp);
585  commentList.append(QString());
586  }
587  else
588  {
589  it = commentList.begin();
590  while ( it != commentList.end() )
591  {
592  bool deleteItem = false;
593  if ( it->indexOf( "copyright", 0, Qt::CaseInsensitive ) != -1 )
594  {
595  // We have a line with a copyright. It should not be moved.
596  }
597  else if ( it->contains( QRegExp("#, *fuzzy") ) )
598  deleteItem = true;
599  else if ( it->contains( regexpYearAlone ) )
600  {
601  // We have found a year number that is preceded by a comma.
602  // That is typical of KBabel 1.10 (and earlier?) when there is neither an author name nor an email
603  // Remove the entry
604  deleteItem = true;
605  }
606  else if ( it->contains( "# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.") )
607  deleteItem = true;
608  else if ( it->contains( "# SOME DESCRIPTIVE TITLE"))
609  deleteItem = true;
610  else if ( it->contains( regexpAuthorYear ) ) // email address followed by year
611  {
612  if ( !foundAuthors.contains( (*it) ) )
613  {
614  // The author line is new (and not a duplicate), so add it to the author line list
615  foundAuthors.append( (*it) );
616  }
617  // Delete also non-duplicated entry, as now all what is needed will be processed in foundAuthors
618  deleteItem = true;
619  }
620 
621  if ( deleteItem )
622  it = commentList.erase( it );
623  else
624  ++it;
625  }
626 
627  if ( !foundAuthors.isEmpty() )
628  {
629  found = false;
630  bool foundAuthor = false;
631 
632  const QString cy = QDate::currentDate().toString("yyyy");
633 
634  ait = foundAuthors.end();
635  for ( it = foundAuthors.begin() ; it!=foundAuthors.end(); ++it )
636  {
637  if ( it->contains(Settings::authorName()) || it->contains(Settings::authorEmail()) )
638  {
639  foundAuthor = true;
640  if ( it->contains( cy ) )
641  found = true;
642  else
643  ait = it;
644  }
645  }
646  if ( !found )
647  {
648  if ( !foundAuthor )
649  foundAuthors.append(temp);
650  else if ( ait != foundAuthors.end() )
651  {
652  //update years
653  const int index = (*ait).lastIndexOf( QRegExp("[\\d]+[\\d\\-, ]*") );
654  if ( index == -1 )
655  (*ait)+=", "%cy;
656  else
657  ait->insert(index+1, ", "%cy);
658  }
659  else
660  kDebug() << "INTERNAL ERROR: author found but iterator dangling!";
661  }
662 
663  }
664  else
665  foundAuthors.append(temp);
666 
667 
668  foreach (QString author, foundAuthors)
669  {
670  // ensure dot at the end of copyright
671  if ( !author.endsWith('.') ) author += '.';
672  commentList.append(author);
673  }
674  }
675 
676  //m_header.setComment( commentList.join( "\n" ) );
677  comment=commentList.join("\n");
678 
679 //END comment = description, copyrights
680 }
681 
project.h
QRegExp::cap
QString cap(int nth) const
QString::append
QString & append(QChar ch)
NUM_LANG_WITH_INFO
#define NUM_LANG_WITH_INFO
this data was obtained by running GNUPluralForms() on all languages KDE knows of
Definition: gettextheader.cpp:49
QString::toShort
short toShort(bool *ok, int base) const
QMap::contains
bool contains(const Key &key) const
QTextCodec::name
virtual QByteArray name() const =0
QDate::toString
QString toString(Qt::DateFormat format) const
QByteArray
QRegExp::setMinimal
void setMinimal(bool minimal)
QString::split
QStringList split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
QRegExp::escape
QString escape(const QString &str)
QMap
Project::instance
static Project * instance()
Definition: project.cpp:67
QStringList::contains
bool contains(const QString &str, Qt::CaseSensitivity cs) const
ProjectBase::langCode
QString langCode() const
Get LangCode.
Definition: projectbase.h:65
Settings::defaultLangCode
static QString defaultLangCode()
Get DefaultLangCode.
Definition: prefs_lokalize.h:79
Settings::authorEmail
static QString authorEmail()
Get authorEmail.
Definition: prefs_lokalize.h:61
numberOfPluralFormsFromHeader
int numberOfPluralFormsFromHeader(const QString &header)
Definition: gettextheader.cpp:140
langsWithPInfo
static const char * langsWithPInfo[NUM_LANG_WITH_INFO]
Definition: gettextheader.cpp:50
QRegExp::indexIn
int indexIn(const QString &str, int offset, CaretMode caretMode) const
QRegExp
Settings::authorName
static QString authorName()
Get authorName.
Definition: prefs_lokalize.h:25
QByteArray::indexOf
int indexOf(char ch, int from) const
QList::append
void append(const T &value)
QString::insert
QString & insert(int position, QChar ch)
Settings::defaultMailingList
static QString defaultMailingList()
Get DefaultMailingList.
Definition: prefs_lokalize.h:97
QProcess
GNUPluralForms
QString GNUPluralForms(const QString &lang)
Definition: gettextheader.cpp:164
QList::isEmpty
bool isEmpty() const
QString::isEmpty
bool isEmpty() const
QString::trimmed
QString trimmed() const
LOKALIZE_VERSION
#define LOKALIZE_VERSION
Definition: version.h:11
QIODevice::readAll
QByteArray readAll()
ProjectBase::mailingList
QString mailingList() const
Get MailingList.
Definition: projectbase.h:116
gettextheader.h
QString::endsWith
bool endsWith(const QString &s, Qt::CaseSensitivity cs) const
QList::Iterator
typedef Iterator
QString
QTextCodec
Project::isLoaded
bool isLoaded() const
Definition: project.h:62
QByteArray::mid
QByteArray mid(int pos, int len) const
QStringList
QList::end
iterator end()
QString::contains
bool contains(QChar ch, Qt::CaseSensitivity cs) const
QProcess::waitForStarted
bool waitForStarted(int msecs)
version.h
QString::replace
QString & replace(int position, int n, QChar after)
prefs_lokalize.h
QDate::currentDate
QDate currentDate()
updateHeader
void updateHeader(QString &header, QString &comment, QString &langCode, int &numberOfPluralForms, const QString &CatalogProjectId, bool generatedFromDocbook, bool belongsToProject, bool forSaving, QTextCodec *codec)
Definition: gettextheader.cpp:245
QByteArray::contains
bool contains(char ch) const
QIODevice::write
qint64 write(const char *data, qint64 maxSize)
QString::fromLatin1
QString fromLatin1(const char *str, int size)
QString::begin
iterator begin()
QProcess::closeWriteChannel
void closeWriteChannel()
QString::arg
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
pInfo
static const char * pInfo[NUM_LANG_WITH_INFO]
Definition: gettextheader.cpp:95
QList::begin
iterator begin()
QMap::size
int size() const
QProcess::start
void start(const QString &program, const QStringList &arguments, QFlags< QIODevice::OpenModeFlag > mode)
numberOfPluralFormsForLangCode
int numberOfPluralFormsForLangCode(const QString &langCode)
Definition: gettextheader.cpp:151
QProcess::state
QProcess::ProcessState state() const
QMap::value
const T value(const Key &key) const
QProcess::waitForFinished
bool waitForFinished(int msecs)
QString::toUtf8
QByteArray toUtf8() const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:40:07 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