23 #include <QtCore/QStringList>
25 #include "abstractlocalizer.h"
27 #include "exception.h"
31 #include <QtCore/QDebug>
35 I18ncNodeFactory::I18ncNodeFactory() {}
44 QStringLiteral(
"Error: i18nc tag takes at least two arguments"));
46 auto contextText = expr.at(1);
48 if (!(contextText.startsWith(QLatin1Char(
'"'))
49 && contextText.endsWith(QLatin1Char(
'"')))
50 && !(contextText.startsWith(QLatin1Char(
'\''))
51 && contextText.endsWith(QLatin1Char(
'\'')))) {
55 "Error: i18nc tag first argument must be a static string."));
57 contextText = contextText.mid(1, contextText.size() - 2);
59 auto sourceText = expr.at(2);
61 if (!(sourceText.startsWith(QLatin1Char(
'"'))
62 && sourceText.endsWith(QLatin1Char(
'"')))
63 && !(sourceText.startsWith(QLatin1Char(
'\''))
64 && sourceText.endsWith(QLatin1Char(
'\'')))) {
68 "Error: i18nc tag second argument must be a static string."));
70 sourceText = sourceText.mid(1, sourceText.size() - 2);
72 QList<FilterExpression> feList;
73 for (
auto i = 3; i < expr.size(); ++i) {
77 return new I18ncNode(sourceText, contextText, feList);
80 I18ncVarNodeFactory::I18ncVarNodeFactory() {}
90 QStringLiteral(
"Error: i18nc_var tag takes at least four arguments"));
92 auto contextText = expr.at(1);
94 if (!(contextText.startsWith(QLatin1Char(
'"'))
95 && contextText.endsWith(QLatin1Char(
'"')))
96 && !(contextText.startsWith(QLatin1Char(
'\''))
97 && contextText.endsWith(QLatin1Char(
'\'')))) {
101 "Error: i18nc_var tag first argument must be a static string."));
103 contextText = contextText.mid(1, contextText.size() - 2);
105 auto sourceText = expr.at(2);
107 if (!(sourceText.startsWith(QLatin1Char(
'"'))
108 && sourceText.endsWith(QLatin1Char(
'"')))
109 && !(sourceText.startsWith(QLatin1Char(
'\''))
110 && sourceText.endsWith(QLatin1Char(
'\'')))) {
114 "Error: i18nc_var tag second argument must be a static string."));
116 sourceText = sourceText.mid(1, sourceText.size() - 2);
118 QList<FilterExpression> feList;
119 for (
auto i = 3; i < expr.size() - 2; ++i) {
123 auto resultName = expr.last();
125 return new I18ncVarNode(sourceText, contextText, feList, resultName);
128 I18ncNode::I18ncNode(
const QString &sourceText,
const QString &context,
129 const QList<Cutelee::FilterExpression> &feList,
131 :
Node(parent), m_sourceText(sourceText), m_context(context),
132 m_filterExpressionList(feList)
142 = c->
localizer()->localizeContextString(m_sourceText, m_context, args);
147 I18ncVarNode::I18ncVarNode(
const QString &sourceText,
const QString &context,
148 const QList<Cutelee::FilterExpression> &feList,
149 const QString &resultName, QObject *parent)
150 :
Node(parent), m_sourceText(sourceText), m_context(context),
151 m_filterExpressionList(feList), m_resultName(resultName)
162 = c->
localizer()->localizeContextString(m_sourceText, m_context, args);
164 c->
insert(m_resultName, resultString);
Q_INVOKABLE QStringList smartSplit(const QString &str) const
The Context class holds the context to render a Template with.
std::shared_ptr< AbstractLocalizer > localizer() const
void insert(const QString &name, QObject *object)
An exception for use when implementing template tags.
A FilterExpression object represents a filter expression in a template.
QVariant resolve(OutputStream *stream, Context *c) const
Base class for all nodes.
void streamValueInContext(OutputStream *stream, const QVariant &input, Cutelee::Context *c) const
The OutputStream class is used to render templates to a QTextStream.
The Parser class processes a string template into a tree of nodes.
Node * getNode(const QString &tagContent, Parser *p) const override
void render(OutputStream *stream, Context *c) const override
Node * getNode(const QString &tagContent, Parser *p) const override
void render(OutputStream *stream, Context *c) const override
Utility functions used throughout Cutelee.