Source

django-dbgettext / docs / registration.rst

Full commit

Registering Models

Models can be registered for django-dbgettext in a similar fashion to registering ModelAdmin classes for django.contrib.admin

Simply create a gettext.py file within your application root directory, import the dbgettext registry object, and register your Models together with their customised dbgettext.models.Options. For example:

from dbgettext.registry import registry, Options
from dbgettext.lexicons import html
from myapp.models import MyModel

class MyModelOptions(Options):
    attributes = ('title',)
    parsed_attributes = {'body': html.lexicon}

registry.register(MyModel, MyModelOptions)

That's it. Your gettext.py files will be automatically imported by django-dbgettext, and registered models will be included when running :doc:`dbgettext_export <dbgettext_export>`.

Options

  • attributes:

    tuple of names of fields/callables to be translated

  • parsed_attributes:

    dictionary of names of fields/callables with HTML content which should have translatable content extracted (should not be listed in attributes). Values are callables which take an Options argument and return a lexicon suitable for re.Scanner -- see dbgettext.lexicons.html for an example.

  • translate_if:

    dictionary used to filter() queryset

  • get_path_identifier:

    function returning string used to identify object in path to exported content (given an object)

  • parent:
    name of foreign key to parent model, if registered. Affects:
    • path (path_identifier appended onto parent path)
    • queryset (object only translated if parent is)
  • custom_lexicon_rules

    list of extra custom rules ((regexp, function) tuples) to be applied when parsing