Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to translate django.po files

First open file in the text editor (e.g. locale/ru/LC_MESSAGES/django.po)

In the simplest situation you will have lines like these:

msgid "Welcome to our website!"
msgstr ""

The string keys (translatable strings in the source code) are prefixed with msgid - you should never touch those! Your translations should go into strings starting with msgstr.

Strings themselves (both keys and translations) are always enclosed into double quotes. (If you need to use double quote inside the string itself - escape it with a backslash "string with a \" - double quote")

How to translate django.po files

First open file in the text editor (e.g. locale/ru/LC_MESSAGES/django.po)

In the simplest situation you will have lines like these:

#: django_authopenid/forms.py:162
msgid "Welcome to our website!"
msgstr ""

The string keys (translatable strings in the source code) are prefixed with msgid - you should never touch those! those (even if they look strange)! Your translations should go into strings starting with msgstr.. If you do decide to change the key - instead of changing it in the django.po file do it in the source code and use command makemessages to rebuild the django.po file(s).

Strings themselves (both keys and translations) are always enclosed into double quotes. (If you need to use double quote inside the string itself - escape it with a backslash "string with a \" - double quote")

Comments are important

In the previous example there was a line

#: django_authopenid/forms.py:162

This is a comment (because it starts with #) - do not delete or modify them (there is one exception where you do need to edit comments). The comment contains information on where this message is coming from in the source code. You will use this comment when you decide to modify the translation key.

Lines that start with a newline

Some entries will look like

msgid ""
"some text"
msgstr ""

In this case translation is empty, but the key consists of two lines (of which first one is also empty). When you add your translation to this item you must keep first line in msgstr part empty as well:

msgid ""
"some text"
msgstr ""
"немного текста"

How to translate django.po files

First open file in the text editor (e.g. locale/ru/LC_MESSAGES/django.po)

In the simplest situation you will have lines like these:

#: django_authopenid/forms.py:162
msgid "Welcome to our website!"
msgstr ""

The string keys (translatable strings in the source code) are prefixed with msgid - you should never touch those (even if they look strange)! Your translations should go into strings starting with msgstr. If you do decide to change the key - instead of changing it in the django.po file do it in the source code and use command makemessages to rebuild the django.po file(s).

Strings themselves (both keys and translations) are always enclosed into double quotes. (If you need to use double quote inside the string itself - escape it with a backslash "string with a \" - double quote")

Comments are important

In the previous example there was a line

#: django_authopenid/forms.py:162

This is a comment (because it starts with #) - do not delete or modify them (there is one exception where you do need to edit comments). The comment contains information on where this message is coming from in the source code. You will use this comment when you decide to modify the translation key.

There is one case when you do need to edit the comment - when you see line starting with

#, fuzzy

This comment indicates that .po file has been rebuilt and the key string has been changed in the source file and the gettext system has guessed the meaning of the string. This comment is actually trying to help you locate strings that need your attention - so check the translation of those and then delete the , fuzzy part.

Make sure to never delete anything that might follow that comment. For example change:

#, fuzzy, python-format

to

#, python-format

Do not delete the whole line in this case, however you can delete the whole comment if it contains only , fuzzy note.

Lines that start with a newline

Some entries will look like

msgid ""
"some text"
msgstr ""

In this case translation is empty, but the key consists of two lines (of which first one is also empty). When you add your translation to this item you must keep first line in msgstr part empty as well:

msgid ""
"some text"
msgstr ""
"немного текста"

How to translate django.po files

First open file in the text editor (e.g. locale/ru/LC_MESSAGES/django.po)

In the simplest situation you will have lines like these:

#: django_authopenid/forms.py:162
msgid "Welcome to our website!"
msgstr ""

The string keys (translatable strings in the source code) are prefixed with msgid - you should never touch those (even if they look strange)! Your translations should go into strings starting with msgstr. If you do decide to change the key - instead of changing it in the django.po file do it in the source code and use command makemessages to rebuild the django.po file(s).

Strings themselves (both keys and translations) are always enclosed into double quotes. (If you need to use double quote inside the string itself - escape it with a backslash "string with a \" - double quote")

Comments are important

In the previous example there was a line

#: django_authopenid/forms.py:162

This is a comment (because it starts with #) - do not delete or modify them (there is one exception this type of comment as it tells where you do need to edit comments). The comment contains information on where in the source code this message is coming from in the source code. from. You will use this comment when you decide to modify the translation key.key. The same string can be actually used in many places throughout the program and the comment will list all of them.

There is one case when you do need to edit the comment - when you see line starting with

#, fuzzy

This comment , fuzzy note indicates that .po file has been rebuilt and the key string has been changed in the source file and the gettext system has guessed the meaning of the string. This comment is actually trying to help you locate strings that need your attention - so check the translation of those and then delete the , fuzzy part.

Make sure to never delete anything that might follow that comment. comment on the same line. For example change:

#, fuzzy, python-format

to

#, python-format

Do not delete the whole line in this case, however case. (However you can delete the whole comment if it contains only , fuzzy note.note).

Lines Keys that start with a newline

Gettext system has a convention that if a key starts with a newline - then translations also must start with the new line.

Some entries will look like

msgid ""
"\n"
"some text"
msgstr ""

In this case translation is empty, but the key consists of two lines (of which string starts with a new line - how can you tell that is explained below.

First, the key string is split into three: "", "\n" and "some text". \n - means "new line" - that is there is a line break. The first one is also empty). string is empty - therefore \n (newline) is the first character in the whole key.

When you add your translation to this item you must keep first line in msgstr part empty as well:

msgid ""
"\n"
"some text"
msgstr ""
"\n"
"немного текста"

First "" is not really necessary in the translation as long as the the first character in the translation is `\n'

How to translate django.po files

First open file in the text editor (e.g. locale/ru/LC_MESSAGES/django.po)

In the simplest situation you will have lines like these:

#: django_authopenid/forms.py:162
msgid "Welcome to our website!"
msgstr ""

The string keys (translatable strings in the source code) are prefixed with msgid - you should never touch those (even if they look strange)! Your translations should go into strings starting with msgstr. If you do decide to change the key - instead of changing it in the django.po file do it in the source code and use command makemessages to rebuild the django.po file(s).

Strings themselves (both keys and translations) are always enclosed into double quotes. (If you need to use double quote inside the string itself - escape it with a backslash "string with a \" - double quote")

). Backslash indicates start of the "escape sequence" - often indicating a special character \n means "new line" or an entry delimiter (double quote in this case).

So in the simple case above the Russian translation will look this way

msgid "Welcome to our website!"
msgstr "Добро пожаловать на наш сайт!"

Comments are important

In the previous example there was a line

#: django_authopenid/forms.py:162

This is a comment (because it starts with #) - do not delete or modify this type of comment as it tells where in the source code this message is coming from. You will use this comment when you decide to modify the translation key. The same string can be actually used in many places throughout the program and the comment will list all of them.

There is one case when you do need to edit comment - when you see line starting with

#, fuzzy

, fuzzy note indicates that the key string has been changed in the source file and the gettext system has guessed the meaning of the string. This comment is actually trying to help you locate strings that need your attention - so check the translation of those and then delete the , fuzzy part.

Make sure to never delete anything that might follow that comment on the same line. For example change:

#, fuzzy, python-format

to

#, python-format

Do not delete the whole line in this case. (However you can delete the whole comment if it contains only , fuzzy note).

Keys that start with a newline

Gettext system has a convention that if a key starts with a newline - then translations also must start with the new line.

Some entries will look like

msgid ""
"\n"
"some text"
msgstr ""

In this case key string starts with a new line - how can you tell that is explained below.

First, the key string is split into three: "", "\n" and "some text". \n - means "new line" - that is there is a line break. The first string is empty - therefore \n (newline) is the first character in the whole key.

When you add your translation to this item you must keep first line in msgstr part empty as well:

msgid ""
"\n"
"some text"
msgstr ""
"\n"
"немного текста"

First "" is not really necessary in the translation as long as the the first character in the translation is `\n'

How to translate django.po files

First open file in the text editor (e.g. locale/ru/LC_MESSAGES/django.po)

In the simplest situation you will have lines like these:

#: django_authopenid/forms.py:162
msgid "Welcome to our website!"
msgstr ""

The string keys (translatable strings in the source code) are prefixed with msgid - you should never touch those (even if they look strange)! Your translations should go into strings starting with msgstr. If you do decide to change the key - instead of changing it in the django.po file do it in the source code and use command makemessages to rebuild the django.po file(s).

Strings themselves (both keys and translations) are always enclosed into double quotes. (If you need to use double quote inside the string itself - escape it with a backslash "string with a \" - double quote"). Backslash indicates start of the "escape sequence" - often indicating a special character \n means "new line" or an entry delimiter (double quote in this case).

So in the simple case above the Russian translation will look this way

msgid "Welcome to our website!"
msgstr "Добро пожаловать на наш сайт!"

Comments are important

In the previous example there was a line

#: django_authopenid/forms.py:162

This is a comment (because it starts with #) - do not delete or modify this type of comment as it tells where in the source code this message is coming from. You will use this comment when you decide to modify the translation key. The same string can be actually used in many places throughout the program and the comment will list all of them.

There is one case when you do need to edit comment - when you see line starting with

#, fuzzy

, fuzzy note indicates that the key string has been changed in the source file and the gettext system has guessed the meaning of the string. This comment is actually trying to help you locate strings that need your attention - so check the translation of those and then delete the , fuzzy part.

Make sure to never delete anything that might follow that comment on the same line. For example change:

#, fuzzy, python-format

to

#, python-format

Do not delete the whole line in this case. (However you can delete the whole comment if it contains only , fuzzy note).

Keys that start with a newline

Gettext system has a convention that if a key starts with a newline - then translations also must start with the new line.

Some entries will look like

msgid ""
"\n"
"some text"
msgstr ""

In this case key string starts with a new line - how can you tell that is explained below.

First, the key string is split into three: "", "\n" and "some text". \n - means "new line" - that is there is a line break. The first string is empty - therefore \n (newline) is the first character in the whole key.

When you add your Your translation to this item you string also must keep first line in msgstr part empty as well:start with a new line:

msgid ""
"\n"
"some text"
msgstr ""
"\n"
"немного текста"

First "" is not really necessary in the translation as long as the the first character in the translation is `\n'

How to translate django.po files

First open file in the text editor (e.g. locale/ru/LC_MESSAGES/django.po)

In the simplest situation you will have lines like these:

#: django_authopenid/forms.py:162
msgid "Welcome to our website!"
msgstr ""

The string keys (translatable strings in the source code) are prefixed with msgid - you should never touch those (even if they look strange)! Your translations should go into strings starting with msgstr. If you do decide to change the key - instead of changing it in the django.po file do it in the source code and use command makemessages to rebuild the django.po file(s).

Strings themselves (both keys and translations) are always enclosed into double quotes. (If you need to use double quote inside the string itself - escape it with a backslash "string with a \" - double quote"). Backslash indicates start of the "escape sequence" - often indicating a special character \n means "new line" or an entry delimiter (double quote in this case).

So in the simple case above the Russian translation will look this way

msgid "Welcome to our website!"
msgstr "Добро пожаловать на наш сайт!"

Comments are important

In the previous example there was a line

#: django_authopenid/forms.py:162

This is a comment (because it starts with #) - do not delete or modify this type of comment as it tells where in the source code this message is coming from. You will use this comment when you decide to modify the translation key. The same string can be actually used in many places throughout the program and the comment will list all of them.

There is one case when you do need to edit comment - when you see line starting with

#, fuzzy

, fuzzy note indicates that the key string has been changed in the source file and the gettext system has guessed the meaning of the string. This comment is actually trying to help you locate strings that need your attention - so check the translation of those and then delete the , fuzzy part.

Make sure to never delete anything that might follow that comment on the same line. For example change:

#, fuzzy, python-format

to

#, python-format

Do not delete the whole line in this case. (However you can delete the whole comment if it contains only , fuzzy note).

Keys that start with a newline

Gettext system has a convention that if a key starts with a newline - then translations also must start with the new line.

Some entries will look like

msgid ""
"\n"
"some text"
msgstr ""

In this case key string starts with a new line - how can you tell that is explained below.

First, the key string is split into three: "", "\n" and "some text". \n - means "new line" - that is there is a line break. The first string is empty - therefore \n (newline) is the first character in the whole key.

Your translation string also must start with a new line:

msgid ""
"\n"
"some text"
msgstr ""
"\n"
"немного текста"

First "" is not really necessary in the translation as long as the the first character in the translation is `\n'

\n. If you omit the newline character there will be an error message when you try compiling .po files.

How to translate django.po files

First open file in the text editor (e.g. locale/ru/LC_MESSAGES/django.po)

In the simplest situation you will have lines like these:

#: django_authopenid/forms.py:162
msgid "Welcome to our website!"
msgstr ""

The string keys (translatable strings in the source code) are prefixed with msgid - you should never touch those (even if they look strange)! Your translations should go into strings starting with msgstr. If you do decide to change the key - instead of changing it in the django.po file do it in the source code and use command makemessages to rebuild the django.po file(s).

Strings themselves (both keys and translations) are always enclosed into double quotes. (If you need to use double quote inside the string itself - escape it with a backslash "string with a \" - double quote"). Backslash indicates start of the "escape sequence" - often indicating a special character \n means "new line" or an entry delimiter (double quote in this case).

So in the simple case above the Russian translation will look this way

msgid "Welcome to our website!"
msgstr "Добро пожаловать на наш сайт!"

Comments are important

In the previous example there was a line

#: django_authopenid/forms.py:162

This is a comment (because it starts with #) - do not delete or modify this type of comment as it tells where in the source code this message is coming from. You will use this comment when you decide to modify the translation key. The same string can be actually used in many places throughout the program and the comment will list all of them.

There is one case when you do need to edit comment - when you see line starting with

#, fuzzy

, fuzzy note indicates that the key string has been changed in the source file and the gettext system has guessed the meaning of the string. This comment is actually trying to help you locate strings that need your attention - so check the translation of those and then delete the , fuzzy part.

Make sure to never delete anything that might follow that comment on the same line. For example change:

#, fuzzy, python-format

to

#, python-format

Do not delete the whole line in this case. (However you can delete the whole comment if it contains only , fuzzy note).

Translating strings with variables

Here is a simple example of a string with a variable (comments with line numbers are omitted):

#, python-format
msgid "see questions tagged '%(tag)s'"
msgstr ""

The key has %(tag)s - that's the most important part. It means that value of a variable named "tag" will be inserted into the string - by the program. Name of the variable is enclosed into parentheses () and preceded by %; s right after the closing parenthesis ) means that variable is of string type. Finally, comment #, python-format instructs the gettext system that this translation is prepared for a program written in python programming language.

Here is how translation might look like:

#, python-format
msgid "see questions tagged '%(tag)s'"
msgstr "вопросы по темам '%(tag)s'"

Variable names are never translated. Also format of the variable entry must be preserved.

Note: even though in this case names of tags will be listed in the end of the string both in English and Russian, the variable in the translation may be moved around and even may be inserted more than once.

Keys that start with a newline

Gettext system has a convention that if a key starts with a newline - then translations also must start with the new line.

Some entries will look like

msgid ""
"\n"
"some text"
msgstr ""

In this case key string starts with a new line - how can you tell that is explained below.

First, the key string is split into three: "", "\n" and "some text". \n - means "new line" - that is there is a line break. The first string is empty - therefore \n (newline) is the first character in the whole key.

Your translation string also must start with a new line:

msgid ""
"\n"
"some text"
msgstr ""
"\n"
"немного текста"

First "" is not really necessary in the translation as long as the the first character in the translation is \n. If you omit the newline character there will be an error message when you try compiling .po files.