Search code examples
pythonlocalizationgettext

Python multilingual localization


I am working a backend project written in python to provider multilingual strings to my frontend handset. Some how I got some text translation that will change the position. I want to know how to do that?
Example:
Cathy invited Thomas.
translated to
Thomas 被 Cathy 邀請了.


Solution

  • Use dict interpolation instead.

    _('%(inviter)s invited %(invitee)s.') % {'inviter': 'Cathy', 'invitee': 'Thomas'}
                 ↓↓↓↓↓↓↓
     u'%(invitee)s 被 %(inviter)s 邀請了.'