### apps_verbose/templatetags/verbose_tags.py ###
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
from django import template
from django.template.defaultfilters import *
from my_project.apps_verbose.models import * ### define import for your project (my_project) ###
register = template.Library()
@register.simple_tag
def verbose_name(app_name, language_code):
try:
app = Verbose_Name.objects.get(app = app_name.lower())
app_name_translated = app.verbose_name_tranlations_set.get(language = language_code)
return app_name_translated.name
except:
return app_name
@register.simple_tag
def verbose_name_title(title, language_code):
title = title.split(' ')
title_translated = []
for word in title:
title_translated.append(verbose_name(word, language_code))
return ' '.join(title_translated)
### apps_verbose/models.py ###
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
from django.db import models
from django.conf import settings
from django.db.models import get_app, get_apps
def get_app_name (path):
path = path.split('.')
i=len(path)-1
return path[i]
app_list = ((get_app_name(app),get_app_name(app))for app in settings.INSTALLED_APPS if get_app_name(app))
class Verbose_Name(models.Model):
"""
Apps
"""
class Meta:
verbose_name = u'Verbose_Name'
verbose_name_plural = u'Verbose_Name'
app = models.CharField(max_length=200,unique=False,choices=app_list)
def __unicode__(self):
return u'%s' % (self.app)
class Verbose_Name_Tranlations(models.Model):
"""
Translations
"""
class Meta:
verbose_name = u'Verbose_Name Tranlations'
verbose_name_plural = u'Verbose_Name Tranlations'
unique_together = ('name','language')
verbose_name = models.ForeignKey(Verbose_Name)
language = models.CharField(max_length=20,unique=True,choices = settings.LANGUAGES)
name = models.CharField(verbose_name = u'Name', max_length = 200, null = False, blank = False,)
### apps_verbose/admin.py ###
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
from django.contrib import admin
from django.contrib.admin.options import ModelAdmin
from my_project.apps_verbose.models import * ### define import for your project (my_project) ###
class Child_Verbose_Name_Tranlations(admin.TabularInline):
model = Verbose_Name_Tranlations
extra = 3
class Admin_Verbose_Name(ModelAdmin):
fieldsets = (
(u'Verbose Name',
{'fields':('app',)}),
)
inlines = [Child_Verbose_Name_Tranlations,]
list_display = ('__unicode__',)
list_display_links = ('__unicode__',)
admin.site.register(Verbose_Name,Admin_Verbose_Name)
{% extends "admin/base_site.html" %}
{% load i18n %}
{% load verbose_tags %}
{% block breadcrumbs %}
{% endblock %}
{% extends "admin/base_site.html" %}
{% load i18n %}
{% load verbose_tags %}
{% block breadcrumbs %}
{% endblock %}
{% extends "admin/base_site.html" %}
{% load i18n %}
{% load verbose_tags %}
{% block breadcrumbs %}
{% endblock %}
{% extends "admin/index.html" %}
{% load i18n %}
{% load verbose_tags %}
{% if not is_popup %}
{% block breadcrumbs %}
{% trans "Home" %} ›
{% for app in app_list %}
{% get_current_language as LANGUAGE_CODE %}{% verbose_name app.name LANGUAGE_CODE %}
{% endfor %}
{% endblock %}
{% endif %}
{% block sidebar %}{% endblock %}
{% extends "admin/base_site.html" %}
{% load i18n admin_modify adminmedia %}
{% load verbose_tags %}
{% block extrahead %}{{ block.super }}
{{ media }}
{% endblock %}
{% block extrastyle %}{{ block.super }}{% endblock %}
{% block coltype %}{% if ordered_objects %}colMS{% else %}colM{% endif %}{% endblock %}
{% block bodyclass %}{{ opts.app_label }}-{{ opts.object_name.lower }} change-form{% endblock %}
{% block breadcrumbs %}{% if not is_popup %}
{% endif %}{% endblock %}
{% extends "admin/base_site.html" %}
{% load i18n %}
{% load verbose_tags %}
{% block extrastyle %}{{ block.super }}{% endblock %}
{% block coltype %}colMS{% endblock %}
{% block bodyclass %}dashboard{% endblock %}
{% block breadcrumbs %}{% endblock %}
{% block content %}
{% if app_list %}
{% for app in app_list %}
{% get_current_language as LANGUAGE_CODE %}{% verbose_name app.name LANGUAGE_CODE %}
{% for model in app.models %}
{% if model.perms.change %}
{{ model.name }} |
{% else %}
{{ model.name }} |
{% endif %}
{% if model.perms.add %}
{% trans 'Add' %} |
{% else %}
|
{% endif %}
(...)
{% extends "admin/base_site.html" %}
{% load adminmedia admin_list i18n %}
{% load verbose_tags %}
{% block extrastyle %}
{{ block.super }}
{% if cl.formset %}
{% endif %}
{{ media }}
{% if not actions_on_top and not actions_on_bottom %}
{% endif %}
{% endblock %}
{% block bodyclass %}change-list{% endblock %}
{% if not is_popup %}
{% block breadcrumbs %}
{% endblock %}
{% endif %}
(...)
{% block title %}{% endblock %}
{% block extrastyle %}{% endblock %}
{% if LANGUAGE_BIDI %}{% endif %}
{% block extrahead %}{% endblock %}
{% block blockbots %}{% endblock %}
{% load i18n %}
{% load verbose_tags %}
(...)
{% block pretitle %}{% endblock %}
{% block content_title %}{% if title %}
{% get_current_language as LANGUAGE_CODE %}{% verbose_name_title title LANGUAGE_CODE %}
{% endif %}{% endblock %}
{% block content %}
{% block object-tools %}{% endblock %}
{{ content }}
{% endblock %}
{% block sidebar %}{% endblock %}
(...)