How to view your translated site?

25 views
Skip to first unread message

Cody Scott

unread,
Apr 18, 2013, 11:42:37 AM4/18/13
to django...@googlegroups.com
I am trying to view my site in japanese. I have create the translations and compiled them with compilemessages.

In my urls.py I have 

urlpatterns = i18n_patterns('',
    #...
)

Settings.py

LANGUAGE_CODE = 'en-us'

#Used for translations
gettext = lambda s: s
LANGUAGES = (
    ('en', gettext('English')),
    ('jp', gettext('Japanese')),    
)

But when I try to access a url with /jp/ at the start I get that there is only /en/

Using the URLconf defined in PLP.urls, Django tried these URL patterns, in this order:
^en/
The current URL, jp/accounts/login, didn't match any of these.
 
I am using dbgettext so I also have my database content translated in my messages.

But how can I display it

        {% trans "Question:" %}{% trans {{question.question}} %}<br>

Could not parse the remainder: '{{question.question}}' from '{{question.question}}'

Tom Evans

unread,
Apr 18, 2013, 12:02:53 PM4/18/13
to django...@googlegroups.com
On Thu, Apr 18, 2013 at 4:42 PM, Cody Scott <cody.j....@gmail.com> wrote:
> I am trying to view my site in japanese. I have create the translations and
> compiled them with compilemessages.
>
> In my urls.py I have
>
> urlpatterns = i18n_patterns('',
> #...
> )
>
>
> Settings.py
>
>
> LANGUAGE_CODE = 'en-us'
>
> #Used for translations
> gettext = lambda s: s
> LANGUAGES = (
> ('en', gettext('English')),
> ('jp', gettext('Japanese')),
> )

Django only supports translations that Django itself has a base
translation for. Django has a Japanese translation, but it uses the
correct ISO-639-1 language name for it, 'ja'. Since you have 'jp',
this doesn't correspond to a language that django has a base
translation for, and so it is ignored.

>
>
> But when I try to access a url with /jp/ at the start I get that there is
> only /en/
>
>
> Using the URLconf defined in PLP.urls, Django tried these URL patterns, in
> this order:
> ^en/
> The current URL, jp/accounts/login, didn't match any of these.
>
>
>
> I am using dbgettext so I also have my database content translated in my
> messages.
>
> But how can I display it
>
> {% trans "Question:" %}{% trans {{question.question}} %}<br>
>
> Could not parse the remainder: '{{question.question}}' from
> '{{question.question}}'
>

You can't use {{ }} inside a template tag, but you don't need to. {%
trans %} is expecting either a string literal or a variable, so give
it the variable - {% trans question.question %}.

Cheers

Tom

Cody Scott

unread,
Apr 18, 2013, 12:23:51 PM4/18/13
to django...@googlegroups.com
Thanks, I went here http://www.i18nguy.com/unicode/language-identifiers.html ctrl+ f "japanese" saw jp on the left hand side. I thought ja was a localization of jp so it would be jp-ja.

Tom Evans

unread,
Apr 18, 2013, 12:41:37 PM4/18/13
to django...@googlegroups.com
On Thu, Apr 18, 2013 at 5:23 PM, Cody Scott <cody.j....@gmail.com> wrote:
> Thanks, I went here http://www.i18nguy.com/unicode/language-identifiers.html
> ctrl+ f "japanese" saw jp on the left hand side. I thought ja was a
> localization of jp so it would be jp-ja.
>

The columns listed on that page are "region code", "region name",
"language". You can't use region code for language, eg the region code
'ca' represents 'Canada', but the language code 'ca' represents
Catalan. It's important to use the right one.

If you're looking for the right ISO-639-1 language code to use, the
best reference is a list of ISO-639-1 codes:

http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes

Cheers

Tom

Cody Scott

unread,
Apr 18, 2013, 12:55:45 PM4/18/13
to django...@googlegroups.com
I agree that link is much better, I got the other one from settings.py



--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/pCJlPwvkirQ/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.



Reply all
Reply to author
Forward
0 new messages