Mercurial > babel > old > mirror
annotate babel/messages/tests/pofile.py @ 193:b5e58a22ebd2
Add an option to the frontend commands for catalog updating that removes completely any obsolete messages, instead of putting them comments.
author | cmlenz |
---|---|
date | Sun, 01 Jul 2007 17:59:44 +0000 |
parents | 8f5805197198 |
children | 982d7e704fdc |
rev | line source |
---|---|
3 | 1 # -*- coding: utf-8 -*- |
2 # | |
14
29ef15a6fd75
* Removed pkg_resources/setuptools requirement from various places.
cmlenz
parents:
3
diff
changeset
|
3 # Copyright (C) 2007 Edgewall Software |
3 | 4 # All rights reserved. |
5 # | |
6 # This software is licensed as described in the file COPYING, which | |
7 # you should have received as part of this distribution. The terms | |
8 # are also available at http://babel.edgewall.org/wiki/License. | |
9 # | |
10 # This software consists of voluntary contributions made by many | |
11 # individuals. For the exact contribution history, see the revision | |
12 # history and logs, available at http://babel.edgewall.org/log/. | |
13 | |
106
2a00e352c986
Merged `write_pot` and `write_po` functions by moving more functionality to the `Catalog` class. This is certainly not perfect yet, but moves us in the right direction.
cmlenz
parents:
105
diff
changeset
|
14 from datetime import datetime |
3 | 15 import doctest |
26
93eaa2f4a0a2
Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents:
19
diff
changeset
|
16 from StringIO import StringIO |
3 | 17 import unittest |
18 | |
183
e927dffc9ab4
The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents:
177
diff
changeset
|
19 from babel.messages.catalog import Catalog, Message |
56
27d55a07c897
Rename the `babel.catalog` package to `babel.messages` for consistency with the other package names.
cmlenz
parents:
53
diff
changeset
|
20 from babel.messages import pofile |
3 | 21 |
19
762a5de6faae
Recognize python-format messages also for unnamed parameters.
cmlenz
parents:
14
diff
changeset
|
22 |
108
8ea225f33f28
Fix for #16: the header message (`msgid = ""`) is now treated specially by `read_po` and `Catalog`.
cmlenz
parents:
107
diff
changeset
|
23 class ReadPoTestCase(unittest.TestCase): |
8ea225f33f28
Fix for #16: the header message (`msgid = ""`) is now treated specially by `read_po` and `Catalog`.
cmlenz
parents:
107
diff
changeset
|
24 |
8ea225f33f28
Fix for #16: the header message (`msgid = ""`) is now treated specially by `read_po` and `Catalog`.
cmlenz
parents:
107
diff
changeset
|
25 def test_read_multiline(self): |
8ea225f33f28
Fix for #16: the header message (`msgid = ""`) is now treated specially by `read_po` and `Catalog`.
cmlenz
parents:
107
diff
changeset
|
26 buf = StringIO(r'''msgid "" |
8ea225f33f28
Fix for #16: the header message (`msgid = ""`) is now treated specially by `read_po` and `Catalog`.
cmlenz
parents:
107
diff
changeset
|
27 "Here's some text that\n" |
8ea225f33f28
Fix for #16: the header message (`msgid = ""`) is now treated specially by `read_po` and `Catalog`.
cmlenz
parents:
107
diff
changeset
|
28 "includesareallylongwordthatmightbutshouldnt" |
8ea225f33f28
Fix for #16: the header message (`msgid = ""`) is now treated specially by `read_po` and `Catalog`.
cmlenz
parents:
107
diff
changeset
|
29 " throw us into an infinite " |
8ea225f33f28
Fix for #16: the header message (`msgid = ""`) is now treated specially by `read_po` and `Catalog`.
cmlenz
parents:
107
diff
changeset
|
30 "loop\n" |
8ea225f33f28
Fix for #16: the header message (`msgid = ""`) is now treated specially by `read_po` and `Catalog`.
cmlenz
parents:
107
diff
changeset
|
31 msgstr ""''') |
8ea225f33f28
Fix for #16: the header message (`msgid = ""`) is now treated specially by `read_po` and `Catalog`.
cmlenz
parents:
107
diff
changeset
|
32 catalog = pofile.read_po(buf) |
8ea225f33f28
Fix for #16: the header message (`msgid = ""`) is now treated specially by `read_po` and `Catalog`.
cmlenz
parents:
107
diff
changeset
|
33 self.assertEqual(1, len(catalog)) |
8ea225f33f28
Fix for #16: the header message (`msgid = ""`) is now treated specially by `read_po` and `Catalog`.
cmlenz
parents:
107
diff
changeset
|
34 message = list(catalog)[1] |
8ea225f33f28
Fix for #16: the header message (`msgid = ""`) is now treated specially by `read_po` and `Catalog`.
cmlenz
parents:
107
diff
changeset
|
35 self.assertEqual("Here's some text that\nincludesareallylongwordthat" |
8ea225f33f28
Fix for #16: the header message (`msgid = ""`) is now treated specially by `read_po` and `Catalog`.
cmlenz
parents:
107
diff
changeset
|
36 "mightbutshouldnt throw us into an infinite loop\n", |
8ea225f33f28
Fix for #16: the header message (`msgid = ""`) is now treated specially by `read_po` and `Catalog`.
cmlenz
parents:
107
diff
changeset
|
37 message.id) |
177
47f6c31e9a24
Changed the `__repr__` output to include the flags(it can be changed back, but it was usefull to implement the fuzzy header parsing).
palgarvio
parents:
108
diff
changeset
|
38 |
47f6c31e9a24
Changed the `__repr__` output to include the flags(it can be changed back, but it was usefull to implement the fuzzy header parsing).
palgarvio
parents:
108
diff
changeset
|
39 def test_fuzzy_header(self): |
47f6c31e9a24
Changed the `__repr__` output to include the flags(it can be changed back, but it was usefull to implement the fuzzy header parsing).
palgarvio
parents:
108
diff
changeset
|
40 buf = StringIO(r'''\ |
47f6c31e9a24
Changed the `__repr__` output to include the flags(it can be changed back, but it was usefull to implement the fuzzy header parsing).
palgarvio
parents:
108
diff
changeset
|
41 # Translations template for AReallyReallyLongNameForAProject. |
47f6c31e9a24
Changed the `__repr__` output to include the flags(it can be changed back, but it was usefull to implement the fuzzy header parsing).
palgarvio
parents:
108
diff
changeset
|
42 # Copyright (C) 2007 ORGANIZATION |
47f6c31e9a24
Changed the `__repr__` output to include the flags(it can be changed back, but it was usefull to implement the fuzzy header parsing).
palgarvio
parents:
108
diff
changeset
|
43 # This file is distributed under the same license as the |
47f6c31e9a24
Changed the `__repr__` output to include the flags(it can be changed back, but it was usefull to implement the fuzzy header parsing).
palgarvio
parents:
108
diff
changeset
|
44 # AReallyReallyLongNameForAProject project. |
47f6c31e9a24
Changed the `__repr__` output to include the flags(it can be changed back, but it was usefull to implement the fuzzy header parsing).
palgarvio
parents:
108
diff
changeset
|
45 # FIRST AUTHOR <EMAIL@ADDRESS>, 2007. |
47f6c31e9a24
Changed the `__repr__` output to include the flags(it can be changed back, but it was usefull to implement the fuzzy header parsing).
palgarvio
parents:
108
diff
changeset
|
46 # |
47f6c31e9a24
Changed the `__repr__` output to include the flags(it can be changed back, but it was usefull to implement the fuzzy header parsing).
palgarvio
parents:
108
diff
changeset
|
47 #, fuzzy |
47f6c31e9a24
Changed the `__repr__` output to include the flags(it can be changed back, but it was usefull to implement the fuzzy header parsing).
palgarvio
parents:
108
diff
changeset
|
48 ''') |
47f6c31e9a24
Changed the `__repr__` output to include the flags(it can be changed back, but it was usefull to implement the fuzzy header parsing).
palgarvio
parents:
108
diff
changeset
|
49 catalog = pofile.read_po(buf) |
47f6c31e9a24
Changed the `__repr__` output to include the flags(it can be changed back, but it was usefull to implement the fuzzy header parsing).
palgarvio
parents:
108
diff
changeset
|
50 self.assertEqual(1, len(list(catalog))) |
47f6c31e9a24
Changed the `__repr__` output to include the flags(it can be changed back, but it was usefull to implement the fuzzy header parsing).
palgarvio
parents:
108
diff
changeset
|
51 self.assertEqual(True, list(catalog)[0].fuzzy) |
47f6c31e9a24
Changed the `__repr__` output to include the flags(it can be changed back, but it was usefull to implement the fuzzy header parsing).
palgarvio
parents:
108
diff
changeset
|
52 |
47f6c31e9a24
Changed the `__repr__` output to include the flags(it can be changed back, but it was usefull to implement the fuzzy header parsing).
palgarvio
parents:
108
diff
changeset
|
53 def test_not_fuzzy_header(self): |
47f6c31e9a24
Changed the `__repr__` output to include the flags(it can be changed back, but it was usefull to implement the fuzzy header parsing).
palgarvio
parents:
108
diff
changeset
|
54 buf = StringIO(r'''\ |
47f6c31e9a24
Changed the `__repr__` output to include the flags(it can be changed back, but it was usefull to implement the fuzzy header parsing).
palgarvio
parents:
108
diff
changeset
|
55 # Translations template for AReallyReallyLongNameForAProject. |
47f6c31e9a24
Changed the `__repr__` output to include the flags(it can be changed back, but it was usefull to implement the fuzzy header parsing).
palgarvio
parents:
108
diff
changeset
|
56 # Copyright (C) 2007 ORGANIZATION |
47f6c31e9a24
Changed the `__repr__` output to include the flags(it can be changed back, but it was usefull to implement the fuzzy header parsing).
palgarvio
parents:
108
diff
changeset
|
57 # This file is distributed under the same license as the |
47f6c31e9a24
Changed the `__repr__` output to include the flags(it can be changed back, but it was usefull to implement the fuzzy header parsing).
palgarvio
parents:
108
diff
changeset
|
58 # AReallyReallyLongNameForAProject project. |
47f6c31e9a24
Changed the `__repr__` output to include the flags(it can be changed back, but it was usefull to implement the fuzzy header parsing).
palgarvio
parents:
108
diff
changeset
|
59 # FIRST AUTHOR <EMAIL@ADDRESS>, 2007. |
47f6c31e9a24
Changed the `__repr__` output to include the flags(it can be changed back, but it was usefull to implement the fuzzy header parsing).
palgarvio
parents:
108
diff
changeset
|
60 # |
47f6c31e9a24
Changed the `__repr__` output to include the flags(it can be changed back, but it was usefull to implement the fuzzy header parsing).
palgarvio
parents:
108
diff
changeset
|
61 ''') |
47f6c31e9a24
Changed the `__repr__` output to include the flags(it can be changed back, but it was usefull to implement the fuzzy header parsing).
palgarvio
parents:
108
diff
changeset
|
62 catalog = pofile.read_po(buf) |
47f6c31e9a24
Changed the `__repr__` output to include the flags(it can be changed back, but it was usefull to implement the fuzzy header parsing).
palgarvio
parents:
108
diff
changeset
|
63 self.assertEqual(1, len(list(catalog))) |
47f6c31e9a24
Changed the `__repr__` output to include the flags(it can be changed back, but it was usefull to implement the fuzzy header parsing).
palgarvio
parents:
108
diff
changeset
|
64 self.assertEqual(False, list(catalog)[0].fuzzy) |
108
8ea225f33f28
Fix for #16: the header message (`msgid = ""`) is now treated specially by `read_po` and `Catalog`.
cmlenz
parents:
107
diff
changeset
|
65 |
8ea225f33f28
Fix for #16: the header message (`msgid = ""`) is now treated specially by `read_po` and `Catalog`.
cmlenz
parents:
107
diff
changeset
|
66 |
106
2a00e352c986
Merged `write_pot` and `write_po` functions by moving more functionality to the `Catalog` class. This is certainly not perfect yet, but moves us in the right direction.
cmlenz
parents:
105
diff
changeset
|
67 class WritePoTestCase(unittest.TestCase): |
26
93eaa2f4a0a2
Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents:
19
diff
changeset
|
68 |
93eaa2f4a0a2
Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents:
19
diff
changeset
|
69 def test_join_locations(self): |
58
068952b4d4c0
Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
56
diff
changeset
|
70 catalog = Catalog() |
068952b4d4c0
Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
56
diff
changeset
|
71 catalog.add(u'foo', locations=[('main.py', 1)]) |
068952b4d4c0
Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
56
diff
changeset
|
72 catalog.add(u'foo', locations=[('utils.py', 3)]) |
26
93eaa2f4a0a2
Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents:
19
diff
changeset
|
73 buf = StringIO() |
106
2a00e352c986
Merged `write_pot` and `write_po` functions by moving more functionality to the `Catalog` class. This is certainly not perfect yet, but moves us in the right direction.
cmlenz
parents:
105
diff
changeset
|
74 pofile.write_po(buf, catalog, omit_header=True) |
26
93eaa2f4a0a2
Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents:
19
diff
changeset
|
75 self.assertEqual('''#: main.py:1 utils.py:3 |
93eaa2f4a0a2
Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents:
19
diff
changeset
|
76 msgid "foo" |
93eaa2f4a0a2
Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents:
19
diff
changeset
|
77 msgstr ""''', buf.getvalue().strip()) |
93eaa2f4a0a2
Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents:
19
diff
changeset
|
78 |
93eaa2f4a0a2
Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents:
19
diff
changeset
|
79 def test_wrap_long_lines(self): |
93eaa2f4a0a2
Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents:
19
diff
changeset
|
80 text = """Here's some text where |
93eaa2f4a0a2
Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents:
19
diff
changeset
|
81 white space and line breaks matter, and should |
93eaa2f4a0a2
Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents:
19
diff
changeset
|
82 |
93eaa2f4a0a2
Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents:
19
diff
changeset
|
83 not be removed |
93eaa2f4a0a2
Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents:
19
diff
changeset
|
84 |
93eaa2f4a0a2
Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents:
19
diff
changeset
|
85 """ |
58
068952b4d4c0
Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
56
diff
changeset
|
86 catalog = Catalog() |
068952b4d4c0
Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
56
diff
changeset
|
87 catalog.add(text, locations=[('main.py', 1)]) |
26
93eaa2f4a0a2
Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents:
19
diff
changeset
|
88 buf = StringIO() |
106
2a00e352c986
Merged `write_pot` and `write_po` functions by moving more functionality to the `Catalog` class. This is certainly not perfect yet, but moves us in the right direction.
cmlenz
parents:
105
diff
changeset
|
89 pofile.write_po(buf, catalog, no_location=True, omit_header=True, |
58
068952b4d4c0
Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
56
diff
changeset
|
90 width=42) |
26
93eaa2f4a0a2
Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents:
19
diff
changeset
|
91 self.assertEqual(r'''msgid "" |
93eaa2f4a0a2
Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents:
19
diff
changeset
|
92 "Here's some text where \n" |
93eaa2f4a0a2
Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents:
19
diff
changeset
|
93 "white space and line breaks matter, and" |
93eaa2f4a0a2
Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents:
19
diff
changeset
|
94 " should\n" |
93eaa2f4a0a2
Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents:
19
diff
changeset
|
95 "\n" |
93eaa2f4a0a2
Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents:
19
diff
changeset
|
96 "not be removed\n" |
93eaa2f4a0a2
Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents:
19
diff
changeset
|
97 "\n" |
93eaa2f4a0a2
Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents:
19
diff
changeset
|
98 msgstr ""''', buf.getvalue().strip()) |
93eaa2f4a0a2
Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents:
19
diff
changeset
|
99 |
93eaa2f4a0a2
Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents:
19
diff
changeset
|
100 def test_wrap_long_lines_with_long_word(self): |
93eaa2f4a0a2
Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents:
19
diff
changeset
|
101 text = """Here's some text that |
93eaa2f4a0a2
Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents:
19
diff
changeset
|
102 includesareallylongwordthatmightbutshouldnt throw us into an infinite loop |
93eaa2f4a0a2
Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents:
19
diff
changeset
|
103 """ |
58
068952b4d4c0
Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
56
diff
changeset
|
104 catalog = Catalog() |
068952b4d4c0
Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
56
diff
changeset
|
105 catalog.add(text, locations=[('main.py', 1)]) |
26
93eaa2f4a0a2
Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents:
19
diff
changeset
|
106 buf = StringIO() |
106
2a00e352c986
Merged `write_pot` and `write_po` functions by moving more functionality to the `Catalog` class. This is certainly not perfect yet, but moves us in the right direction.
cmlenz
parents:
105
diff
changeset
|
107 pofile.write_po(buf, catalog, no_location=True, omit_header=True, |
58
068952b4d4c0
Add actual data structures for handling message catalogs, so that more code can be reused here between the frontends.
cmlenz
parents:
56
diff
changeset
|
108 width=32) |
26
93eaa2f4a0a2
Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents:
19
diff
changeset
|
109 self.assertEqual(r'''msgid "" |
93eaa2f4a0a2
Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents:
19
diff
changeset
|
110 "Here's some text that\n" |
93eaa2f4a0a2
Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents:
19
diff
changeset
|
111 "includesareallylongwordthatmightbutshouldnt" |
93eaa2f4a0a2
Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents:
19
diff
changeset
|
112 " throw us into an infinite " |
93eaa2f4a0a2
Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents:
19
diff
changeset
|
113 "loop\n" |
93eaa2f4a0a2
Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents:
19
diff
changeset
|
114 msgstr ""''', buf.getvalue().strip()) |
82
f421e5576d26
Added support for translator comments at the API and frontends levels.(See #12, item 1). Updated docs and tests accordingly.
palgarvio
parents:
58
diff
changeset
|
115 |
105
abd3a594dab4
Implement wrapping of header comments in PO(T) output. Related to #14.
cmlenz
parents:
82
diff
changeset
|
116 def test_wrap_long_lines_in_header(self): |
abd3a594dab4
Implement wrapping of header comments in PO(T) output. Related to #14.
cmlenz
parents:
82
diff
changeset
|
117 """ |
abd3a594dab4
Implement wrapping of header comments in PO(T) output. Related to #14.
cmlenz
parents:
82
diff
changeset
|
118 Verify that long lines in the header comment are wrapped correctly. |
abd3a594dab4
Implement wrapping of header comments in PO(T) output. Related to #14.
cmlenz
parents:
82
diff
changeset
|
119 """ |
106
2a00e352c986
Merged `write_pot` and `write_po` functions by moving more functionality to the `Catalog` class. This is certainly not perfect yet, but moves us in the right direction.
cmlenz
parents:
105
diff
changeset
|
120 catalog = Catalog(project='AReallyReallyLongNameForAProject', |
2a00e352c986
Merged `write_pot` and `write_po` functions by moving more functionality to the `Catalog` class. This is certainly not perfect yet, but moves us in the right direction.
cmlenz
parents:
105
diff
changeset
|
121 revision_date=datetime(2007, 4, 1)) |
105
abd3a594dab4
Implement wrapping of header comments in PO(T) output. Related to #14.
cmlenz
parents:
82
diff
changeset
|
122 buf = StringIO() |
106
2a00e352c986
Merged `write_pot` and `write_po` functions by moving more functionality to the `Catalog` class. This is certainly not perfect yet, but moves us in the right direction.
cmlenz
parents:
105
diff
changeset
|
123 pofile.write_po(buf, catalog) |
105
abd3a594dab4
Implement wrapping of header comments in PO(T) output. Related to #14.
cmlenz
parents:
82
diff
changeset
|
124 self.assertEqual('''\ |
abd3a594dab4
Implement wrapping of header comments in PO(T) output. Related to #14.
cmlenz
parents:
82
diff
changeset
|
125 # Translations template for AReallyReallyLongNameForAProject. |
abd3a594dab4
Implement wrapping of header comments in PO(T) output. Related to #14.
cmlenz
parents:
82
diff
changeset
|
126 # Copyright (C) 2007 ORGANIZATION |
abd3a594dab4
Implement wrapping of header comments in PO(T) output. Related to #14.
cmlenz
parents:
82
diff
changeset
|
127 # This file is distributed under the same license as the |
abd3a594dab4
Implement wrapping of header comments in PO(T) output. Related to #14.
cmlenz
parents:
82
diff
changeset
|
128 # AReallyReallyLongNameForAProject project. |
106
2a00e352c986
Merged `write_pot` and `write_po` functions by moving more functionality to the `Catalog` class. This is certainly not perfect yet, but moves us in the right direction.
cmlenz
parents:
105
diff
changeset
|
129 # FIRST AUTHOR <EMAIL@ADDRESS>, 2007. |
105
abd3a594dab4
Implement wrapping of header comments in PO(T) output. Related to #14.
cmlenz
parents:
82
diff
changeset
|
130 # |
abd3a594dab4
Implement wrapping of header comments in PO(T) output. Related to #14.
cmlenz
parents:
82
diff
changeset
|
131 #, fuzzy''', '\n'.join(buf.getvalue().splitlines()[:7])) |
abd3a594dab4
Implement wrapping of header comments in PO(T) output. Related to #14.
cmlenz
parents:
82
diff
changeset
|
132 |
82
f421e5576d26
Added support for translator comments at the API and frontends levels.(See #12, item 1). Updated docs and tests accordingly.
palgarvio
parents:
58
diff
changeset
|
133 def test_pot_with_translator_comments(self): |
f421e5576d26
Added support for translator comments at the API and frontends levels.(See #12, item 1). Updated docs and tests accordingly.
palgarvio
parents:
58
diff
changeset
|
134 catalog = Catalog() |
f421e5576d26
Added support for translator comments at the API and frontends levels.(See #12, item 1). Updated docs and tests accordingly.
palgarvio
parents:
58
diff
changeset
|
135 catalog.add(u'foo', locations=[('main.py', 1)], |
107
4b42e23644e5
`Message`, `read_po` and `write_po` now all handle user/auto comments correctly.
palgarvio
parents:
106
diff
changeset
|
136 auto_comments=['Comment About `foo`']) |
82
f421e5576d26
Added support for translator comments at the API and frontends levels.(See #12, item 1). Updated docs and tests accordingly.
palgarvio
parents:
58
diff
changeset
|
137 catalog.add(u'bar', locations=[('utils.py', 3)], |
107
4b42e23644e5
`Message`, `read_po` and `write_po` now all handle user/auto comments correctly.
palgarvio
parents:
106
diff
changeset
|
138 user_comments=['Comment About `bar` with', |
4b42e23644e5
`Message`, `read_po` and `write_po` now all handle user/auto comments correctly.
palgarvio
parents:
106
diff
changeset
|
139 'multiple lines.']) |
82
f421e5576d26
Added support for translator comments at the API and frontends levels.(See #12, item 1). Updated docs and tests accordingly.
palgarvio
parents:
58
diff
changeset
|
140 buf = StringIO() |
106
2a00e352c986
Merged `write_pot` and `write_po` functions by moving more functionality to the `Catalog` class. This is certainly not perfect yet, but moves us in the right direction.
cmlenz
parents:
105
diff
changeset
|
141 pofile.write_po(buf, catalog, omit_header=True) |
82
f421e5576d26
Added support for translator comments at the API and frontends levels.(See #12, item 1). Updated docs and tests accordingly.
palgarvio
parents:
58
diff
changeset
|
142 self.assertEqual('''#. Comment About `foo` |
f421e5576d26
Added support for translator comments at the API and frontends levels.(See #12, item 1). Updated docs and tests accordingly.
palgarvio
parents:
58
diff
changeset
|
143 #: main.py:1 |
f421e5576d26
Added support for translator comments at the API and frontends levels.(See #12, item 1). Updated docs and tests accordingly.
palgarvio
parents:
58
diff
changeset
|
144 msgid "foo" |
f421e5576d26
Added support for translator comments at the API and frontends levels.(See #12, item 1). Updated docs and tests accordingly.
palgarvio
parents:
58
diff
changeset
|
145 msgstr "" |
f421e5576d26
Added support for translator comments at the API and frontends levels.(See #12, item 1). Updated docs and tests accordingly.
palgarvio
parents:
58
diff
changeset
|
146 |
107
4b42e23644e5
`Message`, `read_po` and `write_po` now all handle user/auto comments correctly.
palgarvio
parents:
106
diff
changeset
|
147 # Comment About `bar` with |
4b42e23644e5
`Message`, `read_po` and `write_po` now all handle user/auto comments correctly.
palgarvio
parents:
106
diff
changeset
|
148 # multiple lines. |
82
f421e5576d26
Added support for translator comments at the API and frontends levels.(See #12, item 1). Updated docs and tests accordingly.
palgarvio
parents:
58
diff
changeset
|
149 #: utils.py:3 |
f421e5576d26
Added support for translator comments at the API and frontends levels.(See #12, item 1). Updated docs and tests accordingly.
palgarvio
parents:
58
diff
changeset
|
150 msgid "bar" |
f421e5576d26
Added support for translator comments at the API and frontends levels.(See #12, item 1). Updated docs and tests accordingly.
palgarvio
parents:
58
diff
changeset
|
151 msgstr ""''', buf.getvalue().strip()) |
26
93eaa2f4a0a2
Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents:
19
diff
changeset
|
152 |
192
8f5805197198
Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents:
183
diff
changeset
|
153 def test_po_with_obsolete_message(self): |
183
e927dffc9ab4
The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents:
177
diff
changeset
|
154 catalog = Catalog() |
e927dffc9ab4
The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents:
177
diff
changeset
|
155 catalog.add(u'foo', u'Voh', locations=[('main.py', 1)]) |
e927dffc9ab4
The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents:
177
diff
changeset
|
156 catalog.obsolete['bar'] = Message(u'bar', u'Bahr', |
e927dffc9ab4
The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents:
177
diff
changeset
|
157 locations=[('utils.py', 3)], |
e927dffc9ab4
The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents:
177
diff
changeset
|
158 user_comments=['User comment']) |
e927dffc9ab4
The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents:
177
diff
changeset
|
159 buf = StringIO() |
e927dffc9ab4
The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents:
177
diff
changeset
|
160 pofile.write_po(buf, catalog, omit_header=True) |
e927dffc9ab4
The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents:
177
diff
changeset
|
161 self.assertEqual('''#: main.py:1 |
e927dffc9ab4
The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents:
177
diff
changeset
|
162 msgid "foo" |
e927dffc9ab4
The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents:
177
diff
changeset
|
163 msgstr "Voh" |
e927dffc9ab4
The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents:
177
diff
changeset
|
164 |
e927dffc9ab4
The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents:
177
diff
changeset
|
165 # User comment |
e927dffc9ab4
The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents:
177
diff
changeset
|
166 #~ msgid "bar" |
e927dffc9ab4
The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents:
177
diff
changeset
|
167 #~ msgstr "Bahr"''', buf.getvalue().strip()) |
e927dffc9ab4
The frontends now provide ways to update existing translations catalogs from a template. Closes #22.
cmlenz
parents:
177
diff
changeset
|
168 |
192
8f5805197198
Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents:
183
diff
changeset
|
169 def test_po_with_multiline_obsolete_message(self): |
8f5805197198
Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents:
183
diff
changeset
|
170 catalog = Catalog() |
8f5805197198
Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents:
183
diff
changeset
|
171 catalog.add(u'foo', u'Voh', locations=[('main.py', 1)]) |
8f5805197198
Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents:
183
diff
changeset
|
172 msgid = r"""Here's a message that covers |
8f5805197198
Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents:
183
diff
changeset
|
173 multiple lines, and should still be handled |
8f5805197198
Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents:
183
diff
changeset
|
174 correctly. |
8f5805197198
Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents:
183
diff
changeset
|
175 """ |
8f5805197198
Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents:
183
diff
changeset
|
176 msgstr = r"""Here's a message that covers |
8f5805197198
Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents:
183
diff
changeset
|
177 multiple lines, and should still be handled |
8f5805197198
Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents:
183
diff
changeset
|
178 correctly. |
8f5805197198
Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents:
183
diff
changeset
|
179 """ |
8f5805197198
Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents:
183
diff
changeset
|
180 catalog.obsolete[msgid] = Message(msgid, msgstr, |
8f5805197198
Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents:
183
diff
changeset
|
181 locations=[('utils.py', 3)]) |
8f5805197198
Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents:
183
diff
changeset
|
182 buf = StringIO() |
8f5805197198
Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents:
183
diff
changeset
|
183 pofile.write_po(buf, catalog, omit_header=True) |
8f5805197198
Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents:
183
diff
changeset
|
184 self.assertEqual(r'''#: main.py:1 |
8f5805197198
Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents:
183
diff
changeset
|
185 msgid "foo" |
8f5805197198
Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents:
183
diff
changeset
|
186 msgstr "Voh" |
8f5805197198
Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents:
183
diff
changeset
|
187 |
8f5805197198
Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents:
183
diff
changeset
|
188 #~ msgid "" |
8f5805197198
Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents:
183
diff
changeset
|
189 #~ "Here's a message that covers\n" |
8f5805197198
Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents:
183
diff
changeset
|
190 #~ "multiple lines, and should still be handled\n" |
8f5805197198
Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents:
183
diff
changeset
|
191 #~ "correctly.\n" |
8f5805197198
Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents:
183
diff
changeset
|
192 #~ msgstr "" |
8f5805197198
Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents:
183
diff
changeset
|
193 #~ "Here's a message that covers\n" |
8f5805197198
Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents:
183
diff
changeset
|
194 #~ "multiple lines, and should still be handled\n" |
8f5805197198
Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents:
183
diff
changeset
|
195 #~ "correctly.\n"''', buf.getvalue().strip()) |
8f5805197198
Correctly write out obsolete messages spanning multiple lines. Fixes #33.
cmlenz
parents:
183
diff
changeset
|
196 |
193
b5e58a22ebd2
Add an option to the frontend commands for catalog updating that removes completely any obsolete messages, instead of putting them comments.
cmlenz
parents:
192
diff
changeset
|
197 def test_po_with_obsolete_message_ignored(self): |
b5e58a22ebd2
Add an option to the frontend commands for catalog updating that removes completely any obsolete messages, instead of putting them comments.
cmlenz
parents:
192
diff
changeset
|
198 catalog = Catalog() |
b5e58a22ebd2
Add an option to the frontend commands for catalog updating that removes completely any obsolete messages, instead of putting them comments.
cmlenz
parents:
192
diff
changeset
|
199 catalog.add(u'foo', u'Voh', locations=[('main.py', 1)]) |
b5e58a22ebd2
Add an option to the frontend commands for catalog updating that removes completely any obsolete messages, instead of putting them comments.
cmlenz
parents:
192
diff
changeset
|
200 catalog.obsolete['bar'] = Message(u'bar', u'Bahr', |
b5e58a22ebd2
Add an option to the frontend commands for catalog updating that removes completely any obsolete messages, instead of putting them comments.
cmlenz
parents:
192
diff
changeset
|
201 locations=[('utils.py', 3)], |
b5e58a22ebd2
Add an option to the frontend commands for catalog updating that removes completely any obsolete messages, instead of putting them comments.
cmlenz
parents:
192
diff
changeset
|
202 user_comments=['User comment']) |
b5e58a22ebd2
Add an option to the frontend commands for catalog updating that removes completely any obsolete messages, instead of putting them comments.
cmlenz
parents:
192
diff
changeset
|
203 buf = StringIO() |
b5e58a22ebd2
Add an option to the frontend commands for catalog updating that removes completely any obsolete messages, instead of putting them comments.
cmlenz
parents:
192
diff
changeset
|
204 pofile.write_po(buf, catalog, omit_header=True, ignore_obsolete=True) |
b5e58a22ebd2
Add an option to the frontend commands for catalog updating that removes completely any obsolete messages, instead of putting them comments.
cmlenz
parents:
192
diff
changeset
|
205 self.assertEqual('''#: main.py:1 |
b5e58a22ebd2
Add an option to the frontend commands for catalog updating that removes completely any obsolete messages, instead of putting them comments.
cmlenz
parents:
192
diff
changeset
|
206 msgid "foo" |
b5e58a22ebd2
Add an option to the frontend commands for catalog updating that removes completely any obsolete messages, instead of putting them comments.
cmlenz
parents:
192
diff
changeset
|
207 msgstr "Voh"''', buf.getvalue().strip()) |
b5e58a22ebd2
Add an option to the frontend commands for catalog updating that removes completely any obsolete messages, instead of putting them comments.
cmlenz
parents:
192
diff
changeset
|
208 |
26
93eaa2f4a0a2
Reimplement line wrapping for PO writing (as the `textwrap` module is too destructive with white space) and move it to the `normalize` function (which was already doing some handling of line breaks).
cmlenz
parents:
19
diff
changeset
|
209 |
3 | 210 def suite(): |
211 suite = unittest.TestSuite() | |
212 suite.addTest(doctest.DocTestSuite(pofile)) | |
108
8ea225f33f28
Fix for #16: the header message (`msgid = ""`) is now treated specially by `read_po` and `Catalog`.
cmlenz
parents:
107
diff
changeset
|
213 suite.addTest(unittest.makeSuite(ReadPoTestCase)) |
106
2a00e352c986
Merged `write_pot` and `write_po` functions by moving more functionality to the `Catalog` class. This is certainly not perfect yet, but moves us in the right direction.
cmlenz
parents:
105
diff
changeset
|
214 suite.addTest(unittest.makeSuite(WritePoTestCase)) |
3 | 215 return suite |
216 | |
217 if __name__ == '__main__': | |
218 unittest.main(defaultTest='suite') |