forked from I2P_Developers/i2p.www
merge of '5b4836353e90a3c1e388a18fe4184b748f920317'
and '6fd06d2ac31dd55d96ed51f368f4b3cf5c5faef0'
This commit is contained in:
@@ -32,6 +32,17 @@ SUPPORTED_LANGS = [
|
||||
# 'el',
|
||||
]
|
||||
|
||||
DEFAULT_GETTEXT_DOMAIN = 'priority'
|
||||
GETTEXT_DOMAIN_MAPPING = {
|
||||
'about': ['about'],
|
||||
'blog': ['blog'],
|
||||
'comparison': ['comparison'],
|
||||
'docs': ['docs'],
|
||||
'get-involved': ['get-involved'],
|
||||
'misc': ['misc'],
|
||||
'research': ['research'],
|
||||
}
|
||||
|
||||
TEMPLATE_DIR = os.path.join(os.path.dirname(__file__), 'pages')
|
||||
STATIC_DIR = os.path.join(os.path.dirname(__file__), 'static')
|
||||
BLOG_DIR = os.path.join(os.path.dirname(__file__), 'blog')
|
||||
@@ -50,7 +61,7 @@ class MyFlask(Flask):
|
||||
|
||||
app = application = MyFlask('i2p2www', template_folder=TEMPLATE_DIR, static_url_path='/_static', static_folder=STATIC_DIR)
|
||||
app.debug = bool(os.environ.get('APP_DEBUG', 'False'))
|
||||
babel = Babel(app)
|
||||
babel = Babel(app, default_domain='priority')
|
||||
cache = Cache(app, config={
|
||||
'CACHE_DEFAULT_TIMEOUT': 600,
|
||||
#'CACHE_TYPE': '', # See http://packages.python.org/Flask-Cache/#configuring-flask-cache
|
||||
@@ -67,7 +78,22 @@ def get_locale():
|
||||
return g.lang
|
||||
# otherwise try to guess the language from the user accept
|
||||
# header the browser transmits. The best match wins.
|
||||
return request.accept_languages.best_match(['en', 'es', 'zh', 'de', 'fr', 'it', 'nl', 'ru', 'sv', 'cs', 'ar'])
|
||||
return request.accept_languages.best_match(SUPPORTED_LANGS)
|
||||
|
||||
@babel.domainselector
|
||||
def get_domains():
|
||||
domains = []
|
||||
frags = request.path.split('/', 2)
|
||||
if len(frags) == 3:
|
||||
path = frags[2]
|
||||
for subpath in GETTEXT_DOMAIN_MAPPING:
|
||||
if path.startswith(subpath):
|
||||
domains.extend(GETTEXT_DOMAIN_MAPPING[subpath])
|
||||
# Always end with the priority domain, as it contains
|
||||
# various template strings and is likely to be the most
|
||||
# up-to-date (in case of any common translation strings).
|
||||
domains.append(DEFAULT_GETTEXT_DOMAIN)
|
||||
return domains
|
||||
|
||||
|
||||
##########################
|
||||
|
@@ -1,7 +0,0 @@
|
||||
[python: **.py]
|
||||
[jinja2: **/pages/**.html]
|
||||
extensions=jinja2.ext.autoescape,jinja2.ext.with_,i2p2www.extensions.HighlightExtension
|
||||
[jinja2: **/pages/global/macros]
|
||||
extensions=jinja2.ext.autoescape,jinja2.ext.with_
|
||||
[jinja2: **/blog/**.rst]
|
||||
extensions=jinja2.ext.autoescape,jinja2.ext.with_
|
Reference in New Issue
Block a user