#14974: Contrib application for i18n functions
---------------------------------------------+------------------------------
          Reporter:  marinho                 |         Owner:  nobody
            Status:  new                     |     Milestone:        
         Component:  Internationalization    |       Version:  SVN   
        Resolution:                          |      Keywords:        
             Stage:  Design decision needed  |     Has_patch:  0     
        Needs_docs:  0                       |   Needs_tests:  0     
Needs_better_patch:  0                       |  
---------------------------------------------+------------------------------
Comment (by marinho):

 Replying to [comment:3 jezdez]:

 I didn't revise the text below, please understand I'm doing it as faster
 as I can (today I'm working).

 Ok, I tried to be clear on the mail list, but I'm going to right a fast
 story with more details below:

 You know, most of i18n functions are in:

     1. utils/translation
     2. core/management/commands/compilemessages.py
     3. core/management/commands/makemessages.py
     4. views/i18n.py
     5. conf/locale

 What I'm saying is about to change the points 1, 2, 3 and 4.

 Keep in my the following structure:

     - contrib/i18n
     - contrib/i18n/__init__.py
     - contrib/i18n/models.py                 <--- here we have the model
 classes for DB storage
     - contrib/i18n/views.py                  <--- here we have the current
 "views/i18n.py"
     - contrib/i18n/backends/__init__.py
     - contrib/i18n/backends/base.py          <--- here we have the backend
 base class
     - contrib/i18n/backends/potfiles.py      <--- here we have the backend
 class for gettext (with most of current "utils/translation" code)
     - contrib/i18n/backends/db.py            <--- here we have the backend
 class for database (using the model class for DB storage, etc)
     - contrib/i18n/management/__init__.py
     - contrib/i18n/management/commands/__init__.py
     - contrib/i18n/management/commands/compilemessages.py   <--- we move
 the current to here
     - contrib/i18n/management/commands/makemessages.py      <--- we move
 the current to here

 Now a prototype of "contrib/i18n/models.py":

 {{{
 class MessageString(models.Model):
     class Meta:
         unique_together = (
             ('hash','language'),
         )
     hash = models.CharField()
     language = models.CharField()
     message_id = models.TextField() # if necessary
     message_str = models.TextField()
 }}}

 Now a prototype of "contrib/i18n/backends/base.py":

 {{{
 class BaseBackend(object):
     def gettext(self, msg):
         raise NotImplemented

     def ugettext(self, msg):
         raise NotImplemented

     def gettext_noop(self, msg):
         raise NotImplemented

     def get_language(self):
         return self._language # Of course, different

     def makemessages(self):
         raise NotImplemented

     def compilemessages(self):
         raise NotImplemented

     # etc...
 }}}

 Now a prototype of "contrib/i18n/backends/potfiles.py":

 {{{
 class GettextBackend(BaseBackend):
     potfile = 'django.po' # etc...

     def gettext(self, msg):
         return do_translate(message, 'gettext') # Like it does nowadays

     def ugettext(self, msg):
         return do_translate(message, 'ugettext') # Like it does nowadays

     def gettext_noop(self, msg):
         return message

     def makemessages(self):
         # do the same that makemessages.py actually does

     def compilemessages(self):
         # do the same that compilemessages.py actually does

     # etc...
 }}}

 Now a prototype of "contrib/i18n/backends/db.py":

 {{{
 class DatabaseBackend(BaseBackend):
     def get_hash(self, msg):
         return hashlib.sha1(msg).hexdigest()

     def gettext(self, msg):
         try:
             obj = MessageString.objects.get(
                     language = self.get_language(),
                     hash = self.get_hash(msg),
                     )
             return obj.message_str
         except MessageString.DoesNotExist:
             return msg

     def ugettext(self, msg):
         return do_translate(message, 'ugettext') # Like it does nowadays

     def gettext_noop(self, msg):
         return message

     def makemessages(self):
         # do the same that makemessages.py actually does, but stores using
         # MessageString instead of using the gettext tools

     def compilemessages(self):
         # do nothing, probably

     # etc...
 }}}

 Now the setting to set the current backend (settings.py):

 {{{
 I18N_BACKEND = 'django.contrib.i18n.backends.DatabaseBackend'
 }}}

 So, the template tags and ugettext functions must be changed to use the
 current
 backend instead of just use gettext.

-- 
Ticket URL: <http://code.djangoproject.com/ticket/14974#comment:4>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to