annotate src/po/check.vim @ 9963:580f57b07547 v7.4.2255

commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7 Author: Bram Moolenaar <Bram@vim.org> Date: Fri Aug 26 15:51:53 2016 +0200 patch 7.4.2255 Problem: The script that checks translations can't handle plurals. Solution: Check for plural msgid and msgstr entries. Leave the cursor on the first error.
author Christian Brabandt <cb@256bit.org>
date Fri, 26 Aug 2016 16:00:06 +0200
parents e037ee8698b3
children 48a95b916781
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
f98374445f66 updated for version 7.0123
vimboss
parents:
diff changeset
9 " Function to get a split line at the cursor.
f98374445f66 updated for version 7.0123
vimboss
parents:
diff changeset
10 " Used for both msgid and msgstr lines.
f98374445f66 updated for version 7.0123
vimboss
parents:
diff changeset
11 " Removes all text except % items and returns the result.
f98374445f66 updated for version 7.0123
vimboss
parents:
diff changeset
12 func! GetMline()
f98374445f66 updated for version 7.0123
vimboss
parents:
diff changeset
13 let idline = substitute(getline('.'), '"\(.*\)"$', '\1', '')
f98374445f66 updated for version 7.0123
vimboss
parents:
diff changeset
14 while line('.') < line('$')
f98374445f66 updated for version 7.0123
vimboss
parents:
diff changeset
15 +
f98374445f66 updated for version 7.0123
vimboss
parents:
diff changeset
16 let line = getline('.')
f98374445f66 updated for version 7.0123
vimboss
parents:
diff changeset
17 if line[0] != '"'
f98374445f66 updated for version 7.0123
vimboss
parents:
diff changeset
18 break
f98374445f66 updated for version 7.0123
vimboss
parents:
diff changeset
19 endif
f98374445f66 updated for version 7.0123
vimboss
parents:
diff changeset
20 let idline .= substitute(line, '"\(.*\)"$', '\1', '')
f98374445f66 updated for version 7.0123
vimboss
parents:
diff changeset
21 endwhile
f98374445f66 updated for version 7.0123
vimboss
parents:
diff changeset
22
557
862863033fdd updated for version 7.0158
vimboss
parents: 461
diff changeset
23 " remove '%', not used for formatting.
862863033fdd updated for version 7.0158
vimboss
parents: 461
diff changeset
24 let idline = substitute(idline, "'%'", '', 'g')
862863033fdd updated for version 7.0158
vimboss
parents: 461
diff changeset
25
1952
6ddd55ac6ce5 updated for version 7.2-249
vimboss
parents: 1599
diff changeset
26 " remove '%' used for plural forms.
6ddd55ac6ce5 updated for version 7.2-249
vimboss
parents: 1599
diff changeset
27 let idline = substitute(idline, '\\nPlural-Forms: .\+;\\n', '', '')
6ddd55ac6ce5 updated for version 7.2-249
vimboss
parents: 1599
diff changeset
28
461
f98374445f66 updated for version 7.0123
vimboss
parents:
diff changeset
29 " remove everything but % items.
f98374445f66 updated for version 7.0123
vimboss
parents:
diff changeset
30 return substitute(idline, '[^%]*\(%[-+ #''.0-9*]*l\=[dsuxXpoc%]\)\=', '\1', 'g')
f98374445f66 updated for version 7.0123
vimboss
parents:
diff changeset
31 endfunc
f98374445f66 updated for version 7.0123
vimboss
parents:
diff changeset
32
9963
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
33 " 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
34 let s:save_wrapscan = &wrapscan
9963
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
35 set nowrapscan
2484
e037ee8698b3 Set 'wrapscan' when checking the .po files. (Mike Williams)
Bram Moolenaar <bram@vim.org>
parents: 1952
diff changeset
36
461
f98374445f66 updated for version 7.0123
vimboss
parents:
diff changeset
37 " Start at the first "msgid" line.
f98374445f66 updated for version 7.0123
vimboss
parents:
diff changeset
38 1
9963
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
39 /^msgid\>
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
40
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
41 " 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
42 " Note: this is used in the Makefile.
461
f98374445f66 updated for version 7.0123
vimboss
parents:
diff changeset
43 let error = 0
f98374445f66 updated for version 7.0123
vimboss
parents:
diff changeset
44
f98374445f66 updated for version 7.0123
vimboss
parents:
diff changeset
45 while 1
f98374445f66 updated for version 7.0123
vimboss
parents:
diff changeset
46 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
47 " 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
48 let prevfromline = 'foobar'
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
49 while 1
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
50 let fromline = GetMline()
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
51 if prevfromline != 'foobar' && prevfromline != fromline
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
52 echomsg 'Mismatching % in line ' . (line('.') - 1)
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
53 echomsg 'msgid: ' . prevfromline
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
54 echomsg 'msgid ' . fromline
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
55 if error == 0
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
56 let error = line('.')
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
57 endif
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
58 endif
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
59 if getline('.') !~ 'msgid_plural'
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
60 break
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
61 endif
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
62 let prevfromline = fromline
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
63 endwhile
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
64
461
f98374445f66 updated for version 7.0123
vimboss
parents:
diff changeset
65 if getline('.') !~ '^msgstr'
9963
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
66 echomsg 'Missing "msgstr" in line ' . line('.')
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
67 if error == 0
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
68 let error = line('.')
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
69 endif
461
f98374445f66 updated for version 7.0123
vimboss
parents:
diff changeset
70 endif
9963
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
71
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
72 " check all the 'msgstr' lines
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
73 while getline('.') =~ '^msgstr'
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
74 let toline = GetMline()
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
75 if fromline != toline
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
76 echomsg 'Mismatching % in line ' . (line('.') - 1)
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
77 echomsg 'msgid: ' . fromline
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
78 echomsg 'msgstr: ' . toline
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
79 if error == 0
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
80 let error = line('.')
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
81 endif
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
82 endif
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
83 if line('.') == line('$')
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
84 break
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
85 endif
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
86 endwhile
461
f98374445f66 updated for version 7.0123
vimboss
parents:
diff changeset
87 endif
f98374445f66 updated for version 7.0123
vimboss
parents:
diff changeset
88
9963
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
89 " 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
90 let lnum = line('.')
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
91 silent! /^msgid\>
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
92 if line('.') == lnum
461
f98374445f66 updated for version 7.0123
vimboss
parents:
diff changeset
93 break
f98374445f66 updated for version 7.0123
vimboss
parents:
diff changeset
94 endif
f98374445f66 updated for version 7.0123
vimboss
parents:
diff changeset
95 endwhile
f98374445f66 updated for version 7.0123
vimboss
parents:
diff changeset
96
1599
2f016b638c0c updated for version 7.1-312
vimboss
parents: 557
diff changeset
97 " Check that error code in msgid matches the one in msgstr.
2f016b638c0c updated for version 7.1-312
vimboss
parents: 557
diff changeset
98 "
2f016b638c0c updated for version 7.1-312
vimboss
parents: 557
diff changeset
99 " Examples of mismatches found with msgid "E123: ..."
2f016b638c0c updated for version 7.1-312
vimboss
parents: 557
diff changeset
100 " - msgstr "E321: ..." error code mismatch
2f016b638c0c updated for version 7.1-312
vimboss
parents: 557
diff changeset
101 " - msgstr "W123: ..." warning instead of error
2f016b638c0c updated for version 7.1-312
vimboss
parents: 557
diff changeset
102 " - msgstr "E123 ..." missing colon
2f016b638c0c updated for version 7.1-312
vimboss
parents: 557
diff changeset
103 " - msgstr "..." missing error code
2f016b638c0c updated for version 7.1-312
vimboss
parents: 557
diff changeset
104 "
2f016b638c0c updated for version 7.1-312
vimboss
parents: 557
diff changeset
105 1
2f016b638c0c updated for version 7.1-312
vimboss
parents: 557
diff changeset
106 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
107 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
108 if error == 0
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
109 let error = line('.')
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
110 endif
1599
2f016b638c0c updated for version 7.1-312
vimboss
parents: 557
diff changeset
111 endif
2f016b638c0c updated for version 7.1-312
vimboss
parents: 557
diff changeset
112
461
f98374445f66 updated for version 7.0123
vimboss
parents:
diff changeset
113 if error == 0
9963
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
114 echomsg "OK"
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
115 else
580f57b07547 commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents: 2484
diff changeset
116 exe error
461
f98374445f66 updated for version 7.0123
vimboss
parents:
diff changeset
117 endif
f98374445f66 updated for version 7.0123
vimboss
parents:
diff changeset
118
2484
e037ee8698b3 Set 'wrapscan' when checking the .po files. (Mike Williams)
Bram Moolenaar <bram@vim.org>
parents: 1952
diff changeset
119 let &wrapscan = s:save_wrapscan
e037ee8698b3 Set 'wrapscan' when checking the .po files. (Mike Williams)
Bram Moolenaar <bram@vim.org>
parents: 1952
diff changeset
120 unlet s:save_wrapscan
e037ee8698b3 Set 'wrapscan' when checking the .po files. (Mike Williams)
Bram Moolenaar <bram@vim.org>
parents: 1952
diff changeset
121
461
f98374445f66 updated for version 7.0123
vimboss
parents:
diff changeset
122 endif