~ubuntu-branches/ubuntu/trusty/grantlee/trusty

« back to all changes in this revision

Viewing changes to templates/i18n/with_locale.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2010-12-07 09:19:01 UTC
  • Revision ID: james.westby@ubuntu.com-20101207091901-hsfsvnkxdshv4k8g
Tags: 0.1.7-0ubuntu3
Revert previous upload and try again with the correct patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
  This file is part of the Grantlee template system.
3
 
 
4
 
  Copyright (c) 2010 Stephen Kelly <steveire@gmail.com>
5
 
 
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.
10
 
 
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.
15
 
 
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/>.
18
 
 
19
 
*/
20
 
 
21
 
#include "with_locale.h"
22
 
 
23
 
#include "exception.h"
24
 
#include "parser.h"
25
 
#include <util.h>
26
 
 
27
 
#include <QDebug>
28
 
#include <abstractlocalizer.h>
29
 
 
30
 
WithLocaleNodeFactory::WithLocaleNodeFactory()
31
 
{
32
 
 
33
 
}
34
 
 
35
 
Node* WithLocaleNodeFactory::getNode( const QString &tagContent, Parser *p ) const
36
 
{
37
 
  QStringList expr = smartSplit( tagContent );
38
 
 
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() ) );
41
 
  }
42
 
 
43
 
  FilterExpression fe( expr.at( 1 ), p );
44
 
 
45
 
  WithLocaleNode *n = new WithLocaleNode( fe, p );
46
 
  NodeList nodeList = p->parse( n, QLatin1String( "endwith_locale" ) );
47
 
  n->setNodeList( nodeList );
48
 
  p->removeNextToken();
49
 
 
50
 
  return n;
51
 
}
52
 
 
53
 
 
54
 
WithLocaleNode::WithLocaleNode( const FilterExpression &localeName, QObject *parent )
55
 
  : Node( parent ), m_localeName( localeName )
56
 
{
57
 
}
58
 
 
59
 
void WithLocaleNode::setNodeList( NodeList nodeList )
60
 
{
61
 
  m_list = nodeList;
62
 
}
63
 
 
64
 
void WithLocaleNode::render( OutputStream *stream, Context *c )
65
 
{
66
 
  const QString name = Grantlee::getSafeString( m_localeName.resolve( c ) ).get();
67
 
 
68
 
  c->push();
69
 
  c->localizer()->pushLocale( name );
70
 
  m_list.render( stream, c );
71
 
  c->localizer()->popLocale();
72
 
  c->pop();
73
 
}
74