~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/plugins/po_merge/__init__.py

  • Committer: Martin Packman
  • Date: 2012-01-05 09:50:04 UTC
  • mfrom: (6424 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6426.
  • Revision ID: martin.packman@canonical.com-20120105095004-mia9xb7y0efmto0v
Merge bzr.dev to resolve conflicts in bzrlib.builtins

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
17
from __future__ import absolute_import
 
18
 
 
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]
 
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.
 
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
 
 
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
 
 
54
"""
 
55
 
 
56
from bzrlib import (
 
57
    config,
 
58
    # Since we are a built-in plugin we share the bzrlib version
 
59
    version_info,
 
60
    )
 
61
from bzrlib.hooks import install_lazy_named_hook
 
62
 
 
63
 
 
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')
 
73
 
 
74
 
 
75
def po_merge_hook(merger):
 
76
    """Merger.merge_file_content hook for po files."""
 
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