Friday, 15 January 2010

python - Django: localize the API calls's resposnse -



python - Django: localize the API calls's resposnse -

i have api interface application , want response of these calls back upwards various languages.

def get_student(request): //code homecoming jsonresponse(content={"message": "student found"}, status=200)

i have gone through django-localization documentation , have created po , mo files specific language. , i'm stuck on how utilize files , give response in particular language.

any help or reference appreciated. edit: 1 helped settings.locale_paths = (os.path.join(project_dir, 'locale')) ,

https://docs.djangoproject.com/en/1.3/howto/i18n/

before worrying .mo , .po files, need set various flags, languages , middlewares in settings, , mark translatable text in apps , templates.

you should start here https://docs.djangoproject.com/en/1.3/topics/i18n/ big pictures , definitions, go on here https://docs.djangoproject.com/en/1.3/topics/i18n/translation/ how mark translatable strings. don't skip notes there configuration job do.

about how mark string translatable, in above snippet, should looks like:

from django.utils.translation import ugettext _ def get_student(request): //code homecoming jsonresponse(content={"message": _(u"student found")}, status=200)

once you're done marking translatable texts, it's time generate source translation files (.po), edit them actual translations , generate compiled translations files (.mo) documented.

python django

No comments:

Post a Comment