From 309b5d264166e07510d6cbc54d681268d07957aa Mon Sep 17 00:00:00 2001 From: Craig Blaszczyk Date: Fri, 2 Jan 2015 11:07:35 +0000 Subject: instructions on how to translate REST framework error messages --- docs/topics/internationalisation.md | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 docs/topics/internationalisation.md (limited to 'docs/topics') diff --git a/docs/topics/internationalisation.md b/docs/topics/internationalisation.md new file mode 100644 index 00000000..01f96891 --- /dev/null +++ b/docs/topics/internationalisation.md @@ -0,0 +1,34 @@ +# Internationalisation +REST framework ships with translatable error messages. You can make these appear in your language enabling [Django's standard translation mechanisms](https://docs.djangoproject.com/en/1.7/topics/i18n/translation) and by translating the messages into your language. + +## How to translate REST Framework errors + + +This guide assumes you are already familiar with how to translate a Django app. If you're not, start by reading [Django's translation docs](https://docs.djangoproject.com/en/1.7/topics/i18n/translation). + + +#### To translate REST framework error messages: + +1. Pick an app where you want the translations to be, for example `myapp` + +2. Add a symlink from that app to the installed `rest_framework` + ``` + ln -s /home/user/.virtualenvs/myproject/lib/python2.7/site-packages/rest_framework/ rest_framework + ``` + + To find out where `rest_framework` is installed, run + + ``` + python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())" + ``` + +3. Run Django's `makemessages` command in the normal way, but add the `--symlink` option. For example, if you want to translate into Brazilian Portuguese you would run + ``` + manage.py makemessages --symlink -l pt_BR + ``` + +4. Translate the `django.po` file which is created as normal. This will be in the folder `myapp/locale/pt_BR/LC_MESSAGES`. + +5. Run `manage.py compilemessages` as normal + +6. Restart your server -- cgit v1.2.3 From 7ad7dd6a4292157ed5bcbaacb60b6ccc93fcf201 Mon Sep 17 00:00:00 2001 From: Craig Blaszczyk Date: Wed, 24 Dec 2014 18:26:17 +0000 Subject: match DRF style guide --- docs/topics/internationalisation.md | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'docs/topics') diff --git a/docs/topics/internationalisation.md b/docs/topics/internationalisation.md index 01f96891..552fdd27 100644 --- a/docs/topics/internationalisation.md +++ b/docs/topics/internationalisation.md @@ -1,10 +1,10 @@ # Internationalisation -REST framework ships with translatable error messages. You can make these appear in your language enabling [Django's standard translation mechanisms](https://docs.djangoproject.com/en/1.7/topics/i18n/translation) and by translating the messages into your language. +REST framework ships with translatable error messages. You can make these appear in your language enabling [Django's standard translation mechanisms][django-translation] and by translating the messages into your language. ## How to translate REST Framework errors -This guide assumes you are already familiar with how to translate a Django app. If you're not, start by reading [Django's translation docs](https://docs.djangoproject.com/en/1.7/topics/i18n/translation). +This guide assumes you are already familiar with how to translate a Django app. If you're not, start by reading [Django's translation docs][django-translation]. #### To translate REST framework error messages: @@ -16,19 +16,28 @@ This guide assumes you are already familiar with how to translate a Django app. ln -s /home/user/.virtualenvs/myproject/lib/python2.7/site-packages/rest_framework/ rest_framework ``` - To find out where `rest_framework` is installed, run + --- + + **Note:** To find out where `rest_framework` is installed, run ``` python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())" ``` -3. Run Django's `makemessages` command in the normal way, but add the `--symlink` option. For example, if you want to translate into Brazilian Portuguese you would run + --- + + + +3. Run Django's `makemessages` command in the normal way, but add the `--symlink` option. For example, if you want to translate into Brazilian Portuguese you would run ``` manage.py makemessages --symlink -l pt_BR ``` -4. Translate the `django.po` file which is created as normal. This will be in the folder `myapp/locale/pt_BR/LC_MESSAGES`. +4. Translate the `django.po` file which is created as normal. This will be in the folder `myapp/locale/pt_BR/LC_MESSAGES`. 5. Run `manage.py compilemessages` as normal 6. Restart your server + + +[django-translation]: https://docs.djangoproject.com/en/1.7/topics/i18n/translation -- cgit v1.2.3 From 2781903a5a0be7f5314de54ff2dbc8ef393eab0a Mon Sep 17 00:00:00 2001 From: Craig Blaszczyk Date: Fri, 26 Dec 2014 12:52:17 +0000 Subject: Add info about how django chooses which language to use --- docs/topics/internationalisation.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'docs/topics') diff --git a/docs/topics/internationalisation.md b/docs/topics/internationalisation.md index 552fdd27..a0aab753 100644 --- a/docs/topics/internationalisation.md +++ b/docs/topics/internationalisation.md @@ -40,4 +40,22 @@ This guide assumes you are already familiar with how to translate a Django app. 6. Restart your server + +## How Django chooses which language to use +REST framework will use the same preferences to select which language to display as Django does. You can find more info in the [django docs on discovering language preferences][django-language-preference]. For reference, these are + +1. First, it looks for the language prefix in the requested URL +2. Failing that, it looks for the `LANGUAGE_SESSION_KEY` key in the current user’s session. +3. Failing that, it looks for a cookie +4. Failing that, it looks at the `Accept-Language` HTTP header. +5. Failing that, it uses the global `LANGUAGE_CODE` setting. + +--- + +**Note:** You'll need to include the `django.middleware.locale.LocaleMiddleware` to enable any of the per-request language preferences. + +--- + + [django-translation]: https://docs.djangoproject.com/en/1.7/topics/i18n/translation +[django-language-preference]: https://docs.djangoproject.com/en/1.7/topics/i18n/translation/#how-django-discovers-language-preference -- cgit v1.2.3 From 0b8a83bd624673cb0a05e01c691729ccee3a8782 Mon Sep 17 00:00:00 2001 From: Craig Blaszczyk Date: Sun, 28 Dec 2014 18:20:41 +0000 Subject: update internationalisation instructions to prevent symlinking; add base .po file --- docs/topics/internationalisation.md | 52 +++++++++++++++++++++++++++++-------- 1 file changed, 41 insertions(+), 11 deletions(-) (limited to 'docs/topics') diff --git a/docs/topics/internationalisation.md b/docs/topics/internationalisation.md index a0aab753..6470ee03 100644 --- a/docs/topics/internationalisation.md +++ b/docs/topics/internationalisation.md @@ -9,13 +9,41 @@ This guide assumes you are already familiar with how to translate a Django app. #### To translate REST framework error messages: -1. Pick an app where you want the translations to be, for example `myapp` +1. Make a new folder where you want to store the translated errors. Add this +path to your [`LOCALE_PATHS`][django-locale-paths] setting. + + --- + + **Note:** For the rest of +this document we will assume the path you created was +`/home/www/project/conf/locale/`, and that you have updated your `settings.py` to include the setting: + + ``` + LOCALE_PATHS = ( + '/home/www/project/conf/locale/', + ) + ``` + + --- + +2. Now create a subfolder for the language you want to translate. The folder should be named using [locale +name][django-locale-name] notation. E.g. `de`, `pt_BR`, `es_AR`, etc. -2. Add a symlink from that app to the installed `rest_framework` ``` - ln -s /home/user/.virtualenvs/myproject/lib/python2.7/site-packages/rest_framework/ rest_framework + mkdir /home/www/project/conf/locale/pt_BR/LC_MESSAGES + ``` + +3. Now copy the base translations file from the REST framework source code +into your translations folder + + ``` + cp /home/user/.virtualenvs/myproject/lib/python2.7/site-packages/rest_framework/locale/en_US/LC_MESSAGES/django.po + /home/www/project/conf/locale/pt_BR/LC_MESSAGES ``` + This should create the file + `/home/www/project/conf/locale/pt_BR/LC_MESSAGES/django.po` + --- **Note:** To find out where `rest_framework` is installed, run @@ -27,17 +55,17 @@ This guide assumes you are already familiar with how to translate a Django app. --- +4. Edit `/home/www/project/conf/locale/pt_BR/LC_MESSAGES/django.po` and +translate all the error messages. -3. Run Django's `makemessages` command in the normal way, but add the `--symlink` option. For example, if you want to translate into Brazilian Portuguese you would run - ``` - manage.py makemessages --symlink -l pt_BR - ``` - -4. Translate the `django.po` file which is created as normal. This will be in the folder `myapp/locale/pt_BR/LC_MESSAGES`. +5. Run `manage.py compilemessages -l pt_BR` to make the translations +available for Django to use. You should see a message -5. Run `manage.py compilemessages` as normal + ``` + processing file django.po in /home/www/project/conf/locale/pt_BR/LC_MESSAGES + ``` -6. Restart your server +6. Restart your server. @@ -59,3 +87,5 @@ REST framework will use the same preferences to select which language to display [django-translation]: https://docs.djangoproject.com/en/1.7/topics/i18n/translation [django-language-preference]: https://docs.djangoproject.com/en/1.7/topics/i18n/translation/#how-django-discovers-language-preference +[django-locale-paths]: https://docs.djangoproject.com/en/1.7/ref/settings/#std:setting-LOCALE_PATHS +[django-locale-name]: https://docs.djangoproject.com/en/1.7/topics/i18n/#term-locale-name \ No newline at end of file -- cgit v1.2.3 From 9f169acb62a6223a5add0fee7f6d53108e42f207 Mon Sep 17 00:00:00 2001 From: Craig Blaszczyk Date: Wed, 31 Dec 2014 14:56:23 +0000 Subject: capitalise Django --- docs/topics/internationalisation.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'docs/topics') diff --git a/docs/topics/internationalisation.md b/docs/topics/internationalisation.md index 6470ee03..fac3bdb7 100644 --- a/docs/topics/internationalisation.md +++ b/docs/topics/internationalisation.md @@ -70,7 +70,8 @@ available for Django to use. You should see a message ## How Django chooses which language to use -REST framework will use the same preferences to select which language to display as Django does. You can find more info in the [django docs on discovering language preferences][django-language-preference]. For reference, these are +REST framework will use the same preferences to select which language to +display as Django does. You can find more info in the [Django docs on discovering language preferences][django-language-preference]. For reference, these are 1. First, it looks for the language prefix in the requested URL 2. Failing that, it looks for the `LANGUAGE_SESSION_KEY` key in the current user’s session. -- cgit v1.2.3 From 7913947757b0e6bd1b8828db81933c32c498e20a Mon Sep 17 00:00:00 2001 From: Craig Blaszczyk Date: Wed, 7 Jan 2015 11:13:03 +0000 Subject: add config and documentation about uploading/downloading translations from Transifex --- docs/topics/internationalisation.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'docs/topics') diff --git a/docs/topics/internationalisation.md b/docs/topics/internationalisation.md index fac3bdb7..2a476c86 100644 --- a/docs/topics/internationalisation.md +++ b/docs/topics/internationalisation.md @@ -3,11 +3,13 @@ REST framework ships with translatable error messages. You can make these appea ## How to translate REST Framework errors +REST framework translations are managed online using [Transifex.com][transifex]. To get started, checkout the guide in the [CONTRIBUTING.md guide][contributing]. -This guide assumes you are already familiar with how to translate a Django app. If you're not, start by reading [Django's translation docs][django-translation]. +Sometimes you may want to use REST Framework in a language which has not been translated yet on Transifex. If that is the case then you should translate the error messages locally. +#### How to translate REST Framework error messages locally: -#### To translate REST framework error messages: +This guide assumes you are already familiar with how to translate a Django app. If you're not, start by reading [Django's translation docs][django-translation]. 1. Make a new folder where you want to store the translated errors. Add this path to your [`LOCALE_PATHS`][django-locale-paths] setting. @@ -89,4 +91,5 @@ display as Django does. You can find more info in the [Django docs on discoveri [django-translation]: https://docs.djangoproject.com/en/1.7/topics/i18n/translation [django-language-preference]: https://docs.djangoproject.com/en/1.7/topics/i18n/translation/#how-django-discovers-language-preference [django-locale-paths]: https://docs.djangoproject.com/en/1.7/ref/settings/#std:setting-LOCALE_PATHS -[django-locale-name]: https://docs.djangoproject.com/en/1.7/topics/i18n/#term-locale-name \ No newline at end of file +[django-locale-name]: https://docs.djangoproject.com/en/1.7/topics/i18n/#term-locale-name +[contributing]: ../../CONTRIBUTING.md -- cgit v1.2.3