title: Django Translation - Translate dynamic strings
body: <p>We are using <code>Django</code> as our backend <code>REST API</code> server. I am looking to translate text being sent as push notifications to our app. I am new to translations. </p>
  
  <p>The text resides in a config file and varies for each user. </p>
  
  <pre><code>NOTIFICATION_TEXT = {
    'access_request': '%(user_name)s has requested to access your document %(story_name)s, please review '}
  </code></pre>
  
  <p>I saw the google translate feature and it perfectly translates if given the final sentence understanding the user_name and story_name are constant. 
  I was looking for a similar magic band functionality in Django where I can just wrap final message before sending to the user in the locale received in the <code>Accept-language</code> header of the <code>REST</code> call. But this doesn't seem possible. </p>
  
  <p>As I understand I would need to pre-mark the text which needs to be translated with <code>ugettext</code> and define language and middleware settings. Then generate <code>locale</code> specific files using</p>
  
  <p><code>django-admin makemessages -l de</code></p>
  
  <p>and then in the generated <code>django.po</code> file for that specific locale gives the translated text manually for Django to refer. </p>
  
  <p>But I am stuck how to mark given my message is dynamic, inside a dic. Or is there another way around? </p>
  
  <p>Edit:</p>
  
  <p>The data is accessed as below</p>
  
  <pre><code>data['msg'] = settings.NOTIFICATION_TEXT['access_request'] % \
                dict(
                  user_name=get_user_name(sender),
                  story_name=story.story_name
                )
  </code></pre>