• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.10.5 API Reference
  • KDE Home
  • Contact Us
 

KNewStuff

  • knewstuff
  • knewstuff2
  • core
ktranslatable.cpp
Go to the documentation of this file.
1 /*
2  This file is part of KNewStuff2.
3  Copyright (c) 2006, 2007 Josef Spillner <spillner@kde.org>
4  Copyright (c) 2008 Jeremy Whiting <jpwhiting@kde.org>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Lesser General Public
8  License as published by the Free Software Foundation; either
9  version 2.1 of the License, or (at your option) any later version.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public
17  License along with this library. If not, see <http://www.gnu.org/licenses/>.
18 */
19 #include "ktranslatable.h"
20 
21 #include <kglobal.h>
22 #include <klocale.h>
23 
24 #include <QtCore/QMutableStringListIterator>
25 
26 using namespace KNS;
27 
28 KTranslatable::KTranslatable()
29  : d(0)
30 {
31 }
32 
33 KTranslatable::KTranslatable(const KTranslatable& other)
34  : d(0)
35 {
36  m_strings = other.m_strings;
37 }
38 
39 KTranslatable& KTranslatable::operator=(const KTranslatable & other)
40 {
41  if (this == &other) {
42  return *this;
43  }
44  m_strings = other.m_strings;
45  return *this;
46 }
47 
48 KTranslatable::~KTranslatable()
49 {
50 // delete d;
51 }
52 
53 KTranslatable::KTranslatable(const QString& string)
54  : d(0)
55 {
56  m_strings[QString()] = string;
57 }
58 
59 void KTranslatable::addString(const QString& lang, const QString& string)
60 {
61  m_strings[lang] = string;
62 }
63 
64 QString KTranslatable::representation() const
65 {
66  if (m_strings.isEmpty()) return QString();
67 
68  const QStringList langs = KGlobal::locale()->languageList();
69  for (QStringList::ConstIterator it = langs.begin(); it != langs.end(); ++it)
70  if (m_strings.contains(*it)) return m_strings[*it];
71 
72  if (m_strings.contains(QString())) return m_strings[QString()];
73  // NOTE: this could be the source of crashes I've seen occasionally
74  else return *(m_strings.begin());
75 }
76 
77 QString KTranslatable::language() const
78 {
79  if (m_strings.isEmpty()) return QString();
80 
81  const QStringList langs = KGlobal::locale()->languageList();
82  for (QStringList::ConstIterator it = langs.begin(); it != langs.end(); ++it)
83  if (m_strings.contains(*it)) return (*it);
84 
85  if (m_strings.contains(QString())) return QString();
86  else return m_strings.begin().key();
87 }
88 
89 QString KTranslatable::translated(const QString& lang) const
90 {
91  if (m_strings.contains(lang))
92  return m_strings[lang];
93  return QString();
94 }
95 
96 QStringList KTranslatable::languages() const
97 {
98  return m_strings.keys();
99 }
100 
101 QStringList KTranslatable::strings() const
102 {
103  return m_strings.values();
104 }
105 
106 QMap<QString, QString> KTranslatable::stringmap() const
107 {
108  return m_strings;
109 }
110 
111 bool KTranslatable::isTranslated() const
112 {
113  return m_strings.count() > 1;
114 }
115 
116 bool KTranslatable::isEmpty() const
117 {
118  return m_strings.isEmpty();
119 }
120 
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Mon Jul 15 2013 13:07:38 by doxygen 1.8.3.1 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KNewStuff

Skip menu "KNewStuff"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs-4.10.5 API Reference

Skip menu "kdelibs-4.10.5 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
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