Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Internationalization: trans with object property
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Ma Ba  
View profile  
 More options Oct 24 2012, 9:16 am
From: Ma Ba <m.bal...@northbit.com>
Date: Wed, 24 Oct 2012 06:16:52 -0700 (PDT)
Local: Wed, Oct 24 2012 9:16 am
Subject: Internationalization: trans with object property

Hi,
I have a question about the internationalization feature ...

I have a country model:

class Country(models.Model):
    nameKey = models.CharField(max_length=50)
    shortNameKey = models.CharField(max_length=30)

The properties 'nameKey' and 'shortNameKey' contain resource keys like
'_country_af' or '_country_af_short'. I need this to show the country names
depending on the current locale.

The problem was/is to add the resource keys to the .po file, so I found a
solution in a forum:
http://stackoverflow.com/questions/7625991/how-to-properly-add-entrie...

For example, I added the following to a model file:

def dummy_for_makemessages():
    #countries
    pgettext('forecast type', '_country_af')
    pgettext('forecast type', '_country_af_short')

Runing makemessages this generates the following entries in the .po file:

msgctxt "forecast type"
msgid "_country_af"
msgstr "Afghanistan"

msgctxt "forecast type"
msgid "_country_af_short"
msgstr "Afghanistan"

For testing purposes I tried to iterate over all countries in my database
in a template and to print out the translated names:

{% for country in countries %}
    {% trans country.nameKey %}
{% endfor %}

Unfortunately, it only prints out the following (the resource keys instead
of the translated names):

_country_af
_country_ai
_country_qa
_country_ke
_country_kg
_country_ki
_country_cc
_country_co
...

I found out that the 'msgctxt' part in the .po file causes the missing
translation. I removed it for testing purposes and this time it worked fine.

So, my question is, how can I translate resource keys that are not defined
in the template itself but in an object property instead? Is there a way to
generate the resource keys without the 'msgctxt' part? I tried NONE or an
empty string but this generates a commented out resource key in the .po
file (please see the link to the other forum above).
Does anybody have an idea how to solve this problem?

Thanks for your help in advance!!


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tom Evans  
View profile  
 More options Oct 25 2012, 7:32 am
From: Tom Evans <tevans...@googlemail.com>
Date: Thu, 25 Oct 2012 12:31:58 +0100
Local: Thurs, Oct 25 2012 7:31 am
Subject: Re: Internationalization: trans with object property

You did compile the po file catalogues to mo files, right? Otherwise,
gettext will simply return the msgid. msgctxt should be irrelevant.

Cheers

Tom


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »