2
This file is part of the Grantlee template system.
4
Copyright (c) 2010 Stephen Kelly <steveire@gmail.com>
6
This library is free software; you can redistribute it and/or
7
modify it under the terms of the GNU Lesser General Public
8
License as published by the Free Software Foundation; either version
9
2.1 of the Licence, or (at your option) any later version.
11
This library is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
Lesser General Public License for more details.
16
You should have received a copy of the GNU Lesser General Public
17
License along with this library. If not, see <http://www.gnu.org/licenses/>.
21
#include "with_locale.h"
23
#include "exception.h"
28
#include <abstractlocalizer.h>
30
WithLocaleNodeFactory::WithLocaleNodeFactory()
35
Node* WithLocaleNodeFactory::getNode( const QString &tagContent, Parser *p ) const
37
QStringList expr = smartSplit( tagContent );
39
if ( expr.size() != 2 ) {
40
throw Grantlee::Exception( TagSyntaxError, QString::fromLatin1( "%1 expected format is for example 'with_locale \"de_DE\"'" ).arg( expr.first() ) );
43
FilterExpression fe( expr.at( 1 ), p );
45
WithLocaleNode *n = new WithLocaleNode( fe, p );
46
NodeList nodeList = p->parse( n, QLatin1String( "endwith_locale" ) );
47
n->setNodeList( nodeList );
54
WithLocaleNode::WithLocaleNode( const FilterExpression &localeName, QObject *parent )
55
: Node( parent ), m_localeName( localeName )
59
void WithLocaleNode::setNodeList( NodeList nodeList )
64
void WithLocaleNode::render( OutputStream *stream, Context *c )
66
const QString name = Grantlee::getSafeString( m_localeName.resolve( c ) ).get();
69
c->localizer()->pushLocale( name );
70
m_list.render( stream, c );
71
c->localizer()->popLocale();