Commit 313b826e authored by Serge S. Koval's avatar Serge S. Koval

Translation fixes.

parent ee46f523
include LICENSE include LICENSE
recursive-include flask_adminex/static * recursive-include flask_adminex/static *
recursive-include flask_adminex/templates * recursive-include flask_adminex/templates *
recursive-include flask_adminex/translations *
- Core - Core
- View Site button? - View Site button?
- Localization - Localization
- Verify that babel string collection works
- Add localized sample
- Model Admin - Model Admin
- Reduce number of parameters passed to list view - Reduce number of parameters passed to list view
- Checkboxes and mass operations - Checkboxes and mass operations
- Filters - Filters
- Custom filters for date fields? - Custom filters for date fields?
- Change boolean filter to True/False instead of Yes/No
- Ability to sort by fields that are not visible? - Ability to sort by fields that are not visible?
- List display callables? - List display callables?
- SQLA Model Admin - SQLA Model Admin
......
# Translations template for Flask-AdminEx.
# Copyright (C) 2012 ORGANIZATION
# This file is distributed under the same license as the Flask-AdminEx
# project.
# FIRST AUTHOR <EMAIL@ADDRESS>, 2012.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: Flask-AdminEx VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2012-04-10 23:45+0300\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 0.9.6\n"
#: ../flask_adminex/form.py:81
msgid "Invalid time format"
msgstr ""
#: ../flask_adminex/ext/fileadmin.py:32
msgid "Invalid directory name"
msgstr ""
#: ../flask_adminex/ext/fileadmin.py:49
msgid "File required."
msgstr ""
#: ../flask_adminex/ext/fileadmin.py:54
msgid "Invalid file type."
msgstr ""
#: ../flask_adminex/ext/fileadmin.py:335
msgid "File uploading is disabled."
msgstr ""
#: ../flask_adminex/ext/fileadmin.py:344
#, python-format
msgid "File \"%(name)s\" already exists."
msgstr ""
#: ../flask_adminex/ext/fileadmin.py:351
#, python-format
msgid "Failed to save file: %(error)s"
msgstr ""
#: ../flask_adminex/ext/fileadmin.py:370
msgid "Directory creation is disabled."
msgstr ""
#: ../flask_adminex/ext/fileadmin.py:380
#, python-format
msgid "Failed to create directory: %(error)s"
msgstr ""
#: ../flask_adminex/ext/fileadmin.py:402
msgid "Deletion is disabled."
msgstr ""
#: ../flask_adminex/ext/fileadmin.py:407
msgid "Directory deletion is disabled."
msgstr ""
#: ../flask_adminex/ext/fileadmin.py:412
#, python-format
msgid "Directory \"%s\" was successfully deleted."
msgstr ""
#: ../flask_adminex/ext/fileadmin.py:414
#, python-format
msgid "Failed to delete directory: %(error)s"
msgstr ""
#: ../flask_adminex/ext/fileadmin.py:418
#, python-format
msgid "File \"%(name)s\" was successfully deleted."
msgstr ""
#: ../flask_adminex/ext/fileadmin.py:420
#, python-format
msgid "Failed to delete file: %(name)s"
msgstr ""
#: ../flask_adminex/ext/fileadmin.py:439
msgid "Renaming is disabled."
msgstr ""
#: ../flask_adminex/ext/fileadmin.py:443
msgid "Path does not exist."
msgstr ""
#: ../flask_adminex/ext/fileadmin.py:454
#, python-format
msgid "Successfully renamed \"%(src)s\" to \"%(dst)s\""
msgstr ""
#: ../flask_adminex/ext/fileadmin.py:457
#, python-format
msgid "Failed to rename: %(error)s"
msgstr ""
#: ../flask_adminex/ext/sqlamodel/filters.py:35
msgid "equals"
msgstr ""
#: ../flask_adminex/ext/sqlamodel/filters.py:43
msgid "not equal"
msgstr ""
#: ../flask_adminex/ext/sqlamodel/filters.py:52
msgid "contains"
msgstr ""
#: ../flask_adminex/ext/sqlamodel/filters.py:61
msgid "not contains"
msgstr ""
#: ../flask_adminex/ext/sqlamodel/filters.py:69
msgid "greater than"
msgstr ""
#: ../flask_adminex/ext/sqlamodel/filters.py:77
msgid "smaller than"
msgstr ""
#: ../flask_adminex/ext/sqlamodel/form.py:37
msgid "Already exists."
msgstr ""
#: ../flask_adminex/ext/sqlamodel/view.py:504
#, python-format
msgid "Failed to create model. %(error)s"
msgstr ""
#: ../flask_adminex/ext/sqlamodel/view.py:519
#, python-format
msgid "Failed to update model. %(error)s"
msgstr ""
#: ../flask_adminex/ext/sqlamodel/view.py:534
#, python-format
msgid "Failed to delete model. %(error)s"
msgstr ""
#: ../flask_adminex/model/base.py:742
msgid "Model was successfully created."
msgstr ""
#: ../flask_adminex/templates/admin/lib.html:105
msgid "Submit"
msgstr ""
#: ../flask_adminex/templates/admin/lib.html:110
msgid "Cancel"
msgstr ""
#: ../flask_adminex/templates/admin/file/list.html:7
msgid "Root"
msgstr ""
#: ../flask_adminex/templates/admin/file/list.html:42
#, python-format
msgid "Are you sure you want to delete \\'%(name)s\\' recursively?"
msgstr ""
#: ../flask_adminex/templates/admin/file/list.html:50
#, python-format
msgid "Are you sure you want to delete \\'%(name)s\\'?"
msgstr ""
#: ../flask_adminex/templates/admin/file/list.html:75
msgid "Upload File"
msgstr ""
#: ../flask_adminex/templates/admin/file/list.html:78
msgid "Create Directory"
msgstr ""
#: ../flask_adminex/templates/admin/file/rename.html:5
#, python-format
msgid "Please provide new name for %(name)s"
msgstr ""
#: ../flask_adminex/templates/admin/model/create.html:11
msgid "Save and Add"
msgstr ""
#: ../flask_adminex/templates/admin/model/create.html:16
#: ../flask_adminex/templates/admin/model/list.html:12
msgid "List"
msgstr ""
#: ../flask_adminex/templates/admin/model/create.html:19
#: ../flask_adminex/templates/admin/model/list.html:16
msgid "Create"
msgstr ""
#: ../flask_adminex/templates/admin/model/list.html:23
msgid "Add Filter"
msgstr ""
#: ../flask_adminex/templates/admin/model/list.html:44
msgid "Search"
msgstr ""
#: ../flask_adminex/templates/admin/model/list.html:57
msgid "Apply"
msgstr ""
#: ../flask_adminex/templates/admin/model/list.html:59
msgid "Reset Filters"
msgstr ""
#: ../flask_adminex/templates/admin/model/list.html:67
msgid "Remove Filter"
msgstr ""
#: ../flask_adminex/templates/admin/model/list.html:128
msgid "You sure you want to delete this item?"
msgstr ""
pybabel extract -F babel.ini -k _gettext -k _ngettext -o admin.pot --project Flask-AdminEx ..\flask_adminex
# Python
[python: **.py]
# Jinja2
[jinja2: **/templates/**.html]
encoding = utf-8
#!/bin/sh
pybabel extract -F babel.ini -k _gettext -k _ngettext -o admin.pot --project Flask-AdminEx ../flask_adminex
from __future__ import absolute_import
import os.path as op
from flask import _request_ctx_stack from flask import _request_ctx_stack
def _gettext(string, **variables): try:
return string % variables from babel import support, Locale
from speaklater import make_lazy_string
class Namespace(object):
def __init__(self, dirname=None, namespace='', default_locale='en'):
self.dirname = dirname
self.namespace = namespace
self.default_locale = Locale.parse(default_locale)
def _ngettext(singular, plural, num, **variables): def _get_locale(self):
return (singular if num == 1 else plural) % variables ctx = _request_ctx_stack.top
if ctx is None:
return None
locale = getattr(ctx, 'admin_locale', None)
if locale is None:
admin = ctx.app.extensions['admin']
def _lazy_gettext(string, **variables): if admin.locale_selector_func:
return string % variables locale_name = admin.locale_selector_func()
# Wrap flask-babel API if locale_name:
try: locale = Locale.parse(locale_name)
from flask.ext import babel else:
locale = self.default_locale
else:
locale = self.default_locale
ctx.admin_locale = locale
return locale
def _get_translations(self):
ctx = _request_ctx_stack.top
if ctx is None:
return None
attr = 'admin_trans_' + self.namespace
translations = getattr(ctx, attr, None)
if translations is None:
dirname = self.dirname or op.join(ctx.app.root_path, 'translations')
translations = support.Translations.load(dirname,
[self._get_locale()],
domain=self.namespace)
setattr(ctx, attr, translations)
return translations
def gettext(self, string, **variables):
translations = self._get_translations()
return translations.ugettext(string, **variables)
def ngettext(self, singular, plural, num, **variables):
translations = self._get_translations()
return translations.ungettext(singular, plural, num, **variables)
def _is_babel_on(): def lazy_gettext(self, string, **variables):
ctx = _request_ctx_stack.top return make_lazy_string(self.gettext, string, **variables)
if ctx is None:
return False
return hasattr(ctx, 'babel_locale') except ImportError, ex:
class DummyNamespace(object):
def __init__(self, dirname=None, namespace='admin'):
self.dirname = dirname
self.namespace = namespace
def gettext(string, **variables): def gettext(self, string, **variables):
if not _is_babel_on(): return string % variables
return _gettext(string, **variables)
return babel.gettext(string, **variables) def ngettext(self, singular, plural, num, **variables):
return (singular if num == 1 else plural) % variables
def ngettext(singular, plural, num, **variables): def lazy_gettext(self, string, **variables):
if not _is_babel_on(): return string % variables
return _ngettext(singular, plural, num, **variables)
return babel.ngettext(singular, plural, num, **variables) Namespace = DummyNamespace
def lazy_gettext(string, **variables): # Create default namespace pointing to the flask-adminex localization directory
from speaklater import make_lazy_string ns = Namespace(namespace='admin')
return make_lazy_string(gettext, string, **variables)
except ImportError: # Create shortcuts for default namespace
gettext = _gettext gettext = ns.gettext
ngettext = _ngettext ngettext = ns.ngettext
lazy_gettext = _lazy_gettext lazy_gettext = ns.lazy_gettext
...@@ -283,6 +283,8 @@ class Admin(object): ...@@ -283,6 +283,8 @@ class Admin(object):
`index_view` `index_view`
Home page view to use. If not provided, will use `AdminIndexView`. Home page view to use. If not provided, will use `AdminIndexView`.
""" """
self.app = app
self._views = [] self._views = []
self._menu = [] self._menu = []
self._menu_categories = dict() self._menu_categories = dict()
...@@ -295,15 +297,21 @@ class Admin(object): ...@@ -295,15 +297,21 @@ class Admin(object):
url = '/admin' url = '/admin'
self.url = url self.url = url
# Localizations
self.locale_selector_func = None
# Index view
if index_view is None: if index_view is None:
index_view = AdminIndexView(url=self.url) index_view = AdminIndexView(url=self.url)
self.app = app
self.index_view = index_view self.index_view = index_view
# Add predefined index view # Add predefined index view
self.add_view(index_view) self.add_view(index_view)
if app:
self._init_extension()
def add_view(self, view): def add_view(self, view):
""" """
Add view to the collection. Add view to the collection.
...@@ -319,6 +327,37 @@ class Admin(object): ...@@ -319,6 +327,37 @@ class Admin(object):
self.app.register_blueprint(view.create_blueprint(self)) self.app.register_blueprint(view.create_blueprint(self))
self._add_view_to_menu(view) self._add_view_to_menu(view)
def locale_selector(self, f):
"""
Install locale selector for current admin instance.
Example::
admin = Admin(app)
@admin.locale_selector
def admin_locale_selector():
return request.args.get('lang', 'en')
Another example:
def admin_locale_selector():
return request.args.get('lang', 'en')
admin = Admin(app)
admin.locale_selector(admin_locale_selector)
And if you want to subclass ``Admin``, you can do something like:
class MyAdmin(Admin):
def locale_selector(self):
return request.args.get('lang', 'en')
"""
if self.locale_selector_func is not None:
raise Exception('Can not add locale_selector second time.')
self.locale_selector_func = f
def _add_view_to_menu(self, view): def _add_view_to_menu(self, view):
""" """
Add view to the menu tree Add view to the menu tree
...@@ -354,6 +393,17 @@ class Admin(object): ...@@ -354,6 +393,17 @@ class Admin(object):
app.register_blueprint(view.create_blueprint(self)) app.register_blueprint(view.create_blueprint(self))
self._add_view_to_menu(view) self._add_view_to_menu(view)
self._init_extension()
def _init_extension(self):
if not hasattr(self.app, 'extensions'):
self.app.extensions = dict()
if 'admin' in self.app.extensions:
raise Exception('Can not have more than one instance of the Admin class associated with Flask application')
self.app.extensions['admin'] = self
def menu(self): def menu(self):
""" """
Return menu hierarchy. Return menu hierarchy.
......
from flask.ext.babel import lazy_gettext from flask.ext.adminex.babel import lazy_gettext
class BaseFilter(object): class BaseFilter(object):
......
...@@ -102,7 +102,7 @@ ...@@ -102,7 +102,7 @@
{% endfor %} {% endfor %}
<div class="control-group"> <div class="control-group">
<div class="controls"> <div class="controls">
<input type="submit" class="btn btn-primary btn-large" /> <input type="submit" class="btn btn-primary btn-large" value="{{ _gettext('Submit') }}" />
{% if extra %} {% if extra %}
{{ extra }} {{ extra }}
{% endif %} {% endif %}
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
<ul class="nav nav-tabs"> <ul class="nav nav-tabs">
<li> <li>
<a href="{{ return_url }}">List</a> <a href="{{ return_url }}">{{ _gettext('List') }}</a>
</li> </li>
<li class="active"> <li class="active">
<a href="#">{{ _gettext('Create') }}</a> <a href="#">{{ _gettext('Create') }}</a>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment