Skip to content

Commit

Permalink
i18n
Browse files Browse the repository at this point in the history
  • Loading branch information
systempuntoout committed Nov 16, 2011
1 parent 2f65d50 commit cee7f1e
Show file tree
Hide file tree
Showing 16 changed files with 231 additions and 116 deletions.
14 changes: 6 additions & 8 deletions app/config/settings.py
@@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-
#Meta
VERSION = '0.9.0.7'
CMS_NAME = u"GAE Cupboard"
AUTHOR_NAME = u"systempuntoout"
SLOGAN = u"Ingredients for your Google App Engine recipes"
Expand Down Expand Up @@ -33,6 +32,7 @@
![test](/images/systempuntooutmail.jpg "mail")
"""

FOOTER = " | ".join([u"© "+ AUTHOR_NAME, CMS_NAME,"Powered by Google App Engine"])


#Views
Expand All @@ -59,17 +59,15 @@
ADSENSE_CHANNEL_ID = '2124691773'
FEED_PROXY = 'http://feeds.feedburner.com/gaecupboard/fb'
FEED_PROXY_USER_AGENT = 'FeedBurner'
GOOGLE_SITE_VERIFICATION_KEY = "m05zkgXk41nY4dXLheGpLdTiTnx-JduC2XOamAra_6Q"
YAHOO_SITE_VERIFICATION_KEY = "88698ce39daf8603"


#Errors
RELAXING_MESSAGE_ERROR = "..cumulus clouds are white, puffy clouds that look like pieces of floating cotton.. "
GENERIC_ERROR = "Ooooops, it works on my machine. Please try again later."
NOT_FOUND_ERROR = "Not found!"
SERVER_ERROR = "Server problem"
#Stuff
BOTS=['Googlebot','Slurp','Twiceler','msnbot','KaloogaBot','YodaoBot','Baiduspider','googlebot','Speedy Spider','DotBot']
MARKUPS = ['Markdown','Html']
DEFAULT_MARKUP = ['Markdown']

DEFAULT_LANGUAGE = 'en'
DATE_FORMAT = '%d %B, %Y'
#Mapping Discovery
AUTO_CONTENT_BY_LINK = {
'http://stackoverflow.com':{
Expand Down
97 changes: 97 additions & 0 deletions app/config/translate.py
@@ -0,0 +1,97 @@
# -*- coding: utf-8 -*-
en={}
it={}

#Errors

en['PAGE_NOT_FOUND_ERROR']=u"Not found!"
it['PAGE_NOT_FOUND_ERROR']=u"Non trovato"

en['SERVER_ERROR']=u"Not found!"
it['SERVER_ERROR']=u"Non trovato"

en['RELAXING_MESSAGE_ERROR'] = u"..cumulus clouds are white, puffy clouds that look like pieces of floating cotton.. "
it['RELAXING_MESSAGE_ERROR'] = u"Il Server ha avuto un problema nell'elaborazione della richiesta, prego riprovare più tardi"

en['POST_NOT_FOUND_ERROR']=u"No posts found!"
it['POST_NOT_FOUND_ERROR']=u"Nessun articolo trovato"

#Navigation

en['ROUTE_ABOUT']=u"about"
it['ROUTE_ABOUT']=u"chisiamo"

en['ROUTE_POST']=u"post"
it['ROUTE_POST']=u"articolo"

en['ROUTE_FEATURED']=u"featured"
it['ROUTE_FEATURED']=u"dasegnalare"

en['ROUTE_SEARCH']=u"search"
it['ROUTE_SEARCH']=u"cerca"

en['ROUTE_TAGCLOUD']=u"tagcloud"
it['ROUTE_TAGCLOUD']=u"tags"

en['TITLE_ERROR']=u"Error"
it['TITLE_ERROR']=u"Errore"

en['TITLE_POST']=u"Posts"
it['TITLE_POST']=u"Articoli"

en['TITLE_ABOUT']=u"About"
it['TITLE_ABOUT']=u"Chi Siamo"

en['TITLE_FEATURED']=u"Featured"
it['TITLE_FEATURED']=u"Da segnalare"

en['TITLE_SEARCH']=u"Search"
it['TITLE_SEARCH']=u"Cerca"

en['TITLE_TAGCLOUD']=u"Tag cloud"
it['TITLE_TAGCLOUD']=u"Tags"

en['TITLE_HOME']=u"Home"
it['TITLE_HOME']=u"Home"

en['META_TAGCLOUD']=u"Weighted tags list that can be filtered"
it['META_TAGCLOUD']=u"Lista di tag che consentono di filtrare gli articoli in base all'argomento"


#Various
en['POSTS']=u"Posts"
it['POSTS']=u"Articoli"

en['TAGS']=u"Tags"
it['TAGS']=u"Tags"

en['BOOKS']=u"Books"
it['BOOKS']=u"Libri"

en['CATEGORIES']=u"Categories"
it['CATEGORIES']=u"Categorie"

en['DETAILS']=u"DETAILS"
it['DETAILS']=u"Dettagli"

en['TAGS_SHOWN']=u"Tags shown"
it['TAGS_SHOWN']=u"Tags visualizzati"

en['FILTER']=u"Filter"
it['FILTER']=u"Filtro"

en['EVEN_MORE']=u"Even more"
it['EVEN_MORE']=u"Mostra tutti"

en['PREV']=u"Prev"
it['PREV']=u"Indietro"

en['NEXT']=u"Next"
it['NEXT']=u"Avanti"

en['MORE']=u"More"
it['MORE']=u"Altri"

en['SEARCH']=u"search"
it['SEARCH']=u"cerca"

19 changes: 11 additions & 8 deletions app/config/urls.py
@@ -1,17 +1,20 @@
import web
i18ns = web.i18ns

"""
Routes to controllers
"""

urls = (
'/tag', 'app.controllers.main.Tags',
'/tag/(.*)', 'app.controllers.main.Tags',
'/featured', 'app.controllers.main.Featured',
'/tagcloud','app.controllers.main.TagCloud',
'/%s' % i18ns['ROUTE_FEATURED'], 'app.controllers.main.Featured',
'/%s' % i18ns['ROUTE_TAGCLOUD'],'app.controllers.main.TagCloud',
'/submit','app.controllers.main.Submit',
'/post', 'app.controllers.main.Post',
'/post/([\w_-]+)(?:/([\w-]+))?/?', 'app.controllers.main.Post',
'/about', 'app.controllers.main.About',
'/search', 'app.controllers.main.Search',
'/%s' % i18ns['ROUTE_POST'], 'app.controllers.main.Post',
'/%s/([\w_-]+)(?:/([\w-]+))?/?' % i18ns['ROUTE_POST'], 'app.controllers.main.Post',
'/%s' % i18ns['ROUTE_ABOUT'], 'app.controllers.main.About',
'/%s' % i18ns['ROUTE_SEARCH'], 'app.controllers.main.Search',
'/img/([\w_-]+)(?:/.*)?', 'app.controllers.main.Image',
'/ajax/tags','app.controllers.ajax.Tags',
'/ajax/links','app.controllers.ajax.Links',
Expand All @@ -37,6 +40,6 @@

sitemap_urls = ('/',
'/tag',
'/post',
'/%s' % i18ns['ROUTE_POST'],
'/featured',
'/about')
'/%s' % i18ns['ROUTE_ABOUT'])
1 change: 0 additions & 1 deletion app/controllers/ajax.py
@@ -1,5 +1,4 @@
from google.appengine.api import memcache
from app.config.settings import GENERIC_ERROR, NOT_FOUND_ERROR
import logging, web
import app.db.models as models
from google.appengine.ext import ereporter
Expand Down
23 changes: 12 additions & 11 deletions app/controllers/main.py
Expand Up @@ -19,6 +19,7 @@
ereporter.register_logger()

render = web.render
i18ns = web.i18ns

def render_template(content, **kwargs):
"""
Expand All @@ -41,7 +42,7 @@ def render_error(error, **kwargs):
"""
Renders the error page
"""
return render.layout(render.oops(error), title ='Error', navbar = False)
return render.layout(render.oops(error), title = i18ns['TITLE_ERROR'], navbar = False)


