Mercurial > vim
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 |
rev | line source |
---|---|
461 | 1 " Vim script for checking .po files. |
2 " | |
1599 | 3 " Go through the file and verify that: |
4 " - All %...s items in "msgid" are identical to the ones in "msgstr". | |
5 " - An error or warning code in "msgid" matches the one in "msgstr". | |
461 | 6 |
7 if 1 " Only execute this if the eval feature is available. | |
8 | |
9 " Function to get a split line at the cursor. | |
10 " Used for both msgid and msgstr lines. | |
11 " Removes all text except % items and returns the result. | |
12 func! GetMline() | |
13 let idline = substitute(getline('.'), '"\(.*\)"$', '\1', '') | |
14 while line('.') < line('$') | |
15 + | |
16 let line = getline('.') | |
17 if line[0] != '"' | |
18 break | |
19 endif | |
20 let idline .= substitute(line, '"\(.*\)"$', '\1', '') | |
21 endwhile | |
22 | |
557 | 23 " remove '%', not used for formatting. |
24 let idline = substitute(idline, "'%'", '', 'g') | |
25 | |
1952 | 26 " remove '%' used for plural forms. |
27 let idline = substitute(idline, '\\nPlural-Forms: .\+;\\n', '', '') | |
28 | |
461 | 29 " remove everything but % items. |
30 return substitute(idline, '[^%]*\(%[-+ #''.0-9*]*l\=[dsuxXpoc%]\)\=', '\1', 'g') | |
31 endfunc | |
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 | 37 " Start at the first "msgid" line. |
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 | 43 let error = 0 |
44 | |
45 while 1 | |
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 | 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 | 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 | 87 endif |
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 | 93 break |
94 endif | |
95 endwhile | |
96 | |
1599 | 97 " Check that error code in msgid matches the one in msgstr. |
98 " | |
99 " Examples of mismatches found with msgid "E123: ..." | |
100 " - msgstr "E321: ..." error code mismatch | |
101 " - msgstr "W123: ..." warning instead of error | |
102 " - msgstr "E123 ..." missing colon | |
103 " - msgstr "..." missing error code | |
104 " | |
105 1 | |
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 | 111 endif |
112 | |
461 | 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 | 117 endif |
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 | 122 endif |