removed transcript support for klokalize (required kjs)

This commit is contained in:
Ivailo Monev 2014-11-18 13:51:32 +00:00
parent 6141d2ef50
commit 5185c917de
4 changed files with 1 additions and 2076 deletions

View file

@ -465,39 +465,6 @@ install(TARGETS kde4-config ${INSTALL_TARGETS_DEFAULT_ARGS} )
########### next target ###############
if(NOT WINCE)
# kjs hash stuff for transcript plugin
set( CREATE_HASH_TABLE ${CMAKE_SOURCE_DIR}/kjs/create_hash_table )
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/ktranscript.lut.h
COMMAND ${PERL_EXECUTABLE} ${CREATE_HASH_TABLE}
${CMAKE_CURRENT_SOURCE_DIR}/localization/ktranscript.cpp
> ${CMAKE_CURRENT_BINARY_DIR}/ktranscript.lut.h
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/localization/ktranscript.cpp
)
# the transcript plugin
set( ktranscript_LIB_SRCS
localization/ktranscript.cpp
localization/common_helpers.cpp
)
kde4_add_plugin( ktranscript ${ktranscript_LIB_SRCS} )
target_link_libraries( ktranscript kjs ${QT_QTCORE_LIBRARY} )
if(KDE4_ENABLE_FINAL)
macro_add_file_dependencies(${CMAKE_CURRENT_BINARY_DIR}/ktranscript_final_cpp.cpp ${CMAKE_CURRENT_BINARY_DIR}/ktranscript.lut.h)
else(KDE4_ENABLE_FINAL)
macro_add_file_dependencies(${CMAKE_CURRENT_SOURCE_DIR}/localization/ktranscript.cpp ${CMAKE_CURRENT_BINARY_DIR}/ktranscript.lut.h)
endif(KDE4_ENABLE_FINAL)
install( TARGETS ktranscript DESTINATION ${PLUGIN_INSTALL_DIR} )
endif(NOT WINCE)
########### install files ###############
install( FILES ${CMAKE_CURRENT_BINARY_DIR}/all_languages DESTINATION ${LOCALE_INSTALL_DIR} )
install( FILES localization/entry.desktop DESTINATION ${LOCALE_INSTALL_DIR}/en_US )

View file