class Index:
Expand All @@ -59,7 +60,7 @@ def GET(self):
selected_category = category,
pagination = utils.Pagination(posts_count, page, POSTS_PER_PAGE),
is_user_admin = users.is_current_user_admin()),
title = "%s" % (category if category else 'Home'))
title = "%s" % (category if category else i18ns['TITLE_HOME']))


class Post:
Expand All @@ -72,7 +73,7 @@ def GET(self, post_id = None, slug = None):
if post_id and not slug:
post = models.Post.get(post_id)
if post:
return web.seeother('/post/%s/%s' % (post_id, post.slug))
return web.seeother('/%s/%s/%s' % (i18ns['ROUTE_POST'], post_id, post.slug))
else:
raise web.notfound()
#Get post
Expand All @@ -84,7 +85,7 @@ def GET(self, post_id = None, slug = None):
if post:
#Return to canonical if the slug is truncated
if slug and slug.strip() != post.slug:
return web.seeother('/post/%s/%s' % (post_id, post.slug))
return web.seeother('/%s/%s/%s' % (i18ns['ROUTE_POST'],post_id, post.slug))

prev_post, next_post = models.Post.get_prev_next(post)
else:
Expand All @@ -96,7 +97,7 @@ def GET(self, post_id = None, slug = None):
utils.ContentDiscoverer(post.link, post.category).get_content_block(),
is_user_admin = users.is_current_user_admin()),
title = post.title,
canonical = "post/%s" % (post.get_path()),
canonical = "%s/%s" % (i18ns['ROUTE_POST'],post.get_path()),
meta_description = utils.get_metadescription(post))
except BadKeyError:
raise web.notfound()
Expand Down Expand Up @@ -143,7 +144,7 @@ def GET(self, tags = None):
category,
pagination = utils.Pagination(posts_count, page, POSTS_PER_PAGE),
is_user_admin = users.is_current_user_admin()),
title = "%s %s" % (category if category else '',' '.join(tags) if tags else ('Posts' if not category else '')))
title = "%s %s" % (category if category else '',' '.join(tags) if tags else (i18ns['TITLE_POST'] if not category else '')))


class TagCloud:
Expand All @@ -158,8 +159,8 @@ def GET(self):
else:
tag_cloud = models.Tag.get_tags(MAIN_CLOUDSIZE)
return render_template(render.tagcloud(tag_cloud, show_all),
title = 'Tag cloud',
meta_description = 'Weighted tags list that can be filtered')
title = i18ns['TITLE_TAGCLOUD'],
meta_description = i18ns['META_TAGCLOUD'])

class Featured:
"""
Expand All @@ -169,21 +170,21 @@ def GET(self):
featured_posts = models.Post.get_featured_posts()

return render_template(render.featured(featured_posts, is_user_admin = users.is_current_user_admin()),
title = 'Featured')
title = i18ns['TITLE_FEATURED'])
class About:
"""
About
"""
@cachepage()
def GET(self):
return render_template(render.about(), title = 'About')
return render_template(render.about(), title = i18ns['TITLE_ABOUT'])

class Search:
"""
Search
"""
def GET(self):
return render_template(render.search(), title = 'Search')
return render_template(render.search(), title = i18ns['TITLE_SEARCH'])

class Feed:
"""
Expand Down
14 changes: 13 additions & 1 deletion app/utility/utils.py
Expand Up @@ -12,6 +12,7 @@

from app.config.settings import *
from app.lib import pyso
import app.config.translate as translate



Expand Down Expand Up @@ -173,4 +174,15 @@ def proxyfunc(self, *args, **kw):
CACHE[url] = func(self, *args, **kw)
return CACHE[url]
return proxyfunc
return decorator
return decorator


def get_i18ns(language):
"""
Return a dictionary with i18n strings of a given language (english by default)
"""
if hasattr(translate,language):
i18ns=getattr(translate,language)
else:
i18ns=translate.en
return i18ns

0 comments on commit cee7f1e

Please sign in to comment.