Mercurial > vim
annotate src/po/check.vim @ 11829:f7091bdf552b
Added tag v8.0.0794 for changeset 5a07a3ff56c196fc004d710df087f005d7a86b0e
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Fri, 28 Jul 2017 17:00:06 +0200 |
parents | 5a07a3ff56c1 |
children | 39e46ae74c69 |
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. |
11702
48a95b916781
patch 8.0.0734: the script to check translations can be improved
Christian Brabandt <cb@256bit.org>
parents:
9963
diff
changeset
|
38 let wsv = winsaveview() |
461 | 39 1 |
9963
580f57b07547
commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents:
2484
diff
changeset
|
40 /^msgid\> |
580f57b07547
commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents:
2484
diff
changeset
|
41 |
580f57b07547
commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents:
2484
diff
changeset
|
42 " 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
|
43 " Note: this is used in the Makefile. |
461 | 44 let error = 0 |
45 | |
46 while 1 | |
47 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
|
48 " 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
|
49 let prevfromline = 'foobar' |
580f57b07547
commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents:
2484
diff
changeset
|
50 while 1 |
580f57b07547
commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents:
2484
diff
changeset
|
51 let fromline = GetMline() |
580f57b07547
commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents:
2484
diff
changeset
|
52 if prevfromline != 'foobar' && prevfromline != fromline |
580f57b07547
commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents:
2484
diff
changeset
|
53 echomsg 'Mismatching % in line ' . (line('.') - 1) |
580f57b07547
commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents:
2484
diff
changeset
|
54 echomsg 'msgid: ' . prevfromline |
580f57b07547
commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents:
2484
diff
changeset
|
55 echomsg 'msgid ' . fromline |
580f57b07547
commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents:
2484
diff
changeset
|
56 if error == 0 |
580f57b07547
commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents:
2484
diff
changeset
|
57 let error = line('.') |
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 endif |
580f57b07547
commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents:
2484
diff
changeset
|
60 if getline('.') !~ 'msgid_plural' |
580f57b07547
commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents:
2484
diff
changeset
|
61 break |
580f57b07547
commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents:
2484
diff
changeset
|
62 endif |
580f57b07547
commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents:
2484
diff
changeset
|
63 let prevfromline = fromline |
580f57b07547
commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents:
2484
diff
changeset
|
64 endwhile |
580f57b07547
commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents:
2484
diff
changeset
|
65 |
461 | 66 if getline('.') !~ '^msgstr' |
9963
580f57b07547
commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents:
2484
diff
changeset
|
67 echomsg 'Missing "msgstr" in line ' . line('.') |
580f57b07547
commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents:
2484
diff
changeset
|
68 if error == 0 |
580f57b07547
commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents:
2484
diff
changeset
|
69 let error = line('.') |
580f57b07547
commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents:
2484
diff
changeset
|
70 endif |
461 | 71 endif |
9963
580f57b07547
commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents:
2484
diff
changeset
|
72 |
580f57b07547
commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents:
2484
diff
changeset
|
73 " check all the 'msgstr' lines |
580f57b07547
commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents:
2484
diff
changeset
|
74 while getline('.') =~ '^msgstr' |
580f57b07547
commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents:
2484
diff
changeset
|
75 let toline = GetMline() |
580f57b07547
commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents:
2484
diff
changeset
|
76 if fromline != toline |
580f57b07547
commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents:
2484
diff
changeset
|
77 echomsg 'Mismatching % in line ' . (line('.') - 1) |
580f57b07547
commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents:
2484
diff
changeset
|
78 echomsg 'msgid: ' . fromline |
580f57b07547
commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents:
2484
diff
changeset
|
79 echomsg 'msgstr: ' . toline |
580f57b07547
commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents:
2484
diff
changeset
|
80 if error == 0 |
580f57b07547
commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents:
2484
diff
changeset
|
81 let error = line('.') |
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 endif |
580f57b07547
commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents:
2484
diff
changeset
|
84 if line('.') == line('$') |
580f57b07547
commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents:
2484
diff
changeset
|
85 break |
580f57b07547
commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents:
2484
diff
changeset
|
86 endif |
580f57b07547
commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents:
2484
diff
changeset
|
87 endwhile |
461 | 88 endif |
89 | |
9963
580f57b07547
commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents:
2484
diff
changeset
|
90 " 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
|
91 let lnum = line('.') |
580f57b07547
commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents:
2484
diff
changeset
|
92 silent! /^msgid\> |
580f57b07547
commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents:
2484
diff
changeset
|
93 if line('.') == lnum |
461 | 94 break |
95 endif | |
96 endwhile | |
97 | |
1599 | 98 " Check that error code in msgid matches the one in msgstr. |
99 " | |
100 " Examples of mismatches found with msgid "E123: ..." | |
101 " - msgstr "E321: ..." error code mismatch | |
102 " - msgstr "W123: ..." warning instead of error | |
103 " - msgstr "E123 ..." missing colon | |
104 " - msgstr "..." missing error code | |
105 " | |
106 1 | |
107 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
|
108 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
|
109 if error == 0 |
580f57b07547
commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents:
2484
diff
changeset
|
110 let error = line('.') |
580f57b07547
commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents:
2484
diff
changeset
|
111 endif |
1599 | 112 endif |
113 | |
11702
48a95b916781
patch 8.0.0734: the script to check translations can be improved
Christian Brabandt <cb@256bit.org>
parents:
9963
diff
changeset
|
114 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
|
115 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
|
116 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
|
117 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
|
118 endfor |
48a95b916781
patch 8.0.0734: the script to check translations can be improved
Christian Brabandt <cb@256bit.org>
parents:
9963
diff
changeset
|
119 return nl |
48a95b916781
patch 8.0.0734: the script to check translations can be improved
Christian Brabandt <cb@256bit.org>
parents:
9963
diff
changeset
|
120 endfunc |
48a95b916781
patch 8.0.0734: the script to check translations can be improved
Christian Brabandt <cb@256bit.org>
parents:
9963
diff
changeset
|
121 |
11828
5a07a3ff56c1
patch 8.0.0794: checking translations fails with multiple NL
Christian Brabandt <cb@256bit.org>
parents:
11702
diff
changeset
|
122 " 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
|
123 " line. Skip over the header. |
48a95b916781
patch 8.0.0734: the script to check translations can be improved
Christian Brabandt <cb@256bit.org>
parents:
9963
diff
changeset
|
124 /^"MIME-Version: |
48a95b916781
patch 8.0.0734: the script to check translations can be improved
Christian Brabandt <cb@256bit.org>
parents:
9963
diff
changeset
|
125 while 1 |
48a95b916781
patch 8.0.0734: the script to check translations can be improved
Christian Brabandt <cb@256bit.org>
parents:
9963
diff
changeset
|
126 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
|
127 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
|
128 break |
48a95b916781
patch 8.0.0734: the script to check translations can be improved
Christian Brabandt <cb@256bit.org>
parents:
9963
diff
changeset
|
129 endif |
48a95b916781
patch 8.0.0734: the script to check translations can be improved
Christian Brabandt <cb@256bit.org>
parents:
9963
diff
changeset
|
130 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
|
131 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
|
132 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
|
133 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
|
134 endif |
48a95b916781
patch 8.0.0734: the script to check translations can be improved
Christian Brabandt <cb@256bit.org>
parents:
9963
diff
changeset
|
135 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
|
136 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
|
137 " 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
|
138 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
|
139 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
|
140 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
|
141 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
|
142 endif |
48a95b916781
patch 8.0.0734: the script to check translations can be improved
Christian Brabandt <cb@256bit.org>
parents:
9963
diff
changeset
|
143 endif |
48a95b916781
patch 8.0.0734: the script to check translations can be improved
Christian Brabandt <cb@256bit.org>
parents:
9963
diff
changeset
|
144 endwhile |
48a95b916781
patch 8.0.0734: the script to check translations can be improved
Christian Brabandt <cb@256bit.org>
parents:
9963
diff
changeset
|
145 |
461 | 146 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
|
147 " 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
|
148 call winrestview(wsv) |
9963
580f57b07547
commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents:
2484
diff
changeset
|
149 echomsg "OK" |
580f57b07547
commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents:
2484
diff
changeset
|
150 else |
580f57b07547
commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents:
2484
diff
changeset
|
151 exe error |
461 | 152 endif |
153 | |
2484
e037ee8698b3
Set 'wrapscan' when checking the .po files. (Mike Williams)
Bram Moolenaar <bram@vim.org>
parents:
1952
diff
changeset
|
154 let &wrapscan = s:save_wrapscan |
e037ee8698b3
Set 'wrapscan' when checking the .po files. (Mike Williams)
Bram Moolenaar <bram@vim.org>
parents:
1952
diff
changeset
|
155 unlet s:save_wrapscan |
e037ee8698b3
Set 'wrapscan' when checking the .po files. (Mike Williams)
Bram Moolenaar <bram@vim.org>
parents:
1952
diff
changeset
|
156 |
461 | 157 endif |