Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…ltranslation

# By Rui Manuel da Silva Martins (27) and others
# Via Rui Martins (4) and Rui Manuel da Silva Martins (3)
* 'master' of https://github.com/infoportugal/wagtail-modeltranslation: (34 commits)
  new release: v0.1.5
  fixed bug of required fields
  no message
  integration of wagtailsearch
  added compatibility with wagtailsnipepts
  Support for translated inline panels #8: #8
  v0.1.2
  Prevent raising error in case of parent page url_path does not exists
  Prevent raising error in case of parent page url_path does not exists
  Add a .gitignore file
  v0.1.1
  no message
  v0.1 Minor release
  Update README.md
  Update README.md
  v0.0.9 - final fix
  Fixed dist version
  v0.0.9
  v0.0.8
  Update README.md
  ...

Conflicts:
	.gitignore
	MANIFEST.in
	setup.py
	wagtail_modeltranslation/management/__init__.py
	wagtail_modeltranslation/management/commands/__init__.py
	wagtail_modeltranslation/models.py
	wagtail_modeltranslation/translation.py
	wagtail_modeltranslation/wagtail_hooks.py
  • Loading branch information
Rui Manuel da Silva Martins committed Aug 4, 2015
2 parents 383348e + c1ca0fc commit 17c640c
Show file tree
Hide file tree
Showing 6 changed files with 170 additions and 0 deletions.
113 changes: 113 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# Wagtail modeltranslation
(based on https://github.com/deschler/django-modeltranslation)

Simple app containing a mixin model that integrates modeltranslation
(https://github.com/deschler/django-modeltranslation) into wagtail panels system.

![alt tag](https://github.com/infoportugal/wagtail-modeltranslation/blob/master/screenshot.png?raw=true)

## Quick start

1. Make sure you have django-modeltranslation installed:

pip install django-modeltranslation

2. Add "wagtail_modeltranslation" to your INSTALLED_APPS setting like this:

INSTALLED_APPS = (
...
'wagtail_modeltranslation',
'modeltranslation',
...
)

3. Use TranslationMixin in order to integrate django-modeltranslation with Wagtail admin. ** IMPORTANT: ** make sure that TranslationMixin is declared before Page class on model inheritance. Like following:

from wagtail_modeltranslation.models import TranslationMixin
class FooModel(TranslationMixin, Page):
foo = models.CharField()
FooModel.panels = [...]

4. Visit django-modeltranslation for documentation on how to implement translation fields: http://django-modeltranslation.readthedocs.org/en/latest/

5. In order to update pages url_path field use **"set\_translation\_url\_paths"** instead of original "set\_url\_paths"

6. Use **"change_lang"** template tag to fetch translated urls based on translated slugs:

{% load modeltranslation %}
<li class="dropdown">
<a data-toggle="dropdown" class="dropdown-toggle" data-hover="dropdown" href="#">{{ LANGUAGE_CODE }}<i class="fa fa-angle-down ml5"></i></a>
<ul class="dropdown-menu" id="language-dropdown">
{% for lang in languages %}
{% if lang.0 != LANGUAGE_CODE %}
<li tabindex="-1"><a href="{% change_lang lang.0 %}">{{ lang.1 }}</a></li>
{% endif %}
{% endfor %}
</ul>
</li>

## Release Notes

## v0.1.5

- Fixed required fields related bug

## v0.1.4

- Support for wagtailsearch and wagtailsnippets

## v0.1.3

- Support for translated inline panels #8: https://github.com/infoportugal/wagtail-modeltranslation/issues/8

## v0.1.2

- Fixed Problem updating field with null value #6: https://github.com/infoportugal/wagtail-modeltranslation/issues/6

## v0.1.1

- Fixed url_path issue caused by a browser with language different from settings.LANGUAGE_CODE

## v0.1

- Minor release working but lacks full test coverage.
- Last version had required fields validation problems, now fixed.

## v0.0.9

- Fixed issue that causes duplicated translation fields, preventing auto-slug from working properly.

## v0.0.8

- Fixed issue related to deleting a non existing key on PAGE_EDIT_HANDLER dict

## v0.0.7

- Fixed set_url_path() translatable model method

### v0.0.6

- Fixed js issue related to auto-generating slugs

### v0.0.5

- Now using django-modeltranslation 0.9.1;
- Fixed problem related to slug field fallbacks;

### v0.0.4

** IMPORTANT: ** make sure that TranslationMixin comes before Page class on model inheritance

- Fix enhancement #1: url_path translation field
- Now includes a template tag that returns current page url to corresponding translated url
- New management command to update url_path translation fields - **set\_translation\_url\_paths**

### v0.0.3

- New methods;
- Now supports required fields;
- Fixed issue related to browser locale;

### v0.0.2

- Prepopulated fields now works for translated fields (title and slug)
Binary file added screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added wagtail_modeltranslation/models.pyc
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
$(document).ready(function() {
$.each(langs, function(idx, lang_code){
$('#id_title_'+lang_code).on('focus', function() {
$('#id_slug_'+lang_code).data('previous-val', $('#id_slug_'+lang_code).val());
$(this).data('previous-val', $(this).val());
});

$('#id_title_'+lang_code).on('keyup keydown keypress blur', function() {
if ($('body').hasClass('create') || (!$('#id_slug_'+lang_code).data('previous-val').length || cleanForSlug($('#id_title_'+lang_code).data('previous-val')) === $('#id_slug_'+lang_code).data('previous-val'))) {
// only update slug if the page is being created from scratch, if slug is completely blank, or if title and slug prior to typing were identical
$('#id_slug_'+lang_code).val(cleanForSlug($('#id_title_'+lang_code).val()));
}
});
});
});
41 changes: 41 additions & 0 deletions wagtail_modeltranslation/templatetags/modeltranslation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# coding: utf-8

import re

from django import template
from django.core.urlresolvers import resolve
from django.utils.translation import activate, get_language
register = template.Library()


# CHANGE LANGUAGE
@register.simple_tag(takes_context=True)
def change_lang(context, lang=None, *args, **kwargs):
current_language = get_language()

if 'request' in context and lang and current_language:
request = context['request']
match = resolve(request.path)
non_prefixed_path = re.sub(current_language+'/', '', request.path)

# means that is an wagtail page object
if match.url_name == 'wagtail_serve':
path_components = [component for component in non_prefixed_path.split('/') if component]
page, args, kwargs = request.site.root_page.specific.route(request, path_components)

activate(lang)
translated_url = page.url
activate(current_language)

return translated_url
elif match.url_name == 'wagtailsearch_search':
path_components = [component for component in non_prefixed_path.split('/') if component]

translated_url = '/' + lang + '/' + path_components[0] + '/'
if request.GET:
translated_url += '?'
for key, value in request.GET.iteritems():
translated_url += key + '=' + value
return translated_url

return ''
1 change: 1 addition & 0 deletions wagtail_modeltranslation/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# coding: utf-8

0 comments on commit 17c640c

Please sign in to comment.