@ -27,7 +27,6 @@
#include <klocale_p.h>
#include <klibrary.h>
#include <kstandarddirs.h>
#include <ktranscript_p.h>
#include <kuitsemantics_p.h>
#include "kcatalogname_p.h"
@ -78,11 +77,6 @@ class KLocalizedStringPrivate
QString postFormat (const QString &text,
const QString &lang,
const QString &ctxt) const;
QString substituteTranscript (const QString &trans,
const QString &lang,
const QString &ctry,
const QString &final,
bool &fallback) const;
int resolveInterpolation (const QString &trans, int pos,
const QString &lang,
const QString &ctry,
@ -90,14 +84,9 @@ class KLocalizedStringPrivate
QString &result,
bool &fallback) const;
QVariant segmentToValue (const QString &arg) const;
QString postTranscript (const QString &pcall,
const QString &lang,
const QString &ctry,
const QString &final) const;
static void notifyCatalogsUpdated (const QStringList &languages,
const QList<KCatalogName> &catalogs);
static void loadTranscript ();
};
class KLocalizedStringPrivateStatics
@ -114,9 +103,6 @@ class KLocalizedStringPrivateStatics
QHash<QString, QStringList> scriptModules;
QList<QStringList> scriptModulesToLoad;
bool loadTranscriptCalled;
KTranscript *ktrs;
QHash<QString, KuitSemantics*> formatters;
KLocalizedStringPrivateStatics () :
@ -130,9 +116,6 @@ class KLocalizedStringPrivateStatics
scriptModules(),
scriptModulesToLoad(),
loadTranscriptCalled(false),
ktrs(NULL),
formatters()
{}
@ -271,17 +254,6 @@ QString KLocalizedStringPrivate::toString (const KLocale *locale,
// Scripted translation.
strans = rawtrans.mid(cdpos + s->theFence.length());
// Try to initialize Transcript if not initialized, and script not empty.
if ( !s->loadTranscriptCalled && !strans.isEmpty()
&& locale && locale->useTranscript())
{
if (KGlobal::hasMainComponent())
loadTranscript();
else
kDebug(173) << QString::fromLatin1("Scripted message {%1} before transcript engine can be loaded.")
.arg(shortenMessage(trans));
}
}
else if (cdpos < 0)
{
@ -302,27 +274,6 @@ QString KLocalizedStringPrivate::toString (const KLocale *locale,
// Post-format ordinary translation.
final = postFormat(final, lang, QString::fromLatin1(ctxt));
// If there is also a scripted translation.
if (!strans.isEmpty()) {
// Evaluate scripted translation.
bool fallback;
QString sfinal = substituteTranscript(strans, lang, ctry, final, fallback);
// If any translation produced and no fallback requested.
if (!sfinal.isEmpty() && !fallback) {
final = postFormat(sfinal, lang, QString::fromLatin1(ctxt));
}
}
// Execute any scripted post calls; they cannot modify the final result,
// but are used to set states.
if (s->ktrs != NULL)
{
QStringList pcalls = s->ktrs->postCalls(lang);
foreach(const QString &pcall, pcalls)
postTranscript(pcall, lang, ctry, final);
}
return final;
}
@ -486,62 +437,6 @@ QString KLocalizedStringPrivate::postFormat (const QString &text,
return final;
}
QString KLocalizedStringPrivate::substituteTranscript (const QString &strans,
const QString &lang,
const QString &ctry,
const QString &final,
bool &fallback) const
{
const KLocalizedStringPrivateStatics *s = staticsKLSP;
QMutexLocker lock(kLocaleMutex());
if (s->ktrs == NULL)
// Scripting engine not available.
return QString();
// Iterate by interpolations.
QString sfinal;
fallback = false;
int ppos = 0;
int tpos = strans.indexOf(s->startInterp);
while (tpos >= 0)
{
// Resolve substitutions in preceding text.
QString ptext = substituteSimple(strans.mid(ppos, tpos - ppos),
s->scriptPlchar, true);
sfinal.append(ptext);
// Resolve interpolation.
QString result;
bool fallbackLocal;
tpos = resolveInterpolation(strans, tpos, lang, ctry, final,
result, fallbackLocal);
// If there was a problem in parsing the interpolation, cannot proceed
// (debug info already reported while parsing).
if (tpos < 0) {
return QString();
}
// If fallback has been explicitly requested, indicate global fallback
// but proceed with evaluations (other interpolations may set states).
if (fallbackLocal) {
fallback = true;
}
// Add evaluated interpolation to the text.
sfinal.append(result);
// On to next interpolation.
ppos = tpos;
tpos = strans.indexOf(s->startInterp, tpos);
}
// Last text segment.
sfinal.append(substituteSimple(strans.mid(ppos), s->scriptPlchar, true));
// Return empty string if fallback was requested.
return fallback ? QString() : sfinal;
}
int KLocalizedStringPrivate::resolveInterpolation (const QString &strans,
int pos,
const QString &lang,
@ -686,10 +581,7 @@ int KLocalizedStringPrivate::resolveInterpolation (const QString &strans,
QString msgid = QString::fromUtf8(msg);
QString scriptError;
bool fallbackLocal;
result = s->ktrs->eval(iargs, lang, ctry,
msgctxt, dynctxt, msgid,
args, vals, final, s->scriptModulesToLoad,
scriptError, fallbackLocal);
// s->scriptModulesToLoad will be cleared during the call.
if (fallbackLocal) { // evaluation requested fallback
@ -737,43 +629,6 @@ QVariant KLocalizedStringPrivate::segmentToValue (const QString &seg) const
return vals.at(index);
}
QString KLocalizedStringPrivate::postTranscript (const QString &pcall,
const QString &lang,
const QString &ctry,
const QString &final) const
{
KLocalizedStringPrivateStatics *s = staticsKLSP;
QMutexLocker lock(kLocaleMutex());
if (s->ktrs == NULL)
// Scripting engine not available.
// (Though this cannot happen, we wouldn't be here then.)
return QString();
// Resolve the post call.
QList<QVariant> iargs;
iargs.append(pcall);
QString msgctxt = QString::fromUtf8(ctxt);
QString msgid = QString::fromUtf8(msg);
QString scriptError;
bool fallback;
QString dummy = s->ktrs->eval(iargs, lang, ctry,
msgctxt, dynctxt, msgid,
args, vals, final, s->scriptModulesToLoad,
scriptError, fallback);
// s->scriptModulesToLoad will be cleared during the call.
// If the evaluation went wrong.
if (!scriptError.isEmpty())
{
kDebug(173) << QString::fromLatin1("Post call {%1} for message {%2} failed: %3")
.arg(pcall, shortenMessage(msgid), scriptError);
return QString();
}
return final;
}
static QString wrapNum (const QString &tag, const QString &numstr,
int fieldWidth, const QChar &fillChar)
{
@ -942,35 +797,6 @@ KLocalizedString ki18ncp (const char* ctxt,
return KLocalizedString(ctxt, singular, plural);
}
extern "C"
{
typedef KTranscript *(*InitFunc)();
}
void KLocalizedStringPrivate::loadTranscript ()
{
KLocalizedStringPrivateStatics *s = staticsKLSP;
QMutexLocker lock(kLocaleMutex());
s->loadTranscriptCalled = true;
s->ktrs = NULL; // null indicates that Transcript is not available
KLibrary lib(QLatin1String("ktranscript"));
if (!lib.load()) {
kDebug(173) << "Cannot load transcript plugin:" << lib.errorString();
return;
}
InitFunc initf = (InitFunc) lib.resolveFunction("load_transcript");
if (!initf) {
lib.unload();
kDebug(173) << "Cannot find function load_transcript in transcript plugin.";
return;
}
s->ktrs = initf();
}
void KLocalizedString::notifyCatalogsUpdated (const QStringList &languages,
const QList<KCatalogName> &catalogs)
{

File diff suppressed because it is too large Load diff

View file

@ -1,90 +0,0 @@
/* This file is part of the KDE libraries
Copyright (C) 2007 Chusslove Illich <caslav.ilic@gmx.net>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef KTRANSCRIPT_P_H
#define KTRANSCRIPT_P_H
#include <QVariant>
#include <QList>
#include <QStringList>
#include <QHash>
/**
* @internal
* (used by KLocalizedString)
*
* KTranscript provides support for programmable translations.
* The class is abstract in order to facilitate dynamic loading.
*
* @author Chusslove Illich <caslav.ilic@gmx.net>
* @short class for supporting programmable translations
*/
class KTranscript
{
public:
/**
* Evaluates interpolation.
*
* @param argv list of interpolation tokens
* @param lang language of the translation
* @param ctry locale country
* @param msgctxt message context
* @param dynctxt dynamic context
* @param msgid original message
* @param subs substitutions for message placeholders
* @param vals values that were formatted to substitutions
* @param final finalized ordinary translation
* @param mods scripting modules to load; the list is cleared after loading
* @param error set to the message detailing the problem, if the script
failed; set to empty otherwise
* @param fallback set to true if the script requested fallback to ordinary
translation; set to false otherwise
* @return resolved interpolation if evaluation succeeded,
* empty string otherwise
*/
virtual QString eval (const QList<QVariant> &argv,
const QString &lang,
const QString &ctry,
const QString &msgctxt,
const QHash<QString, QString> &dynctxt,
const QString &msgid,
const QStringList &subs,
const QList<QVariant> &vals,
const QString &final,
QList<QStringList> &mods,
QString &error,
bool &fallback) = 0;
/**
* Returns the list of calls to execute an all messages after the
* interpolations are done, as evaluations with no parameters.
*
* @param lang language of the translation
* @return list of post calls
*/
virtual QStringList postCalls (const QString &lang) = 0;
/**
* Destructor.
*/
virtual ~KTranscript () {}
};
#endif