~bzr-pqm/bzr/bzr.dev

6282.3.1 by Vincent Ladeuil
First cut at a working plugin to avoid conflicts in .po files by shelling out to msgmerge.
1
# Copyright (C) 2011 Canonical Ltd
2
#
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.
7
#
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.
12
#
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
16
6379.6.1 by Jelmer Vernooij
Import absolute_import in a few places.
17
from __future__ import absolute_import
18
6282.3.1 by Vincent Ladeuil
First cut at a working plugin to avoid conflicts in .po files by shelling out to msgmerge.
19
__doc__ = """Merge hook for ``.po`` files.
20
21
To enable this plugin, add a section to your branch.conf or location.conf
22
like::
23
24
    [/home/user/code/bzr]
6282.3.5 by Vincent Ladeuil
Update the doc.
25
    po_merge.pot_dirs = po,doc/po4a/po
26
27
The ``po_merge.pot_dirs`` config option takes a list of directories that can
28
contain ``.po`` files, separated by commas (if several directories are
29
needed). Each directory should contain a single ``.pot`` file.
6282.3.1 by Vincent Ladeuil
First cut at a working plugin to avoid conflicts in .po files by shelling out to msgmerge.
30
31
The ``po_merge.command`` is the command whose output is used as the result of
32
the merge. It defaults to::
33
34
   msgmerge -N "{other}" "{pot_file}" -C "{this}" -o "{result}"
35
36
where:
37
38
* ``this`` is the ``.po`` file content before the merge in the current branch,
39
* ``other`` is the ``.po`` file content in the branch merged from,
40
* ``pot_file`` is the path to the ``.pot`` file corresponding to the ``.po``
41
  file being merged.
42
6282.3.5 by Vincent Ladeuil
Update the doc.
43
If conflicts occur in a ``.pot`` file during a given merge, the ``.po`` files
44
will use the ``.pot`` file present in tree before the merge. If this doesn't
45
suit your needs, you should can disable the plugin during the merge with::
46
47
  bzr merge <usual merge args> -Opo_merge.po_dirs=
48
49
This will allow you to resolve the conflicts in the ``.pot`` file and then
50
merge the ``.po`` files again with::
51
52
  bzr remerge po/*.po doc/po4a/po/*.po
53
6282.3.1 by Vincent Ladeuil
First cut at a working plugin to avoid conflicts in .po files by shelling out to msgmerge.
54
"""
55
6282.3.13 by Vincent Ladeuil
Register the options earlier so 'bzr help po_merge.pot_dirs' can be used.
56
from bzrlib import (
57
    config,
58
    # Since we are a built-in plugin we share the bzrlib version
59
    version_info,
60
    )
6282.3.1 by Vincent Ladeuil
First cut at a working plugin to avoid conflicts in .po files by shelling out to msgmerge.
61
from bzrlib.hooks import install_lazy_named_hook
62
63
6282.3.14 by Vincent Ladeuil
Use lazy registration for plugin options to set a good example.
64
def register_lazy_option(key, member):
65
    config.option_registry.register_lazy(
66
        key, 'bzrlib.plugins.po_merge.po_merge', member)
67
68
69
register_lazy_option('po_merge.command', 'command_option')
70
register_lazy_option('po_merge.po_dirs', 'po_dirs_option')
71
register_lazy_option('po_merge.po_glob', 'po_glob_option')
72
register_lazy_option('po_merge.pot_glob', 'pot_glob_option')
6282.3.13 by Vincent Ladeuil
Register the options earlier so 'bzr help po_merge.pot_dirs' can be used.
73
74
6282.3.1 by Vincent Ladeuil
First cut at a working plugin to avoid conflicts in .po files by shelling out to msgmerge.
75
def po_merge_hook(merger):
6391.1.1 by Benjamin Peterson
fix copy and paste error
76
    """Merger.merge_file_content hook for po files."""
6282.3.1 by Vincent Ladeuil
First cut at a working plugin to avoid conflicts in .po files by shelling out to msgmerge.
77
    from bzrlib.plugins.po_merge.po_merge import PoMerger
78
    return PoMerger(merger)
79
80
81
install_lazy_named_hook("bzrlib.merge", "Merger.hooks", "merge_file_content",
82
    po_merge_hook, ".po file merge")
83
84
85
def load_tests(basic_tests, module, loader):
86
    testmod_names = [
87
        'tests',
88
        ]
89
    basic_tests.addTest(loader.loadTestsFromModuleNames(
90
            ["%s.%s" % (__name__, tmn) for tmn in testmod_names]))
91
    return basic_tests
92