Added rtl language support
RTL languages like Arabic, Hebrew etc were displayed from left to right. I fixed this by adding a function to check whether the language of the locale is rtl and change the direction of the html in "base.html" accordingly. [Fixes #220]
This commit is contained in:
parent
8f88b1f6dc
commit
4a4e4e4ae8
@ -16,11 +16,12 @@
|
|||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
-#}
|
-#}
|
||||||
<!doctype html>
|
<!doctype html>
|
||||||
|
|
||||||
<html
|
<html
|
||||||
{% block mediagoblin_html_tag %}
|
{% block mediagoblin_html_tag %}
|
||||||
{% endblock mediagoblin_html_tag %}
|
{% endblock mediagoblin_html_tag %}
|
||||||
>
|
>
|
||||||
<head>
|
<head {% if is_rtl %} dir="rtl" {% endif %}>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>{% block title %}{{ app_config['html_title'] }}{% endblock %}</title>
|
<title>{% block title %}{{ app_config['html_title'] }}{% endblock %}</title>
|
||||||
@ -48,6 +49,7 @@
|
|||||||
{% endblock mediagoblin_head %}
|
{% endblock mediagoblin_head %}
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
<div {% if is_rtl %} dir="rtl" {% endif %}>
|
||||||
{% include 'mediagoblin/bits/body-start.html' %}
|
{% include 'mediagoblin/bits/body-start.html' %}
|
||||||
{% block mediagoblin_body %}
|
{% block mediagoblin_body %}
|
||||||
{% block mediagoblin_header %}
|
{% block mediagoblin_header %}
|
||||||
@ -133,5 +135,6 @@
|
|||||||
</div>
|
</div>
|
||||||
{%- endblock mediagoblin_body %}
|
{%- endblock mediagoblin_body %}
|
||||||
{% include 'mediagoblin/bits/body-end.html' %}
|
{% include 'mediagoblin/bits/body-end.html' %}
|
||||||
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -26,7 +26,9 @@ from mediagoblin import mg_globals
|
|||||||
from mediagoblin import messages
|
from mediagoblin import messages
|
||||||
from mediagoblin import _version
|
from mediagoblin import _version
|
||||||
from mediagoblin.tools import common
|
from mediagoblin.tools import common
|
||||||
|
from mediagoblin.tools.translate import is_rtl
|
||||||
from mediagoblin.tools.translate import set_thread_locale
|
from mediagoblin.tools.translate import set_thread_locale
|
||||||
|
from mediagoblin.tools.translate import get_locale_from_request
|
||||||
from mediagoblin.tools.pluginapi import get_hook_templates
|
from mediagoblin.tools.pluginapi import get_hook_templates
|
||||||
from mediagoblin.tools.timesince import timesince
|
from mediagoblin.tools.timesince import timesince
|
||||||
from mediagoblin.meddleware.csrf import render_csrf_form_token
|
from mediagoblin.meddleware.csrf import render_csrf_form_token
|
||||||
@ -67,11 +69,12 @@ def get_jinja_env(template_loader, locale):
|
|||||||
# ... fetch all waiting messages and remove them from the queue
|
# ... fetch all waiting messages and remove them from the queue
|
||||||
# ... construct a grid of thumbnails or other media
|
# ... construct a grid of thumbnails or other media
|
||||||
# ... have access to the global and app config
|
# ... have access to the global and app config
|
||||||
|
# ... determine if the language is rtl or ltr
|
||||||
template_env.globals['fetch_messages'] = messages.fetch_messages
|
template_env.globals['fetch_messages'] = messages.fetch_messages
|
||||||
template_env.globals['app_config'] = mg_globals.app_config
|
template_env.globals['app_config'] = mg_globals.app_config
|
||||||
template_env.globals['global_config'] = mg_globals.global_config
|
template_env.globals['global_config'] = mg_globals.global_config
|
||||||
template_env.globals['version'] = _version.__version__
|
template_env.globals['version'] = _version.__version__
|
||||||
|
template_env.globals['is_rtl'] = is_rtl(locale)
|
||||||
template_env.filters['urlencode'] = url_quote_plus
|
template_env.filters['urlencode'] = url_quote_plus
|
||||||
|
|
||||||
# add human readable fuzzy date time
|
# add human readable fuzzy date time
|
||||||
|
@ -31,6 +31,12 @@ AVAILABLE_LOCALES = None
|
|||||||
TRANSLATIONS_PATH = pkg_resources.resource_filename(
|
TRANSLATIONS_PATH = pkg_resources.resource_filename(
|
||||||
'mediagoblin', 'i18n')
|
'mediagoblin', 'i18n')
|
||||||
|
|
||||||
|
# Known RTL languages
|
||||||
|
KNOWN_RTL = set(["ar", "fa", "zh","he","iw","ja","ur","yi","ji"])
|
||||||
|
|
||||||
|
def is_rtl(lang):
|
||||||
|
"""Returns true when the local language is right to left"""
|
||||||
|
return lang in KNOWN_RTL
|
||||||
|
|
||||||
def set_available_locales():
|
def set_available_locales():
|
||||||
"""Set available locales for which we have translations"""
|
"""Set available locales for which we have translations"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user