Permalink
Browse files

add language settings.

  • Loading branch information...
1 parent aa40ae5 commit c4cd4969e55790913be8f39e5c882054a09a7f1f whtsky committed Jul 21, 2012
View
@@ -4,6 +4,7 @@
from __future__ import print_function
import time
from init_db import db
+import settings
from handlers.utils import username_validator
import hashlib
@@ -37,6 +38,7 @@
'description': '',
'created': time.time(),
'role': 3,
+'language': settings.default_locale,
'block': [],
'like': [], # topics
'follow': [], # users
View
@@ -127,11 +127,11 @@ table{
margin-top: $spacing;
text-align: center;
- #followed, #favorite {
+ td {
width: 33%
}
- #liked{
+ .liked{
width: 34%;
border-left: 1px solid rgba(100, 100, 100, 0.4);
border-right: 1px solid rgba(100, 100, 100, 0.4);
View
@@ -3,6 +3,7 @@
import re
import tornado.web
import tornado.escape
+import tornado.locale
import time
from bson.objectid import ObjectId
import hashlib
@@ -19,6 +20,11 @@ def get_current_user(self):
password = self.get_secure_cookie('user')
return self.application.db.members.find_one({'password': password})
+ def get_user_locale(self):
+ if not self.current_user:
+ return None
+ return tornado.locale.get(self.current_user['language'])
+
@property
def db(self):
return self.application.db
View
@@ -3,6 +3,7 @@
import time
import hashlib
import tornado.web
+import tornado.locale
from bson.objectid import ObjectId
from . import BaseHandler
from .utils import username_validator, email_validator
@@ -43,6 +44,7 @@ def post(self):
'website': '',
'description': '',
'created': time.time(),
+ 'language': self.settings['default_locale'],
'role': 1, # TODO:send mail.
'block': [],
'like': [], # topics
@@ -87,16 +89,20 @@ def get(self):
class SettingsHandler(BaseHandler):
@tornado.web.authenticated
def get(self):
- self.render('account/settings.html')
+ self.render('account/settings.html', locales=self.application.locales)
@tornado.web.authenticated
def post(self):
website = self.get_argument('website', '')
description = self.get_argument('description', '')
+ language = self.get_argument('language')
if len(description) > 1500:
self.flash("The description is too lang")
- self.db.members.update({'_id': self.current_user['_id']},
- {'$set': {'website': website, 'description': description}})
+ self.db.members.update({'_id': self.current_user['_id']}, {'$set': {
+ 'website': website,
+ 'description': description,
+ 'language': language
+ }})
self.flash('Saved successfully', type='success')
self.redirect('/account/settings')
View
@@ -11,8 +11,8 @@ def get(self):
count = members.count()
p = int(self.get_argument('p', 1))
members = members[(p - 1) * per_page:p * per_page]
- self.render('member/list.html', per_page=per_page, members=members, count=count,
- p=p)
+ self.render('member/list.html', per_page=per_page, members=members,
+ count=count, p=p)
class MemberPageHandler(BaseHandler):
@@ -85,7 +85,7 @@ class ChangeRoleHandler(BaseHandler):
def post(self, name):
role = int(self.get_argument('role', 100))
if self.current_user['role'] < 3:
- self.check_role(role_min=role+1)
+ self.check_role(role_min=role + 1)
name = name.lower()
self.db.members.update({'name_lower': name},
{'$set': {'role': role}})
View
@@ -20,7 +20,7 @@ class TopicHandler(BaseHandler):
def get(self, topic_id):
if self.current_user:
self.db.notifications.update({
- 'topic': topic_id, 'to':self.current_user['name_lower']
+ 'topic': topic_id, 'to': self.current_user['name_lower']
}, {'$set': {'read': True}})
topic = self.get_topic(topic_id)
replies = self.db.replies.find({'topic': topic_id},
View
No changes.
View
@@ -15,6 +15,7 @@
"Replies",回复
"Description",简介
"Website",网站
+"Language",语言
"Author",作者
"Code Block Example",代码块示例
"Choose a node",选择一个节点
View
12 main.py
@@ -14,7 +14,8 @@
ROOT = os.path.abspath(os.path.dirname(__file__))
define('port', default=8888, help='run on the given port', type=int)
-define('settings', default=os.path.join(ROOT, 'settings.py'), help='path to the settings file.', type=str)
+define('settings', default=os.path.join(ROOT, 'settings.py'),
+ help='path to the settings file.', type=str)
class Application(tornado.web.Application):
@@ -35,7 +36,14 @@ def __init__(self):
self.db = db
tornado.locale.load_translations(os.path.join(ROOT, "locale"))
- tornado.locale.set_default_locale('zh_CN')
+ tornado.locale.set_default_locale(settings['default_locale'])
+ supported_locales = tornado.locale.get_supported_locales()
+ supported_locales.sort()
+ locales = []
+ for locale in supported_locales:
+ locale = (locale, tornado.locale.LOCALE_NAMES[locale]['name'])
+ locales.append(locale)
+ self.locales = tuple(locales)
def main():
View
@@ -1,3 +1,3 @@
-tornado
-pymongo
-pygments
+tornado>=2.3
+pymongo>=2.2.1
+pygments>=1.5
View
@@ -4,12 +4,14 @@
mongodb_port = 27017
database_name = 'forum'
+
forum_title = 'site_name'
forum_url = 'http://xxx.com/'
# forum_url MUST ends with '/'
#static_path = ''
#static_url_prefix = 'http://assets.xxx.com'
+default_locale = 'zh_CN'
gmt_offset = 8
notifications_per_page = 10
members_per_page = 100
@@ -21,4 +23,4 @@
cookie_secret = 'hey reset me!'
gzip = False
-debug = True
+debug = True
View

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -32,6 +32,20 @@
<textarea class="input-xxlarge" id="description" name="description" rows="10">{{ current_user['description'] }}</textarea>
</div>
</div>
+ <div class="control-group">
+ <label class="control-label" for="language">{{ _("Language") }}</label>
+ <div class="controls">
+ <select name="language" id="language">
+ {% for locale in locales %}
+ <option value="{{ locale[0] }}"
+ {% if current_user['language'] == locale[0] %}
+ selected="selected"
+ {% end %}
+ >{{ locale[1] }}</option>
+ {% end %}
+ </select>
+ </div>
+ </div>
<div class="form-actions">
<button type="submit" class="btn btn-primary">{{ _("Save") }}</button>
</div>
View
@@ -80,24 +80,40 @@
{% end %}
</div>
<table id="current_info">
- <td id="followed">
+ <tr>
+ <td>
<a href="/account/followed">
<span>{{ len(current_user['follow']) }}</span>
- <p>{{ _("Followed Members") }}</p>
</a>
</td>
- <td id="liked">
+ <td class="liked">
<a href="/account/liked">
<span>{{ len(current_user['like']) }}</span>
- <p>{{ _("Liked Topics") }}</p>
</a>
</td>
- <td id="favorite">
+ <td>
<a href="/account/favorited">
<span>{{ len(current_user['favorite']) }}</span>
- <p>{{ _("Favorite Nodes") }}</p>
</a>
</td>
+ </tr>
+ <tr>
+ <td>
+ <a href="/account/followed">
+ <p>{{ _("Followed Members") }}</p>
+ </a>
+ </td>
+ <td class="liked">
+ <a href="/account/liked">
+ <p>{{ _("Liked Topics") }}</p>
+ </a>
+ </td>
+ <td>
+ <a href="/account/favorited">
+ <p>{{ _("Favorite Nodes") }}</p>
+ </a>
+ </td>
+ </tr>
</table>
<footer>
<a href="/account/notifications">

0 comments on commit c4cd496

Please sign in to comment.