My favorites | Sign in
Project Home Downloads Wiki Issues Source
Project Information
Members
Featured
Downloads
Links

django-flags

The django-flags helps writing internationalized applications based on "verbose" templates:

In this situation, it is more efficient to maintain a set of templates per language than writing one set of templates with many trans tags.

Last languages added: romanian


What django-flags does

django-flags provides:

  • a template tag displaying country flags in a form
  • two template loaders searching (LANGUAGE_CODE)/(template_name)

Here's an example of a flags form:

Test it

download or check it out, then launch the project test with:

  python manage.py testserver

That's all !

A screenshot of test page:


Using django-flags in your django project

settings.py

add the following template loaders first:

TEMPLATE_LOADERS = (
    'yourproject.flags.loaders.filesystem.load_template_source',
    'yourproject.flags.loaders.app_directories.load_template_source',
    ...
)

add the local middleware after the session middleware:

MIDDLEWARE_CLASSES = (
    ...
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.locale.LocaleMiddleware',
    ...
)

add the flags application:

INSTALLED_APPS = (
    ...
    'yourproject.flags',
)

add flags application parameters; you can choose flags icons server:

# see urls.py
FLAGS_I18N_PREFIX = '/lang/i18n/'
# flags served by local server
#FLAGS_URL = MEDIA_URL
# flags served by net server
FLAGS_URL = 'http://djangodev.free.fr/flags/'

# languages
ugettext = lambda s: s
LANGUAGES = (
    ('ar', ugettext('Arabic')),
    ('fr', ugettext('French')),
    ('en', ugettext('English')),
    ('es', ugettext('Spanish')),
    ('de', ugettext('German')),
    ('pl', ugettext('Polish')),
)

urls.py

include flags.urls (the prefix must match settings.FLAGS_I18N_PREFIX):

urlpatterns = patterns('',
    # django-flags for internationalization
    (r'^lang/', include('yourproject.flags.urls')),
    ...
)

templates

Insert the following code to generate the flags form:

{% load flags_lib %}{% flags_form %}
  • copy templates/.html to templates/LANG/.html
  • translate templates/LANG/.html

That's all.


Help needed

You can help me this way:

  • generate a 10x15 flag of your country named flag_CC.jpg
  • translate this template
  • send me these items
Thanks for your participation :-)

Powered by Google Project Hosting