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();
49 if (!(sourceText.startsWith(QLatin1Char(
'"'))
50 && sourceText.endsWith(QLatin1Char(
'"')))
51 && !(sourceText.startsWith(QLatin1Char(
'\''))
52 && sourceText.endsWith(QLatin1Char(
'\'')))) {
56 "Error: i18n tag first argument must be a static string."));
58 sourceText = sourceText.mid(1, size - 2);
60 QList<FilterExpression> feList;
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();
84 if (!(sourceText.startsWith(QLatin1Char(
'"'))
85 && sourceText.endsWith(QLatin1Char(
'"')))
86 && !(sourceText.startsWith(QLatin1Char(
'\''))
87 && sourceText.endsWith(QLatin1Char(
'\'')))) {
91 "Error: i18n tag first argument must be a static string."));
93 sourceText = sourceText.mid(1, size - 2);
95 QList<FilterExpression> feList;
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,
106 const QList<Cutelee::FilterExpression> &feList,
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,
123 const QList<Cutelee::FilterExpression> &feList,
124 const QString &resultName, QObject *parent)
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);
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.