GithubHelp home page GithubHelp logo

transdb's Introduction

OVERVIEW

Django's field that stores labels in more than one language in database.

INSTALLATION

See Installation file in this directory.

USAGE

Create your models:

    from transdb import TransCharField, TransTextField
    [...]

    class MyModel(models.Model):
        [...]
        my_char_field = TransCharField(max_length=32)
        my_text_field = TransTextField()

If you need to use in models in a more advanced way:

    from transdb import TransDbField
    from django.conf import settings
    from django.utils.translation import get_language
    from django.template.defaultfilters import slugify
    [...]

    class MyModel(models.Model):
        [...]
        my_char_field = TransCharField(max_length=32)
        my_text_field = TransTextField()
        slug_field = models.SlugField(editable=False)

        def __unicode__(self):
            return self.my_char_field

        def save(self):
            self.slug_field = slugify(self.my_char_field.get_in_language(settings.LANGUAGE_CODE))
            super(MyModel, self).save()
    [...]

Use as any other field in templates:

    [...]
    <p>{{ object.my_field }}</p>
    [...]

And that's all, enjoy!

MIGRATION

Migration from non-translatable fields (and previous versions of TransDb)

There is a wiki page that covers the migration procedure from non-translatable fields:

    http://code.google.com/p/transdb/wiki/MigrationProcedure

TECHINCAL INFORMATION

Internally data is stored in database as a string in dictionary format, for example:

    u'{u'en': u'This is english', u'ca': u'Això és català'}'

Field uses a subclass of unicode class, adding a raw_data attribute to store the string with all languages, and implementing the get_in_language(language) method to allow access to a diferent language (diferent from the user's current language).

KNOWN ISSUES

See the list in http://code.google.com/p/transdb/issues/list 


transdb's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.