1
# Copyright (C) 2011 Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
__doc__ = """Merge hook for ``.po`` files.
19
To enable this plugin, add a section to your branch.conf or location.conf
23
po_merge.pot_dirs = po,doc/po4a/po
25
The ``po_merge.pot_dirs`` config option takes a list of directories that can
26
contain ``.po`` files, separated by commas (if several directories are
27
needed). Each directory should contain a single ``.pot`` file.
29
The ``po_merge.command`` is the command whose output is used as the result of
30
the merge. It defaults to::
32
msgmerge -N "{other}" "{pot_file}" -C "{this}" -o "{result}"
36
* ``this`` is the ``.po`` file content before the merge in the current branch,
37
* ``other`` is the ``.po`` file content in the branch merged from,
38
* ``pot_file`` is the path to the ``.pot`` file corresponding to the ``.po``
41
If conflicts occur in a ``.pot`` file during a given merge, the ``.po`` files
42
will use the ``.pot`` file present in tree before the merge. If this doesn't
43
suit your needs, you should can disable the plugin during the merge with::
45
bzr merge <usual merge args> -Opo_merge.po_dirs=
47
This will allow you to resolve the conflicts in the ``.pot`` file and then
48
merge the ``.po`` files again with::
50
bzr remerge po/*.po doc/po4a/po/*.po
56
# Since we are a built-in plugin we share the bzrlib version
59
from bzrlib.hooks import install_lazy_named_hook
62
config.option_registry.register(config.Option(
64
default='msgmerge -N "{other}" "{pot_file}" -C "{this}" -o "{result}"',
66
Command used to create a conflict-free .po file during merge.
68
The following parameters are provided by the hook:
69
``this`` is the ``.po`` file content before the merge in the current branch,
70
``other`` is the ``.po`` file content in the branch merged from,
71
``pot_file`` is the path to the ``.pot`` file corresponding to the ``.po``
73
``result`` is the path where ``msgmerge`` will output its result. The hook will
74
use the content of this file to produce the resulting ``.po`` file.
76
The command is invoked at the root of the working tree so all paths are
81
config.option_registry.register(config.Option(
82
'po_merge.po_dirs', default='po,debian/po',
83
from_unicode=config.list_from_store,
84
help='List of dirs containing .po files that the hook applies to.'))
87
config.option_registry.register(config.Option(
88
'po_merge.po_glob', default='*.po',
89
help='Glob matching all ``.po`` files in one of ``po_merge.po_dirs``.'))
91
config.option_registry.register(config.Option(
92
'po_merge.pot_glob', default='*.pot',
93
help='Glob matching the ``.pot`` file in one of ``po_merge.po_dirs``.'))
96
def po_merge_hook(merger):
97
"""Merger.merge_file_content hook for bzr-format NEWS files."""
98
from bzrlib.plugins.po_merge.po_merge import PoMerger
99
return PoMerger(merger)
102
install_lazy_named_hook("bzrlib.merge", "Merger.hooks", "merge_file_content",
103
po_merge_hook, ".po file merge")
106
def load_tests(basic_tests, module, loader):
110
basic_tests.addTest(loader.loadTestsFromModuleNames(
111
["%s.%s" % (__name__, tmn) for tmn in testmod_names]))