Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Django's field that stores labels in more than one language in database.
Just working on newforms-admin branch.
Installation Download, unpack and copy files to ${PYTHON_PATH}/site-packages/transdb (or anywhere else if you know what you're doing)
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:
[...]
{{ object.my_field }}
[...] And that's all, enjoy!Due to technical reasons, serialization on models with TransDb fields has some specific restrictions.
Django comes with two serialization formats, xml and json.
TransDb requires two diferent methods when serializing, one that serializes information for all languages (for example for saving data as fixture). Other method should just return the current language (serialization for ajax processing).
Probably will change in the future, but now TransDb applies a method depending on the format, so
Use xml format for including all languages in serialization objects (and use TransDb serializer, see below). User json format for returning just the current language in serialization objects. For using TransDb serializer add next lines to your settings.py file:
SERIALIZATION_MODULES = { 'xml': 'transdb.xml_serializer', }
There is a wiki page MigrationProcedure http://code.google.com/p/transdb/wiki/MigrationProcedure that covers this subject.
Internally data is stored in database as a string in dictionary format, for example:
u'{u'en': u'This is english', u'ca': u'Other lang .. '}' 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).
See the list in http://code.google.com/p/transdb/issues/list
FAQs
I18n django reusable app
We found that transdb demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.