Permalink
Browse files

Added support for unihandecode.js

Added support for unihandecode.js on the add page form in the admin.
This support must be explicitly enabled by the user and the django CMS
will not ship a copy of unihandecode.js.
  • Loading branch information...
1 parent e1bd3ee commit 10d462ac07a445f44d1ca5689b08869fd1da204a @ojii ojii committed Jan 20, 2013
@@ -464,8 +464,14 @@ def get_inline_instances(self, request):
def add_view(self, request, form_url='', extra_context=None):
extra_context = extra_context or {}
language = get_language_from_request(request)
+ if language[:2] in ['ja', 'zh', 'vn', 'kr']:
+ unihandecodelang = language[:2]
+ else:
+ unihandecodelang = 'diacritic'
extra_context.update({
'language': language,
+ 'unihandecode_lang': unihandecodelang,
+ 'unihandecode_url': get_cms_setting('UNIHANDECODE_URL')
})
return super(PageAdmin, self).add_view(request, form_url, extra_context=extra_context)
@@ -14,14 +14,20 @@
<script type="text/javascript" src="{% admin_static_url %}js/urlify.js"></script>
{% if add %}
+{% if unihandecode_url %}
+<script type="text/javascript" src="{{ unihandecode_url }}unihandecode.core.min.js"></script>
+<script type="text/javascript" src="{{ unihandecode_url }}unihandecode.{{ unihandecode_lang }}.min.js"></script>
+{% endif %}
<script type="text/javascript">
//<![CDATA[
jQuery(document).ready(function (){
jQuery("#id_title").keyup(function () {
var e = jQuery("#id_slug")[0];
if(!e._changed) {
- e.value = URLify(this.value, 64);
+ var value = this.value;
+ {% if unihandecode_url %}value = Unihandecoder('{{ unihandecode_lang }}').decode(value);{% endif %}
+ e.value = URLify(value, 64);
}
});
});
View
@@ -49,7 +49,8 @@ def wrapper():
'TITLE_CHARACTER': '+',
'CACHE_PREFIX': 'cms-',
'PLUGIN_PROCESSORS': [],
- 'PLUGIN_CONTEXT_PROCESSORS': []
+ 'PLUGIN_CONTEXT_PROCESSORS': [],
+ 'UNIHANDECODE_URL': None,
}
def get_cache_durations():
@@ -77,3 +77,10 @@ and you are on a page that doesn't yet have an English translation and you view
the German version then the language chooser will redirect to ``/``. The same
goes for urls that are not handled by the cms and display a language chooser.
+*************************************************
+Automated slug generation for non-ASCII languages
+*************************************************
+
+If your site has languages which use non-ASCII character sets, you might want
+to enable :setting:`CMS_UNIHANDECODE_URL` to get automated slugs for those
+languages too.
@@ -333,6 +333,30 @@ Type: Boolean
Default:``True``
+.. setting:: CMS_UNIHANDECODE_URL
+
+CMS_UNIHANDECODE_URL
+====================
+
+default: ``None``
+
+To enable automatic slugs in the page add form in the admin for Japanese,
+Chinese, Korean or Vietnamese, or to improve the existing slug generation
+for other languages that use diacritics, you may set this setting to a URL
+where `unihandecode.js`_ is hosted.
+
+Due to conflicting licenses, unihandecode.js is not included in the django CMS
+and you must optain a copy of it yourself.
+
+If set to ``None``, the default, unihandecode.js is not used.
+
+.. note::
+
+ Unihandecode.js is a rather large library, especially when loading support
+ for Japanese. It is therefore very important that you serve it from a
+ server that supports gzip compression. Further, make sure that those files
+ can be cached by the browser for a very long period.
+
**************
Media Settings
**************
@@ -569,3 +593,6 @@ Example::
Django 1.3 introduced a site-wide cache key prefix. See Django's own docs on
:ref:`cache key prefixing <django:cache_key_prefixing>`
+
+
+.. _unihandecode.js: https://github.com/ojii/unihandecode.js

0 comments on commit 10d462a

Please sign in to comment.