23 #include <QtCore/QStringList> 25 #include "abstractlocalizer.h" 27 #include "exception.h" 31 #include <QtCore/QDebug> 35 I18nNodeFactory::I18nNodeFactory() {}
44 QStringLiteral(
"Error: i18n tag takes at least one argument"));
46 auto sourceText = expr.at(1);
47 auto size = sourceText.size();
56 "Error: i18n tag first argument must be a static string."));
58 sourceText = sourceText.mid(1, size - 2);
61 for (
auto i = 2; i < expr.size(); ++i) {
65 return new I18nNode(sourceText, feList);
68 I18nVarNodeFactory::I18nVarNodeFactory() {}
79 QStringLiteral(
"Error: i18n_var tag takes at least three arguments"));
81 auto sourceText = expr.at(1);
82 auto size = sourceText.size();
91 "Error: i18n tag first argument must be a static string."));
93 sourceText = sourceText.mid(1, size - 2);
96 for (
auto i = 2; i < expr.size() - 2; ++i) {
100 auto resultName = expr.last();
102 return new I18nVarNode(sourceText, feList, resultName);
105 I18nNode::I18nNode(
const QString &sourceText,
108 :
Node(parent), m_sourceText(sourceText), m_filterExpressionList(feList)
117 const auto resultString = c->
localizer()->localizeString(m_sourceText, args);
122 I18nVarNode::I18nVarNode(
const QString &sourceText,
125 :
Node(parent), m_sourceText(sourceText), m_filterExpressionList(feList),
126 m_resultName(resultName)
136 auto resultString = c->
localizer()->localizeString(m_sourceText, args);
138 c->
insert(m_resultName, resultString);
The Context class holds the context to render a Template with.
Node * getNode(const QString &tagContent, Parser *p) const override
Base class for all nodes.
Utility functions used throughout Cutelee.
The OutputStream class is used to render templates to a QTextStream.
void append(QList< T > &&value)
QVariant resolve(OutputStream *stream, Context *c) const
std::shared_ptr< AbstractLocalizer > localizer() const
The Parser class processes a string template into a tree of nodes.
void render(OutputStream *stream, Context *c) const override
A FilterExpression object represents a filter expression in a template.
void render(OutputStream *stream, Context *c) const override
Q_INVOKABLE QStringList smartSplit(const QString &str) const
void streamValueInContext(OutputStream *stream, const QVariant &input, Cutelee::Context *c) const
Node * getNode(const QString &tagContent, Parser *p) const override
void insert(const QString &name, QObject *object)
An exception for use when implementing template tags.