From ce599e4f9f94b4eb00c1b5edb85bce5431ab3df2 Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdeedu@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- kturtle/src/translate.cpp | 107 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 kturtle/src/translate.cpp (limited to 'kturtle/src/translate.cpp') diff --git a/kturtle/src/translate.cpp b/kturtle/src/translate.cpp new file mode 100644 index 00000000..d2c43f16 --- /dev/null +++ b/kturtle/src/translate.cpp @@ -0,0 +1,107 @@ +/* + Copyright (C) 2004 by Cies Breijs + + This program is free software; you can redistribute it and/or + modify it under the terms of version 2 of the GNU General Public + License as published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + + +#include +#include + +#include +#include + +#include "settings.h" + +#include "translate.h" + + + +Translate::Translate() +{ + loadTranslations(); +} + + +QString Translate::name2fuzzy(const QString &name) +{ + if ( !aliasMap[name].isEmpty() ) // translate the alias if any + { + return QString( i18n("'%1' (%2)").arg(keyMap[name]).arg(reverseAliasMap[name]) ); + } + return QString( "'" + keyMap[name] + "'"); +} + +QString Translate::name2key(const QString &name) +{ + return keyMap[name]; +} + +QString Translate::alias2key(const QString &name) +{ + return aliasMap[name]; +} + + +void Translate::loadTranslations() { + QDomDocument KeywordsXML; + + kdDebug(0) << "Loading translation dictionary: "<< locate("data", "kturtle/data/logokeywords." + Settings::logoLanguage() + ".xml") < tag) + QDomElement rootElement = KeywordsXML.documentElement(); + QDomNode n = rootElement.firstChild(); + + while ( !n.isNull() ) + { + QString name, key, alias; + name = n.toElement().attribute("name"); // get the name attribute of + QDomNode m = n.firstChild(); // get into the first child of a + while (true) + { + if( !m.toElement().text().isEmpty() ) + { + if (m.toElement().tagName() == "keyword") + { + key = m.toElement().text(); + keyMap.insert(name, key); + } + if (m.toElement().tagName() == "alias") + { + alias = m.toElement().text(); + aliasMap.insert(alias, key); + reverseAliasMap.insert(key, alias); + } + } + // break when read the last child of the current + if ( m == n.lastChild() ) break; + m = m.nextSibling(); // goto the next element in the current + } + n = n.nextSibling(); // goto the next + } + + kdDebug(0) << "Translation dictionary loaded" <