##// END OF EJS Templates
scripts/i18n: tweak messages
Mads Kiilerich -
r8204:80ffe0f2 default
parent child Browse files
Show More
@@ -1,140 +1,140 b''
1 #!/usr/bin/env python3
1 #!/usr/bin/env python3
2
2
3 # -*- coding: utf-8 -*-
3 # -*- coding: utf-8 -*-
4 # This program is free software: you can redistribute it and/or modify
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
7 # (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
16
17 import os
17 import os
18 import shutil
18 import shutil
19 import sys
19 import sys
20
20
21 import click
21 import click
22
22
23 import i18n_utils
23 import i18n_utils
24
24
25
25
26 """
26 """
27 Tool for maintenance of .po and .pot files
27 Tool for maintenance of .po and .pot files
28
28
29 Normally, the i18n-related files contain for each translatable string a
29 Normally, the i18n-related files contain for each translatable string a
30 reference to all the source code locations where this string is found. This
30 reference to all the source code locations where this string is found. This
31 meta data is useful for translators to assess how strings are used, but is not
31 meta data is useful for translators to assess how strings are used, but is not
32 relevant for normal development nor for running Kallithea. Such meta data, or
32 relevant for normal development nor for running Kallithea. Such meta data, or
33 derived data like kallithea.pot, will inherently be outdated, and create
33 derived data like kallithea.pot, will inherently be outdated, and create
34 unnecessary churn and repository growth, making it harder to spot actual and
34 unnecessary churn and repository growth, making it harder to spot actual and
35 important changes.
35 important changes.
36 """
36 """
37
37
38 @click.group()
38 @click.group()
39 @click.option('--debug/--no-debug', default=False)
39 @click.option('--debug/--no-debug', default=False)
40 def cli(debug):
40 def cli(debug):
41 if (debug):
41 if (debug):
42 i18n_utils.do_debug = True
42 i18n_utils.do_debug = True
43 pass
43 pass
44
44
45 @cli.command()
45 @cli.command()
46 @click.argument('po_files', nargs=-1)
46 @click.argument('po_files', nargs=-1)
47 @click.option('--merge-pot-file', default=None)
47 @click.option('--merge-pot-file', default=None)
48 @click.option('--strip/--no-strip', default=False)
48 @click.option('--strip/--no-strip', default=False)
49 def normalize_po_files(po_files, merge_pot_file, strip):
49 def normalize_po_files(po_files, merge_pot_file, strip):
50 """Normalize the specified .po and .pot files.
50 """Normalize the specified .po and .pot files.
51
51
52 By default, only actual translations and essential headers will be
52 By default, only actual translations and essential headers will be
53 preserved, just as we want it in the main branches with minimal noise.
53 preserved, just as we want it in the main branches with minimal noise.
54
54
55 If a .pot file is specified, the po files will instead be updated by
55 If a .pot file is specified, the po files will instead be updated by
56 running GNU msgmerge with this .pot file, thus updating source code
56 running GNU msgmerge with this .pot file, thus updating source code
57 references and preserving comments and outdated translations.
57 references and preserving comments and outdated translations.
58 """
58 """
59 for po_file in po_files:
59 for po_file in po_files:
60 i18n_utils._normalize_po_file(po_file, merge_pot_file=merge_pot_file, strip=strip)
60 i18n_utils._normalize_po_file(po_file, merge_pot_file=merge_pot_file, strip=strip)
61
61
62 @cli.command()
62 @cli.command()
63 @click.argument('local')
63 @click.argument('local')
64 @click.argument('base')
64 @click.argument('base')
65 @click.argument('other')
65 @click.argument('other')
66 @click.argument('output')
66 @click.argument('output')
67 @click.option('--merge-pot-file', default=None)
67 @click.option('--merge-pot-file', default=None)
68 @click.option('--strip/--no-strip', default=False)
68 @click.option('--strip/--no-strip', default=False)
69 def normalized_merge(local, base, other, output, merge_pot_file, strip):
69 def normalized_merge(local, base, other, output, merge_pot_file, strip):
70 """Merge tool for use with 'hg merge/rebase/graft --tool'
70 """Merge tool for use with 'hg merge/rebase/graft --tool'
71
71
72 i18n files are partially manually editored original source of content, and
72 i18n files are partially manually editored original source of content, and
73 partially automatically generated and updated. That create a lot of churn
73 partially automatically generated and updated. That create a lot of churn
74 and often cause a lot of merge conflicts.
74 and often cause a lot of merge conflicts.
75
75
76 To avoid that, this merge tool wrapper will normalize .po content before
76 To avoid that, this merge tool wrapper will normalize .po content before
77 running the merge tool.
77 running the merge tool.
78
78
79 By default, only actual translations and essential headers will be
79 By default, only actual translations and essential headers will be
80 preserved, just as we want it in the main branches with minimal noise.
80 preserved, just as we want it in the main branches with minimal noise.
81
81
82 If a .pot file is specified, the po files will instead be updated by
82 If a .pot file is specified, the po files will instead be updated by
83 running GNU msgmerge with this .pot file, thus updating source code
83 running GNU msgmerge with this .pot file, thus updating source code
84 references and preserving comments and outdated translations.
84 references and preserving comments and outdated translations.
85
85
86 Add the following to your user or repository-specific .hgrc file to use it:
86 Add the following to your user or repository-specific .hgrc file to use it:
87 [merge-tools]
87 [merge-tools]
88 i18n.executable = /path/to/scripts/i18n
88 i18n.executable = /path/to/scripts/i18n
89 i18n.args = normalized-merge $local $base $other $output
89 i18n.args = normalized-merge $local $base $other $output
90
90
91 and then invoke merge/rebase/graft with the additional argument '--tool i18n'.
91 and then invoke merge/rebase/graft with the additional argument '--tool i18n'.
92 """
92 """
93 from mercurial import (
93 from mercurial import (
94 context,
94 context,
95 simplemerge,
95 simplemerge,
96 ui as uimod,
96 ui as uimod,
97 )
97 )
98
98
99 print('i18n normalized-merge: merging file %s' % output)
99 print('i18n normalized-merge: normalizing and merging %s' % output)
100
100
101 i18n_utils._normalize_po_file(local, merge_pot_file=merge_pot_file, strip=strip)
101 i18n_utils._normalize_po_file(local, merge_pot_file=merge_pot_file, strip=strip)
102 i18n_utils._normalize_po_file(base, merge_pot_file=merge_pot_file, strip=strip)
102 i18n_utils._normalize_po_file(base, merge_pot_file=merge_pot_file, strip=strip)
103 i18n_utils._normalize_po_file(other, merge_pot_file=merge_pot_file, strip=strip)
103 i18n_utils._normalize_po_file(other, merge_pot_file=merge_pot_file, strip=strip)
104 i18n_utils._normalize_po_file(output, merge_pot_file=merge_pot_file, strip=strip)
104 i18n_utils._normalize_po_file(output, merge_pot_file=merge_pot_file, strip=strip)
105
105
106 # simplemerge will write markers to 'local' if it fails, keep a copy without markers
106 # simplemerge will write markers to 'local' if it fails, keep a copy without markers
107 localkeep = local + '.keep'
107 localkeep = local + '.keep'
108 shutil.copyfile(local, localkeep)
108 shutil.copyfile(local, localkeep)
109
109
110 ret = simplemerge.simplemerge(uimod.ui.load(),
110 ret = simplemerge.simplemerge(uimod.ui.load(),
111 context.arbitraryfilectx(local.encode('utf-8')),
111 context.arbitraryfilectx(local.encode('utf-8')),
112 context.arbitraryfilectx(base.encode('utf-8')),
112 context.arbitraryfilectx(base.encode('utf-8')),
113 context.arbitraryfilectx(other.encode('utf-8')),
113 context.arbitraryfilectx(other.encode('utf-8')),
114 label=[b'local', b'other', b'base'],
114 label=[b'local', b'other', b'base'],
115 mode='merge',
115 mode='merge',
116 )
116 )
117 shutil.copyfile(local, output) # simplemerge wrote to local - either resolved or with conflict markers
117 shutil.copyfile(local, output) # simplemerge wrote to local - either resolved or with conflict markers
118 if ret:
118 if ret:
119 shutil.copyfile(localkeep, local)
119 shutil.copyfile(localkeep, local)
120 basekeep = base + '.keep'
120 basekeep = base + '.keep'
121 otherkeep = other + '.keep'
121 otherkeep = other + '.keep'
122 shutil.copyfile(base, basekeep)
122 shutil.copyfile(base, basekeep)
123 shutil.copyfile(other, otherkeep)
123 shutil.copyfile(other, otherkeep)
124 sys.stderr.write("Error: simple merge failed and %s is left with conflict markers. Resolve the conflics , then use 'hg resolve -m'.\n" % output)
124 sys.stderr.write("Error: simple merge failed and %s is left with conflict markers. Resolve the conflicts, then use 'hg resolve -m'.\n" % output)
125 sys.stderr.write('Resolve with e.g.: kdiff3 %s %s %s -o %s\n' % (basekeep, localkeep, otherkeep, output))
125 sys.stderr.write('Resolve with e.g.: kdiff3 %s %s %s -o %s\n' % (basekeep, localkeep, otherkeep, output))
126 sys.exit(ret)
126 sys.exit(ret)
127
127
128 os.remove(localkeep)
128 os.remove(localkeep)
129
129
130 @cli.command()
130 @cli.command()
131 @click.argument('file1')
131 @click.argument('file1')
132 @click.argument('file2')
132 @click.argument('file2')
133 @click.option('--merge-pot-file', default=None)
133 @click.option('--merge-pot-file', default=None)
134 @click.option('--strip/--no-strip', default=False)
134 @click.option('--strip/--no-strip', default=False)
135 def normalized_diff(file1, file2, merge_pot_file, strip):
135 def normalized_diff(file1, file2, merge_pot_file, strip):
136 """Compare two files while transparently normalizing them."""
136 """Compare two files while transparently normalizing them."""
137 sys.exit(i18n_utils._normalized_diff(file1, file2, merge_pot_file=merge_pot_file, strip=strip))
137 sys.exit(i18n_utils._normalized_diff(file1, file2, merge_pot_file=merge_pot_file, strip=strip))
138
138
139 if __name__ == '__main__':
139 if __name__ == '__main__':
140 cli()
140 cli()
General Comments 0
You need to be logged in to leave comments. Login now