23#include <QtCore/QStringList>
25#include "abstractlocalizer.h"
31#include <QtCore/QDebug>
35I18ncpNodeFactory::I18ncpNodeFactory() {}
44 QStringLiteral(
"Error: i18ncp tag takes at least three arguments"));
46 auto contextText = expr.at(1);
55 "Error: i18ncp tag first argument must be a static string."));
57 contextText = contextText.mid(1, contextText.size() - 2);
59 auto sourceText = expr.at(2);
68 "Error: i18ncp tag second argument must be a static string."));
70 sourceText = sourceText.mid(1, sourceText.size() - 2);
72 auto pluralText = expr.at(3);
80 pluralText = sourceText;
82 pluralText = pluralText.mid(1, pluralText.size() - 2);
86 for (
auto i = argsStart; i < expr.size(); ++i) {
90 return new I18ncpNode(contextText, sourceText, pluralText, feList);
93I18ncpVarNodeFactory::I18ncpVarNodeFactory() {}
100 if (expr.size() < 6) {
103 QStringLiteral(
"Error: i18ncp_var tag takes at least five arguments"));
106 auto contextText = expr.at(1);
115 "Error: i18ncp_var tag first argument must be a static string."));
117 contextText = contextText.mid(1, contextText.size() - 2);
119 auto sourceText = expr.at(2);
128 "Error: i18ncp_var tag second argument must be a static string."));
130 sourceText = sourceText.mid(1, sourceText.size() - 2);
132 auto pluralText = expr.at(3);
140 pluralText = sourceText;
142 pluralText = pluralText.mid(1, pluralText.size() - 2);
146 for (
auto i = argsStart; i < expr.size() - 2; ++i) {
150 auto resultName = expr.
last();
152 return new I18ncpVarNode(contextText, sourceText, pluralText, feList,
156I18ncpNode::I18ncpNode(
const QString &contextText,
const QString &sourceText,
160 :
Node(parent), m_contextText(contextText), m_sourceText(sourceText),
161 m_pluralText(pluralText), m_filterExpressionList(feList)
170 auto resultString = c->
localizer()->localizePluralContextString(
171 m_sourceText, m_pluralText, m_contextText, args);
176I18ncpVarNode::I18ncpVarNode(
const QString &contextText,
181 :
Node(parent), m_contextText(contextText), m_sourceText(sourceText),
182 m_pluralText(pluralText), m_filterExpressionList(feList),
183 m_resultName(resultName)
193 auto resultString = c->
localizer()->localizePluralContextString(
194 m_sourceText, m_pluralText, m_contextText, args);
196 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
void append(const T &value)
Utility functions used throughout Cutelee.