diff --git a/django/core/management/commands/compilemessages.py b/django/core/management/commands/compilemessages.py
a
|
b
|
|
| 1 | import codecs |
1 | 2 | import os |
2 | 3 | import sys |
3 | 4 | from optparse import make_option |
… |
… |
|
8 | 9 | except NameError: |
9 | 10 | from sets import Set as set # For Python 2.3 |
10 | 11 | |
| 12 | def has_bom(fn): |
| 13 | f = open(fn, 'r') |
| 14 | sample = f.read(4) |
| 15 | return sample[:3] == '\xef\xbb\xbf' or \ |
| 16 | sample.startswith(codecs.BOM_UTF16_LE) or \ |
| 17 | sample.startswith(codecs.BOM_UTF16_BE) |
| 18 | |
11 | 19 | def compile_messages(locale=None): |
12 | 20 | basedirs = [os.path.join('conf', 'locale'), 'locale'] |
13 | 21 | if os.environ.get('DJANGO_SETTINGS_MODULE'): |
… |
… |
|
27 | 35 | for f in filenames: |
28 | 36 | if f.endswith('.po'): |
29 | 37 | sys.stderr.write('processing file %s in %s\n' % (f, dirpath)) |
30 | | pf = os.path.splitext(os.path.join(dirpath, f))[0] |
| 38 | fn = os.path.join(dirpath, f) |
| 39 | if has_bom(fn): |
| 40 | raise CommandError("The %s file has a BOM (Byte Order Mark). Django only supports .po files encoded in UTF-8 and without any BOM." % fn) |
| 41 | pf = os.path.splitext(fn)[0] |
31 | 42 | # Store the names of the .mo and .po files in an environment |
32 | 43 | # variable, rather than doing a string replacement into the |
33 | 44 | # command, so that we can take advantage of shell quoting, to |
diff --git a/docs/topics/i18n.txt b/docs/topics/i18n.txt
a
|
b
|
|
650 | 650 | ``django-admin compilemessages`` works see `gettext on Windows`_ for more |
651 | 651 | information. |
652 | 652 | |
| 653 | .. admonition:: .po files: Encoding and BOM usage. |
| 654 | |
| 655 | Django only supports ``.po`` files encoded in UTF-8 and without any BOM |
| 656 | (Byte Order Mark) so if your text editor adds BOM to the beginning of |
| 657 | files by default you need to configure it to not do so. |
| 658 | |
653 | 659 | .. _how-django-discovers-language-preference: |
654 | 660 | |
655 | 661 | 3. How Django discovers language preference |