annotate src/po/check.vim @ 32509:ec4e725ab8cd v9.0.1586

patch 9.0.1586: error for using two messages with ngettext() differing in "%" Commit: https://github.com/vim/vim/commit/78ee62563ea940086f094150f0356e38f780c580 Author: Bram Moolenaar <Bram@vim.org> Date: Sun May 28 18:39:55 2023 +0100 patch 9.0.1586: error for using two messages with ngettext() differing in "%" Problem: Checking translations gives an error for using two messages with ngettext() that differ in "%" items. Solution: Adjust the check script to tolerate omitting one "%" item.
author Bram Moolenaar <Bram@vim.org>
date Sun, 28 May 2023 19:45:04 +0200
parents 7fb63ad3a9ab
children 448aef880252
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
461
f98374445f66 updated for version 7.0123
vimboss
parents:
diff changeset
1 " Vim script for checking .po files.
f98374445f66 updated for version 7.0123
vimboss
parents:
diff changeset
2 "
1599
2f016b638c0c updated for version 7.1-312
vimboss
parents: 557
diff changeset
3 " Go through the file and verify that:
2f016b638c0c updated for version 7.1-312
vimboss
parents: 557
diff changeset
4 " - All %...s items in "msgid" are identical to the ones in "msgstr".
2f016b638c0c updated for version 7.1-312
vimboss
parents: 557
diff changeset
5 " - An error or warning code in "msgid" matches the one in "msgstr".
461
f98374445f66 updated for version 7.0123
vimboss
parents:
diff changeset
6
f98374445f66 updated for version 7.0123
vimboss
parents:
diff changeset
7 if 1 " Only execute this if the eval feature is available.
f98374445f66 updated for version 7.0123
vimboss
parents:
diff changeset
8
32509
ec4e725ab8cd patch 9.0.1586: error for using two messages with ngettext() differing in "%"
Bram Moolenaar <Bram@vim.org>
parents: 28958
diff changeset
9 " using line continuation
ec4e725ab8cd patch 9.0.1586: error for using two messages with ngettext() differing in "%"
Bram Moolenaar <Bram@vim.org>
parents: 28958
diff changeset
10 set cpo&vim
ec4e725ab8cd patch 9.0.1586: error for using two messages with ngettext() differing in "%"
Bram Moolenaar <Bram@vim.org>
parents: 28958
diff changeset
11
461
f98374445f66 updated for version 7.0123
vimboss
parents:
diff changeset
12 " Function to get a split line at the cursor.
f98374445f66 updated for version 7.0123
vimboss
parents:
diff changeset
13 " Used for both msgid and msgstr lines.
f98374445f66 updated for version 7.0123
vimboss
parents:
diff changeset
14 " Removes all text except % items and returns the result.
f98374445f66 updated for version 7.0123
vimboss
parents:
diff changeset
15 func! GetMline()
f98374445f66 updated for version 7.0123
vimboss
parents:
diff changeset
16 let idline = substitute(getline('.'), '"\(.*\)"$', '\1', '')
f98374445f66 updated for version 7.0123
vimboss
parents:
diff changeset
17 while line('.') < line('$')
f98374445f66 updated for version 7.0123
vimboss
parents:
diff changeset
18 +
f98374445f66 updated for version 7.0123
vimboss
parents:
diff changeset
19 let line = getline('.')
f98374445f66 updated for version 7.0123
vimboss
parents:
diff changeset
20 if line[0] != '"'
f98374445f66 updated for version 7.0123
vimboss
parents:
diff changeset
21 break
f98374445f66 updated for version 7.0123
vimboss
parents:
diff changeset
22 endif
f98374445f66 updated for version 7.0123
vimboss
parents:
diff changeset
23 let idline .= substitute(line, '"\(.*\)"$', '\1', '')
f98374445f66 updated for version 7.0123
vimboss
parents:
diff changeset
24 endwhile
f98374445f66 updated for version 7.0123
vimboss
parents:
diff changeset
25
557
862863033fdd updated for version 7.0158
vimboss
parents: 461
diff changeset
26 " remove '%', not used for formatting.
862863033fdd updated for version 7.0158
vimboss
parents: 461
diff changeset
27 let idline = substitute(idline, "'%'", '', 'g')
21998
4d5081260d5a patch 8.2.1548: cannot move position of "%%" in message translations
Bram Moolenaar <Bram@vim.org>
parents: 18625
diff changeset
28 let idline = substitute(idline, "%%", '', 'g')
557
862863033fdd updated for version 7.0158
vimboss
parents: 461
diff changeset
29
1952
6ddd55ac6ce5 updated for version 7.2-249
vimboss
parents: 1599
diff changeset
30 " remove '%' used for plural forms.
6ddd55ac6ce5 updated for version 7.2-249
vimboss
parents: 1599
diff changeset
31 let idline = substitute(idline, '\\nPlural-Forms: .\+;\\n', '', '')
6ddd55ac6ce5 updated for version 7.2-249
vimboss
parents: 1599
diff changeset
32
461
f98374445f66 updated for version 7.0123
vimboss
parents:
diff changeset
33 " remove everything but % items.
f98374445f66 updated for version 7.0123
vimboss
parents:
diff changeset
34 return substitute(idline, '[^%]*\(%[-+ #''.0-9*]*l\=[dsuxXpoc%]\)\=', '\1', 'g')
f98374445f66 updated for version 7.0123
vimboss
parents:
diff changeset
35 endfunc
f98374445f66 updated for version 7.0123
vimboss
parents:
diff changeset
36
9963
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
37 " This only works when 'wrapscan' is not set.
2484
e037ee8698b3 Set 'wrapscan' when checking the .po files. (Mike Williams)
Bram Moolenaar <bram@vim.org>
parents: 1952
diff changeset
38 let s:save_wrapscan = &wrapscan
9963
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
39 set nowrapscan
2484
e037ee8698b3 Set 'wrapscan' when checking the .po files. (Mike Williams)
Bram Moolenaar <bram@vim.org>
parents: 1952
diff changeset
40
461
f98374445f66 updated for version 7.0123
vimboss
parents:
diff changeset
41 " Start at the first "msgid" line.
11702
48a95b916781 patch 8.0.0734: the script to check translations can be improved
Christian Brabandt <cb@256bit.org>
parents: 9963
diff changeset
42 let wsv = winsaveview()
461
f98374445f66 updated for version 7.0123
vimboss
parents:
diff changeset
43 1
28958
7fb63ad3a9ab patch 8.2.5001: checking translations affects the search pattern history
Bram Moolenaar <Bram@vim.org>
parents: 21998
diff changeset
44 keeppatterns /^msgid\>
9963
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
45
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
46 " When an error is detected this is set to the line number.
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
47 " Note: this is used in the Makefile.
461
f98374445f66 updated for version 7.0123
vimboss
parents:
diff changeset
48 let error = 0
f98374445f66 updated for version 7.0123
vimboss
parents:
diff changeset
49
f98374445f66 updated for version 7.0123
vimboss
parents:
diff changeset
50 while 1
18625
57927799c27e patch 8.1.2305: no warning for wrong entry in translations
Bram Moolenaar <Bram@vim.org>
parents: 14187
diff changeset
51 let lnum = line('.')
57927799c27e patch 8.1.2305: no warning for wrong entry in translations
Bram Moolenaar <Bram@vim.org>
parents: 14187
diff changeset
52 if getline(lnum) =~ 'msgid "Text;.*;"'
57927799c27e patch 8.1.2305: no warning for wrong entry in translations
Bram Moolenaar <Bram@vim.org>
parents: 14187
diff changeset
53 if getline(lnum + 1) !~ '^msgstr "\([^;]\+;\)\+"'
57927799c27e patch 8.1.2305: no warning for wrong entry in translations
Bram Moolenaar <Bram@vim.org>
parents: 14187
diff changeset
54 echomsg 'Mismatching ; in line ' . (lnum + 1)
57927799c27e patch 8.1.2305: no warning for wrong entry in translations
Bram Moolenaar <Bram@vim.org>
parents: 14187
diff changeset
55 echomsg 'Did you forget the trailing semicolon?'
57927799c27e patch 8.1.2305: no warning for wrong entry in translations
Bram Moolenaar <Bram@vim.org>
parents: 14187
diff changeset
56 if error == 0
57927799c27e patch 8.1.2305: no warning for wrong entry in translations
Bram Moolenaar <Bram@vim.org>
parents: 14187
diff changeset
57 let error = lnum + 1
57927799c27e patch 8.1.2305: no warning for wrong entry in translations
Bram Moolenaar <Bram@vim.org>
parents: 14187
diff changeset
58 endif
57927799c27e patch 8.1.2305: no warning for wrong entry in translations
Bram Moolenaar <Bram@vim.org>
parents: 14187
diff changeset
59 endif
57927799c27e patch 8.1.2305: no warning for wrong entry in translations
Bram Moolenaar <Bram@vim.org>
parents: 14187
diff changeset
60 endif
57927799c27e patch 8.1.2305: no warning for wrong entry in translations
Bram Moolenaar <Bram@vim.org>
parents: 14187
diff changeset
61
461
f98374445f66 updated for version 7.0123
vimboss
parents:
diff changeset
62 if getline(line('.') - 1) !~ "no-c-format"
9963
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
63 " go over the "msgid" and "msgid_plural" lines
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
64 let prevfromline = 'foobar'
32509
ec4e725ab8cd patch 9.0.1586: error for using two messages with ngettext() differing in "%"
Bram Moolenaar <Bram@vim.org>
parents: 28958
diff changeset
65 let plural = 0
9963
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
66 while 1
32509
ec4e725ab8cd patch 9.0.1586: error for using two messages with ngettext() differing in "%"
Bram Moolenaar <Bram@vim.org>
parents: 28958
diff changeset
67 if getline('.') =~ 'msgid_plural'
ec4e725ab8cd patch 9.0.1586: error for using two messages with ngettext() differing in "%"
Bram Moolenaar <Bram@vim.org>
parents: 28958
diff changeset
68 let plural += 1
ec4e725ab8cd patch 9.0.1586: error for using two messages with ngettext() differing in "%"
Bram Moolenaar <Bram@vim.org>
parents: 28958
diff changeset
69 endif
9963
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
70 let fromline = GetMline()
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
71 if prevfromline != 'foobar' && prevfromline != fromline
32509
ec4e725ab8cd patch 9.0.1586: error for using two messages with ngettext() differing in "%"
Bram Moolenaar <Bram@vim.org>
parents: 28958
diff changeset
72 \ && (plural != 1
ec4e725ab8cd patch 9.0.1586: error for using two messages with ngettext() differing in "%"
Bram Moolenaar <Bram@vim.org>
parents: 28958
diff changeset
73 \ || count(prevfromline, '%') + 1 != count(fromline, '%'))
9963
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
74 echomsg 'Mismatching % in line ' . (line('.') - 1)
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
75 echomsg 'msgid: ' . prevfromline
32509
ec4e725ab8cd patch 9.0.1586: error for using two messages with ngettext() differing in "%"
Bram Moolenaar <Bram@vim.org>
parents: 28958
diff changeset
76 echomsg 'msgid: ' . fromline
9963
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
77 if error == 0
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
78 let error = line('.')
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
79 endif
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
80 endif
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
81 if getline('.') !~ 'msgid_plural'
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
82 break
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
83 endif
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
84 let prevfromline = fromline
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
85 endwhile
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
86
461
f98374445f66 updated for version 7.0123
vimboss
parents:
diff changeset
87 if getline('.') !~ '^msgstr'
9963
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
88 echomsg 'Missing "msgstr" in line ' . line('.')
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
89 if error == 0
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
90 let error = line('.')
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
91 endif
461
f98374445f66 updated for version 7.0123
vimboss
parents:
diff changeset
92 endif
9963
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
93
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
94 " check all the 'msgstr' lines
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
95 while getline('.') =~ '^msgstr'
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
96 let toline = GetMline()
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
97 if fromline != toline
32509
ec4e725ab8cd patch 9.0.1586: error for using two messages with ngettext() differing in "%"
Bram Moolenaar <Bram@vim.org>
parents: 28958
diff changeset
98 \ && (plural == 0 || count(fromline, '%') != count(toline, '%') + 1)
9963
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
99 echomsg 'Mismatching % in line ' . (line('.') - 1)
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
100 echomsg 'msgid: ' . fromline
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
101 echomsg 'msgstr: ' . toline
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
102 if error == 0
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
103 let error = line('.')
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
104 endif
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
105 endif
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
106 if line('.') == line('$')
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
107 break
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
108 endif
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
109 endwhile
461
f98374445f66 updated for version 7.0123
vimboss
parents:
diff changeset
110 endif
f98374445f66 updated for version 7.0123
vimboss
parents:
diff changeset
111
9963
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
112 " Find next msgid. Quit when there is no more.
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
113 let lnum = line('.')
28958
7fb63ad3a9ab patch 8.2.5001: checking translations affects the search pattern history
Bram Moolenaar <Bram@vim.org>
parents: 21998
diff changeset
114 silent! keeppatterns /^msgid\>
9963
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
115 if line('.') == lnum
461
f98374445f66 updated for version 7.0123
vimboss
parents:
diff changeset
116 break
f98374445f66 updated for version 7.0123
vimboss
parents:
diff changeset
117 endif
f98374445f66 updated for version 7.0123
vimboss
parents:
diff changeset
118 endwhile
f98374445f66 updated for version 7.0123
vimboss
parents:
diff changeset
119
1599
2f016b638c0c updated for version 7.1-312
vimboss
parents: 557
diff changeset
120 " Check that error code in msgid matches the one in msgstr.
2f016b638c0c updated for version 7.1-312
vimboss
parents: 557
diff changeset
121 "
2f016b638c0c updated for version 7.1-312
vimboss
parents: 557
diff changeset
122 " Examples of mismatches found with msgid "E123: ..."
2f016b638c0c updated for version 7.1-312
vimboss
parents: 557
diff changeset
123 " - msgstr "E321: ..." error code mismatch
2f016b638c0c updated for version 7.1-312
vimboss
parents: 557
diff changeset
124 " - msgstr "W123: ..." warning instead of error
2f016b638c0c updated for version 7.1-312
vimboss
parents: 557
diff changeset
125 " - msgstr "E123 ..." missing colon
2f016b638c0c updated for version 7.1-312
vimboss
parents: 557
diff changeset
126 " - msgstr "..." missing error code
2f016b638c0c updated for version 7.1-312
vimboss
parents: 557
diff changeset
127 "
2f016b638c0c updated for version 7.1-312
vimboss
parents: 557
diff changeset
128 1
2f016b638c0c updated for version 7.1-312
vimboss
parents: 557
diff changeset
129 if search('msgid "\("\n"\)\?\([EW][0-9]\+:\).*\nmsgstr "\("\n"\)\?[^"]\@=\2\@!') > 0
9963
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
130 echomsg 'Mismatching error/warning code in line ' . line('.')
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
131 if error == 0
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
132 let error = line('.')
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
133 endif
1599
2f016b638c0c updated for version 7.1-312
vimboss
parents: 557
diff changeset
134 endif
2f016b638c0c updated for version 7.1-312
vimboss
parents: 557
diff changeset
135
11702
48a95b916781 patch 8.0.0734: the script to check translations can be improved
Christian Brabandt <cb@256bit.org>
parents: 9963
diff changeset
136 func! CountNl(first, last)
48a95b916781 patch 8.0.0734: the script to check translations can be improved
Christian Brabandt <cb@256bit.org>
parents: 9963
diff changeset
137 let nl = 0
48a95b916781 patch 8.0.0734: the script to check translations can be improved
Christian Brabandt <cb@256bit.org>
parents: 9963
diff changeset
138 for lnum in range(a:first, a:last)
11828
5a07a3ff56c1 patch 8.0.0794: checking translations fails with multiple NL
Christian Brabandt <cb@256bit.org>
parents: 11702
diff changeset
139 let nl += count(getline(lnum), "\n")
11702
48a95b916781 patch 8.0.0734: the script to check translations can be improved
Christian Brabandt <cb@256bit.org>
parents: 9963
diff changeset
140 endfor
48a95b916781 patch 8.0.0734: the script to check translations can be improved
Christian Brabandt <cb@256bit.org>
parents: 9963
diff changeset
141 return nl
48a95b916781 patch 8.0.0734: the script to check translations can be improved
Christian Brabandt <cb@256bit.org>
parents: 9963
diff changeset
142 endfunc
48a95b916781 patch 8.0.0734: the script to check translations can be improved
Christian Brabandt <cb@256bit.org>
parents: 9963
diff changeset
143
11828
5a07a3ff56c1 patch 8.0.0794: checking translations fails with multiple NL
Christian Brabandt <cb@256bit.org>
parents: 11702
diff changeset
144 " Check that the \n at the end of the msgid line is also present in the msgstr
11702
48a95b916781 patch 8.0.0734: the script to check translations can be improved
Christian Brabandt <cb@256bit.org>
parents: 9963
diff changeset
145 " line. Skip over the header.
13812
9d6cd12ae7bc patch 8.0.1778: script to check translations does not always work
Christian Brabandt <cb@256bit.org>
parents: 12756
diff changeset
146 1
28958
7fb63ad3a9ab patch 8.2.5001: checking translations affects the search pattern history
Bram Moolenaar <Bram@vim.org>
parents: 21998
diff changeset
147 keeppatterns /^"MIME-Version:
11702
48a95b916781 patch 8.0.0734: the script to check translations can be improved
Christian Brabandt <cb@256bit.org>
parents: 9963
diff changeset
148 while 1
48a95b916781 patch 8.0.0734: the script to check translations can be improved
Christian Brabandt <cb@256bit.org>
parents: 9963
diff changeset
149 let lnum = search('^msgid\>')
48a95b916781 patch 8.0.0734: the script to check translations can be improved
Christian Brabandt <cb@256bit.org>
parents: 9963
diff changeset
150 if lnum <= 0
48a95b916781 patch 8.0.0734: the script to check translations can be improved
Christian Brabandt <cb@256bit.org>
parents: 9963
diff changeset
151 break
48a95b916781 patch 8.0.0734: the script to check translations can be improved
Christian Brabandt <cb@256bit.org>
parents: 9963
diff changeset
152 endif
48a95b916781 patch 8.0.0734: the script to check translations can be improved
Christian Brabandt <cb@256bit.org>
parents: 9963
diff changeset
153 let strlnum = search('^msgstr\>')
48a95b916781 patch 8.0.0734: the script to check translations can be improved
Christian Brabandt <cb@256bit.org>
parents: 9963
diff changeset
154 let end = search('^$')
48a95b916781 patch 8.0.0734: the script to check translations can be improved
Christian Brabandt <cb@256bit.org>
parents: 9963
diff changeset
155 if end <= 0
48a95b916781 patch 8.0.0734: the script to check translations can be improved
Christian Brabandt <cb@256bit.org>
parents: 9963
diff changeset
156 let end = line('$') + 1
48a95b916781 patch 8.0.0734: the script to check translations can be improved
Christian Brabandt <cb@256bit.org>
parents: 9963
diff changeset
157 endif
48a95b916781 patch 8.0.0734: the script to check translations can be improved
Christian Brabandt <cb@256bit.org>
parents: 9963
diff changeset
158 let origcount = CountNl(lnum, strlnum - 1)
48a95b916781 patch 8.0.0734: the script to check translations can be improved
Christian Brabandt <cb@256bit.org>
parents: 9963
diff changeset
159 let transcount = CountNl(strlnum, end - 1)
48a95b916781 patch 8.0.0734: the script to check translations can be improved
Christian Brabandt <cb@256bit.org>
parents: 9963
diff changeset
160 " Allow for a few more or less line breaks when there are 2 or more
48a95b916781 patch 8.0.0734: the script to check translations can be improved
Christian Brabandt <cb@256bit.org>
parents: 9963
diff changeset
161 if origcount != transcount && (origcount <= 2 || transcount <= 2)
11828
5a07a3ff56c1 patch 8.0.0794: checking translations fails with multiple NL
Christian Brabandt <cb@256bit.org>
parents: 11702
diff changeset
162 echomsg 'Mismatching "\n" in line ' . line('.')
11702
48a95b916781 patch 8.0.0734: the script to check translations can be improved
Christian Brabandt <cb@256bit.org>
parents: 9963
diff changeset
163 if error == 0
48a95b916781 patch 8.0.0734: the script to check translations can be improved
Christian Brabandt <cb@256bit.org>
parents: 9963
diff changeset
164 let error = lnum
48a95b916781 patch 8.0.0734: the script to check translations can be improved
Christian Brabandt <cb@256bit.org>
parents: 9963
diff changeset
165 endif
48a95b916781 patch 8.0.0734: the script to check translations can be improved
Christian Brabandt <cb@256bit.org>
parents: 9963
diff changeset
166 endif
48a95b916781 patch 8.0.0734: the script to check translations can be improved
Christian Brabandt <cb@256bit.org>
parents: 9963
diff changeset
167 endwhile
48a95b916781 patch 8.0.0734: the script to check translations can be improved
Christian Brabandt <cb@256bit.org>
parents: 9963
diff changeset
168
11900
39e46ae74c69 patch 8.0.0830: translating messages is not ideal
Christian Brabandt <cb@256bit.org>
parents: 11828
diff changeset
169 " Check that the file is well formed according to msgfmts understanding
39e46ae74c69 patch 8.0.0830: translating messages is not ideal
Christian Brabandt <cb@256bit.org>
parents: 11828
diff changeset
170 if executable("msgfmt")
39e46ae74c69 patch 8.0.0830: translating messages is not ideal
Christian Brabandt <cb@256bit.org>
parents: 11828
diff changeset
171 let filename = expand("%")
12756
3b26420fc639 Long overdue runtime update.
Christian Brabandt <cb@256bit.org>
parents: 11910
diff changeset
172 " Newer msgfmt does not take OLD_PO_FILE_INPUT argument, must be in
3b26420fc639 Long overdue runtime update.
Christian Brabandt <cb@256bit.org>
parents: 11910
diff changeset
173 " environment.
3b26420fc639 Long overdue runtime update.
Christian Brabandt <cb@256bit.org>
parents: 11910
diff changeset
174 let $OLD_PO_FILE_INPUT = 'yes'
3b26420fc639 Long overdue runtime update.
Christian Brabandt <cb@256bit.org>
parents: 11910
diff changeset
175 let a = system("msgfmt --statistics " . filename)
11900
39e46ae74c69 patch 8.0.0830: translating messages is not ideal
Christian Brabandt <cb@256bit.org>
parents: 11828
diff changeset
176 if v:shell_error != 0
39e46ae74c69 patch 8.0.0830: translating messages is not ideal
Christian Brabandt <cb@256bit.org>
parents: 11828
diff changeset
177 let error = matchstr(a, filename.':\zs\d\+\ze:')+0
39e46ae74c69 patch 8.0.0830: translating messages is not ideal
Christian Brabandt <cb@256bit.org>
parents: 11828
diff changeset
178 for line in split(a, '\n') | echomsg line | endfor
39e46ae74c69 patch 8.0.0830: translating messages is not ideal
Christian Brabandt <cb@256bit.org>
parents: 11828
diff changeset
179 endif
39e46ae74c69 patch 8.0.0830: translating messages is not ideal
Christian Brabandt <cb@256bit.org>
parents: 11828
diff changeset
180 endif
39e46ae74c69 patch 8.0.0830: translating messages is not ideal
Christian Brabandt <cb@256bit.org>
parents: 11828
diff changeset
181
13938
b9db0bc9b8f9 patch 8.0.1839: script to check .po file doesn't check for plural header
Christian Brabandt <cb@256bit.org>
parents: 13812
diff changeset
182 " Check that the plural form is properly initialized
b9db0bc9b8f9 patch 8.0.1839: script to check .po file doesn't check for plural header
Christian Brabandt <cb@256bit.org>
parents: 13812
diff changeset
183 1
b9db0bc9b8f9 patch 8.0.1839: script to check .po file doesn't check for plural header
Christian Brabandt <cb@256bit.org>
parents: 13812
diff changeset
184 let plural = search('^msgid_plural ', 'n')
b9db0bc9b8f9 patch 8.0.1839: script to check .po file doesn't check for plural header
Christian Brabandt <cb@256bit.org>
parents: 13812
diff changeset
185 if (plural && search('^"Plural-Forms: ', 'n') == 0) || (plural && search('^msgstr\[0\] ".\+"', 'n') != plural + 1)
b9db0bc9b8f9 patch 8.0.1839: script to check .po file doesn't check for plural header
Christian Brabandt <cb@256bit.org>
parents: 13812
diff changeset
186 if search('^"Plural-Forms: ', 'n') == 0
b9db0bc9b8f9 patch 8.0.1839: script to check .po file doesn't check for plural header
Christian Brabandt <cb@256bit.org>
parents: 13812
diff changeset
187 echomsg "Missing Plural header"
b9db0bc9b8f9 patch 8.0.1839: script to check .po file doesn't check for plural header
Christian Brabandt <cb@256bit.org>
parents: 13812
diff changeset
188 if error == 0
b9db0bc9b8f9 patch 8.0.1839: script to check .po file doesn't check for plural header
Christian Brabandt <cb@256bit.org>
parents: 13812
diff changeset
189 let error = search('\(^"[A-Za-z-_]\+: .*\\n"\n\)\+\zs', 'n') - 1
b9db0bc9b8f9 patch 8.0.1839: script to check .po file doesn't check for plural header
Christian Brabandt <cb@256bit.org>
parents: 13812
diff changeset
190 endif
b9db0bc9b8f9 patch 8.0.1839: script to check .po file doesn't check for plural header
Christian Brabandt <cb@256bit.org>
parents: 13812
diff changeset
191 elseif error == 0
b9db0bc9b8f9 patch 8.0.1839: script to check .po file doesn't check for plural header
Christian Brabandt <cb@256bit.org>
parents: 13812
diff changeset
192 let error = plural
b9db0bc9b8f9 patch 8.0.1839: script to check .po file doesn't check for plural header
Christian Brabandt <cb@256bit.org>
parents: 13812
diff changeset
193 endif
b9db0bc9b8f9 patch 8.0.1839: script to check .po file doesn't check for plural header
Christian Brabandt <cb@256bit.org>
parents: 13812
diff changeset
194 elseif !plural && search('^"Plural-Forms: ', 'n')
b9db0bc9b8f9 patch 8.0.1839: script to check .po file doesn't check for plural header
Christian Brabandt <cb@256bit.org>
parents: 13812
diff changeset
195 " We allow for a stray plural header, msginit adds one.
b9db0bc9b8f9 patch 8.0.1839: script to check .po file doesn't check for plural header
Christian Brabandt <cb@256bit.org>
parents: 13812
diff changeset
196 endif
b9db0bc9b8f9 patch 8.0.1839: script to check .po file doesn't check for plural header
Christian Brabandt <cb@256bit.org>
parents: 13812
diff changeset
197
14187
b79453d0d01c patch 8.1.0111: .po files do not use recommended names
Christian Brabandt <cb@256bit.org>
parents: 13938
diff changeset
198 " Check that 8bit encoding is used instead of 8-bit
b79453d0d01c patch 8.1.0111: .po files do not use recommended names
Christian Brabandt <cb@256bit.org>
parents: 13938
diff changeset
199 let cte = search('^"Content-Transfer-Encoding:\s\+8-bit', 'n')
b79453d0d01c patch 8.1.0111: .po files do not use recommended names
Christian Brabandt <cb@256bit.org>
parents: 13938
diff changeset
200 let ctc = search('^"Content-Type:.*;\s\+\<charset=[iI][sS][oO]_', 'n')
b79453d0d01c patch 8.1.0111: .po files do not use recommended names
Christian Brabandt <cb@256bit.org>
parents: 13938
diff changeset
201 let ctu = search('^"Content-Type:.*;\s\+\<charset=utf-8', 'n')
b79453d0d01c patch 8.1.0111: .po files do not use recommended names
Christian Brabandt <cb@256bit.org>
parents: 13938
diff changeset
202 if cte
b79453d0d01c patch 8.1.0111: .po files do not use recommended names
Christian Brabandt <cb@256bit.org>
parents: 13938
diff changeset
203 echomsg "Content-Transfer-Encoding should be 8bit instead of 8-bit"
b79453d0d01c patch 8.1.0111: .po files do not use recommended names
Christian Brabandt <cb@256bit.org>
parents: 13938
diff changeset
204 " TODO: make this an error
b79453d0d01c patch 8.1.0111: .po files do not use recommended names
Christian Brabandt <cb@256bit.org>
parents: 13938
diff changeset
205 " if error == 0
b79453d0d01c patch 8.1.0111: .po files do not use recommended names
Christian Brabandt <cb@256bit.org>
parents: 13938
diff changeset
206 " let error = cte
b79453d0d01c patch 8.1.0111: .po files do not use recommended names
Christian Brabandt <cb@256bit.org>
parents: 13938
diff changeset
207 " endif
b79453d0d01c patch 8.1.0111: .po files do not use recommended names
Christian Brabandt <cb@256bit.org>
parents: 13938
diff changeset
208 elseif ctc
b79453d0d01c patch 8.1.0111: .po files do not use recommended names
Christian Brabandt <cb@256bit.org>
parents: 13938
diff changeset
209 echomsg "Content-Type charset should be 'ISO-...' instead of 'ISO_...'"
b79453d0d01c patch 8.1.0111: .po files do not use recommended names
Christian Brabandt <cb@256bit.org>
parents: 13938
diff changeset
210 " TODO: make this an error
b79453d0d01c patch 8.1.0111: .po files do not use recommended names
Christian Brabandt <cb@256bit.org>
parents: 13938
diff changeset
211 " if error == 0
b79453d0d01c patch 8.1.0111: .po files do not use recommended names
Christian Brabandt <cb@256bit.org>
parents: 13938
diff changeset
212 " let error = ct
b79453d0d01c patch 8.1.0111: .po files do not use recommended names
Christian Brabandt <cb@256bit.org>
parents: 13938
diff changeset
213 " endif
b79453d0d01c patch 8.1.0111: .po files do not use recommended names
Christian Brabandt <cb@256bit.org>
parents: 13938
diff changeset
214 elseif ctu
b79453d0d01c patch 8.1.0111: .po files do not use recommended names
Christian Brabandt <cb@256bit.org>
parents: 13938
diff changeset
215 echomsg "Content-Type charset should be 'UTF-8' instead of 'utf-8'"
b79453d0d01c patch 8.1.0111: .po files do not use recommended names
Christian Brabandt <cb@256bit.org>
parents: 13938
diff changeset
216 " TODO: make this an error
b79453d0d01c patch 8.1.0111: .po files do not use recommended names
Christian Brabandt <cb@256bit.org>
parents: 13938
diff changeset
217 " if error == 0
b79453d0d01c patch 8.1.0111: .po files do not use recommended names
Christian Brabandt <cb@256bit.org>
parents: 13938
diff changeset
218 " let error = ct
b79453d0d01c patch 8.1.0111: .po files do not use recommended names
Christian Brabandt <cb@256bit.org>
parents: 13938
diff changeset
219 " endif
b79453d0d01c patch 8.1.0111: .po files do not use recommended names
Christian Brabandt <cb@256bit.org>
parents: 13938
diff changeset
220 endif
b79453d0d01c patch 8.1.0111: .po files do not use recommended names
Christian Brabandt <cb@256bit.org>
parents: 13938
diff changeset
221
13938
b9db0bc9b8f9 patch 8.0.1839: script to check .po file doesn't check for plural header
Christian Brabandt <cb@256bit.org>
parents: 13812
diff changeset
222
461
f98374445f66 updated for version 7.0123
vimboss
parents:
diff changeset
223 if error == 0
11702
48a95b916781 patch 8.0.0734: the script to check translations can be improved
Christian Brabandt <cb@256bit.org>
parents: 9963
diff changeset
224 " If all was OK restore the view.
48a95b916781 patch 8.0.0734: the script to check translations can be improved
Christian Brabandt <cb@256bit.org>
parents: 9963
diff changeset
225 call winrestview(wsv)
9963
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
226 echomsg "OK"
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
227 else
14187
b79453d0d01c patch 8.1.0111: .po files do not use recommended names
Christian Brabandt <cb@256bit.org>
parents: 13938
diff changeset
228 " Put the cursor on the line with the error.
9963
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
229 exe error
461
f98374445f66 updated for version 7.0123
vimboss
parents:
diff changeset
230 endif
f98374445f66 updated for version 7.0123
vimboss
parents:
diff changeset
231
2484
e037ee8698b3 Set 'wrapscan' when checking the .po files. (Mike Williams)
Bram Moolenaar <bram@vim.org>
parents: 1952
diff changeset
232 let &wrapscan = s:save_wrapscan
e037ee8698b3 Set 'wrapscan' when checking the .po files. (Mike Williams)
Bram Moolenaar <bram@vim.org>
parents: 1952
diff changeset
233 unlet s:save_wrapscan
e037ee8698b3 Set 'wrapscan' when checking the .po files. (Mike Williams)
Bram Moolenaar <bram@vim.org>
parents: 1952
diff changeset
234
461
f98374445f66 updated for version 7.0123
vimboss
parents:
diff changeset
235 endif