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

klettres

  • sources
  • kde-4.14
  • kdeedu
  • klettres
  • src
langutils.cpp
Go to the documentation of this file.
1 /*
2  Copyright 2007 Pino Toscano <pino@kde.org>
3  Copyright 2007-2008 Anne-Marie Mahfouf <annma@kde.org>
4 
5  This program is free software; you can redistribute it and/or
6  modify it under the terms of the GNU General Public
7  License as published by the Free Software Foundation; either
8  version 2 of the License, or (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  */
19 
20 //project headers
21 #include "langutils.h"
22 #include "prefs.h"
23 
24 #include <QDir>
25 
26 #include <KGlobal>
27 #include <KLocale>
28 #include <KStandardDirs>
29 
30 bool LangUtils::hasSpecialChars(const QString& lang)
31 {
32  if (lang== "cs"
33  || lang== "da"
34  || lang== "sk"
35  || lang== "es"
36  || lang== "de"
37  || lang== "hu"
38  || lang== "nds"
39  || lang== "lt")
40  return true;
41  return false;
42 }
43 
44 bool LangUtils::isIndian(const QString& lang)
45 {
46  if (lang == "kn"
47  || lang == "ml"
48  || lang == "te"
49  || lang == "pa")
50  return true;
51  return false;
52 }
53 
54 QStringList LangUtils::getLanguages()
55 {
56  QStringList m_languages;
57  m_languages.clear();
58  //the program scans in klettres/data/ to see what languages data is found
59  const QStringList mdirs = KGlobal::dirs()->findDirs("data", "klettres/");
60  //if (mdirs.isEmpty()) return NULL;
61  for (QStringList::const_iterator it =mdirs.constBegin(); it !=mdirs.constEnd(); ++it ) {
62  QDir dir(*it);
63  m_languages += dir.entryList(QDir::Dirs, QDir::Name);
64  m_languages.removeAll(".");
65  m_languages.removeAll("..");
66  }
67  m_languages.removeAll("pics");
68  m_languages.removeAll("data");
69  m_languages.removeAll("icons");
70  m_languages.sort();
71 
72  //find duplicated entries in KDEDIR and KDEHOME
73  QStringList temp_languages;
74  for (int i=0; i<m_languages.count(); i++) {
75  if (m_languages.count(m_languages[i])>1) {
76  temp_languages.append(m_languages[i]);
77  m_languages.removeAll(m_languages[i]);
78  }
79  for (int i=0; i<temp_languages.count(); i++) {
80  if (i%2==0)
81  m_languages.append(temp_languages[i]);//append 1 of the 2 instances found
82  }
83  temp_languages.clear();
84  }
85  //TODO TEST in FRENCH
86  m_languages.sort();
87  kDebug() <<m_languages;
88  return m_languages;
89 }
90 
91 QStringList LangUtils::getLanguagesNames(QStringList languagesList)
92 {
93  //we look in $KDEDIR/share/locale/all_languages from /kdelibs/kdecore/all_languages
94  //to find the name of the country
95  //corresponding to the code and the language the user set
96  QStringList languagesNames;
97  KConfig entry(KStandardDirs::locate("locale", "all_languages"));
98 
99  foreach(const QString &language, languagesList) {
100  if (language == "hi-ro") {
101  languagesNames.append(i18n("Romanized Hindi"));
102  } else if (language == "lug_UG") {
103  languagesNames.append(i18n("Luganda"));
104  } else if (language == "ep") {
105  languagesNames.append(i18n("English Phonics"));
106  } else {
107  KConfigGroup group = entry.group(language);
108  QString languageName = group.readEntry("Name");
109  if (languageName.isEmpty()) {
110  languageName = i18nc("@item:inlistbox no language for that locale", "None");
111  }
112  languagesNames.append(languageName);
113  }
114  }
115  //never sort m_languageNames as it's m_languages translated
116  return languagesNames;
117 }
118 
119 void LangUtils::writeLangConfig()
120 {
121  //write the present languages in config so they cannot be downloaded
122  KConfigGroup config(KGlobal::config(), "KNewStuffStatus");
123  QStringList m_languages = getLanguages();
124  for (int i=0; i<m_languages.count(); i++) {
125  QString tmp = m_languages[i];
126  if (!config.readEntry(tmp, QString()).isEmpty()) {
127  config.writeEntry(tmp, QDate::currentDate().toString());
128  }
129  }
130  config.sync();
131 }
132 
133 
QList::clear
void clear()
LangUtils::isIndian
static bool isIndian(const QString &lang)
Indian languages cannot have isLetter()
Definition: langutils.cpp:44
prefs.h
QList::const_iterator
QList::count
int count(const T &value) const
QList::append
void append(const T &value)
QString::isEmpty
bool isEmpty() const
QList::removeAll
int removeAll(const T &value)
QString
QStringList
QDir
QDir::entryList
QStringList entryList(QFlags< QDir::Filter > filters, QFlags< QDir::SortFlag > sort) const
QDate::currentDate
QDate currentDate()
langutils.h
QStringList::sort
void sort()
LangUtils::writeLangConfig
static void writeLangConfig()
Definition: langutils.cpp:119
QList::constEnd
const_iterator constEnd() const
QList::constBegin
const_iterator constBegin() const
LangUtils::getLanguagesNames
static QStringList getLanguagesNames(QStringList languagesList)
All available languages translated names.
Definition: langutils.cpp:91
LangUtils::hasSpecialChars
static bool hasSpecialChars(const QString &lang)
Definition: langutils.cpp:30
LangUtils::getLanguages
static QStringList getLanguages()
Available languages ISO names.
Definition: langutils.cpp:54
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:12:27 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

klettres

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

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

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