summaryrefslogtreecommitdiffstats
path: root/tools/linguist/shared/translator.h
diff options
context:
space:
mode:
Diffstat (limited to 'tools/linguist/shared/translator.h')
-rw-r--r--tools/linguist/shared/translator.h31
1 files changed, 26 insertions, 5 deletions
diff --git a/tools/linguist/shared/translator.h b/tools/linguist/shared/translator.h
index fb9bd2d..3b7bd64 100644
--- a/tools/linguist/shared/translator.h
+++ b/tools/linguist/shared/translator.h
@@ -118,6 +118,17 @@ public:
TranslatorSaveMode m_saveMode;
};
+class TMMKey {
+public:
+ TMMKey(const TranslatorMessage &msg)
+ { context = msg.context(); source = msg.sourceText(); comment = msg.comment(); }
+ bool operator==(const TMMKey &o) const
+ { return context == o.context && source == o.source && comment == o.comment; }
+ QString context, source, comment;
+};
+Q_DECLARE_TYPEINFO(TMMKey, Q_MOVABLE_TYPE);
+inline uint qHash(const TMMKey &key) { return qHash(key.context) ^ qHash(key.source) ^ qHash(key.comment); }
+
class Translator
{
public:
@@ -125,14 +136,12 @@ public:
bool load(const QString &filename, ConversionData &err, const QString &format /* = "auto" */);
bool save(const QString &filename, ConversionData &err, const QString &format /* = "auto" */) const;
- bool release(QFile *iod, ConversionData &cd) const;
int find(const TranslatorMessage &msg) const;
- TranslatorMessage find(const QString &context,
+ int find(const QString &context,
const QString &comment, const TranslatorMessage::References &refs) const;
- bool contains(const QString &context) const;
- TranslatorMessage find(const QString &context) const;
+ int find(const QString &context) const;
void replaceSorted(const TranslatorMessage &msg);
void extend(const TranslatorMessage &msg); // Only for single-location messages
@@ -171,7 +180,6 @@ public:
void setSourceLanguageCode(const QString &languageCode) { m_sourceLanguage = languageCode; }
static QString guessLanguageCodeFromFileName(const QString &fileName);
QList<TranslatorMessage> messages() const;
- QList<TranslatorMessage> translatedMessages() const;
static QStringList normalizedTranslations(const TranslatorMessage &m, int numPlurals);
void normalizeTranslations(ConversionData &cd);
QStringList normalizedTranslations(const TranslatorMessage &m, ConversionData &cd, bool *ok) const;
@@ -179,6 +187,7 @@ public:
int messageCount() const { return m_messages.size(); }
TranslatorMessage &message(int i) { return m_messages[i]; }
const TranslatorMessage &message(int i) const { return m_messages.at(i); }
+ const TranslatorMessage &constMessage(int i) const { return m_messages.at(i); }
void dump() const;
// additional file format specific data
@@ -212,6 +221,11 @@ public:
};
private:
+ void insert(int idx, const TranslatorMessage &msg);
+ void addIndex(int idx, const TranslatorMessage &msg) const;
+ void delIndex(int idx) const;
+ void ensureIndexed() const;
+
typedef QList<TranslatorMessage> TMM; // int stores the sequence position.
TMM m_messages;
@@ -230,11 +244,18 @@ private:
QString m_language;
QString m_sourceLanguage;
ExtraData m_extra;
+
+ mutable bool m_indexOk;
+ mutable QHash<QString, int> m_ctxCmtIdx;
+ mutable QHash<QString, int> m_idMsgIdx;
+ mutable QHash<TMMKey, int> m_msgIdx;
};
bool getNumerusInfo(QLocale::Language language, QLocale::Country country,
QByteArray *rules, QStringList *forms, const char **gettextRules);
+bool saveQM(const Translator &translator, QIODevice &dev, ConversionData &cd);
+
/*
This is a quick hack. The proper way to handle this would be
to extend Translator's interface.