Mercurial > vim
annotate src/po/check.vim @ 21791:d504fcd3d2c0 v8.2.1445
patch 8.2.1445: Vim9: function expanded name is cleared when sourcing again
Commit: https://github.com/vim/vim/commit/c4ce36d48698669f81ec90f7c9dc9ab8c362e538
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri Aug 14 17:08:15 2020 +0200
patch 8.2.1445: Vim9: function expanded name is cleared when sourcing again
Problem: Vim9: function expanded name is cleared when sourcing a script
again.
Solution: Only clear the expanded name when deleting the function.
(closes #6707)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 14 Aug 2020 17:15:04 +0200 |
parents | 57927799c27e |
children | 4d5081260d5a |
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 | |
18625
57927799c27e
patch 8.1.2305: no warning for wrong entry in translations
Bram Moolenaar <Bram@vim.org>
parents:
14187
diff
changeset
|
47 let lnum = line('.') |
57927799c27e
patch 8.1.2305: no warning for wrong entry in translations
Bram Moolenaar <Bram@vim.org>
parents:
14187
diff
changeset
|
48 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
|
49 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
|
50 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
|
51 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
|
52 if error == 0 |
57927799c27e
patch 8.1.2305: no warning for wrong entry in translations
Bram Moolenaar <Bram@vim.org>
parents:
14187
diff
changeset
|
53 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
|
54 endif |
57927799c27e
patch 8.1.2305: no warning for wrong entry in translations
Bram Moolenaar <Bram@vim.org>
parents:
14187
diff
changeset
|
55 endif |
57927799c27e
patch 8.1.2305: no warning for wrong entry in translations
Bram Moolenaar <Bram@vim.org>
parents:
14187
diff
changeset
|
56 endif |
57927799c27e
patch 8.1.2305: no warning for wrong entry in translations
Bram Moolenaar <Bram@vim.org>
parents:
14187
diff
changeset
|
57 |
461 | 58 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
|
59 " 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
|
60 let prevfromline = 'foobar' |
580f57b07547
commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents:
2484
diff
changeset
|
61 while 1 |
580f57b07547
commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents:
2484
diff
changeset
|
62 let fromline = GetMline() |
580f57b07547
commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents:
2484
diff
changeset
|
63 if prevfromline != 'foobar' && prevfromline != fromline |
580f57b07547
commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents:
2484
diff
changeset
|
64 echomsg 'Mismatching % in line ' . (line('.') - 1) |
580f57b07547
commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents:
2484
diff
changeset
|
65 echomsg 'msgid: ' . prevfromline |
580f57b07547
commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents:
2484
diff
changeset
|
66 echomsg 'msgid ' . fromline |
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 |
580f57b07547
commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents:
2484
diff
changeset
|
70 endif |
580f57b07547
commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents:
2484
diff
changeset
|
71 if getline('.') !~ 'msgid_plural' |
580f57b07547
commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents:
2484
diff
changeset
|
72 break |
580f57b07547
commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents:
2484
diff
changeset
|
73 endif |
580f57b07547
commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents:
2484
diff
changeset
|
74 let prevfromline = fromline |
580f57b07547
commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents:
2484
diff
changeset
|
75 endwhile |
580f57b07547
commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents:
2484
diff
changeset
|
76 |
461 | 77 if getline('.') !~ '^msgstr' |
9963
580f57b07547
commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents:
2484
diff
changeset
|
78 echomsg 'Missing "msgstr" in line ' . line('.') |
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 |
461 | 82 endif |
9963
580f57b07547
commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents:
2484
diff
changeset
|
83 |
580f57b07547
commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents:
2484
diff
changeset
|
84 " check all the 'msgstr' lines |
580f57b07547
commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents:
2484
diff
changeset
|
85 while getline('.') =~ '^msgstr' |
580f57b07547
commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents:
2484
diff
changeset
|
86 let toline = GetMline() |
580f57b07547
commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents:
2484
diff
changeset
|
87 if fromline != toline |
580f57b07547
commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents:
2484
diff
changeset
|
88 echomsg 'Mismatching % in line ' . (line('.') - 1) |
580f57b07547
commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents:
2484
diff
changeset
|
89 echomsg 'msgid: ' . fromline |
580f57b07547
commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents:
2484
diff
changeset
|
90 echomsg 'msgstr: ' . toline |
580f57b07547
commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents:
2484
diff
changeset
|
91 if error == 0 |
580f57b07547
commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents:
2484
diff
changeset
|
92 let error = line('.') |
580f57b07547
commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents:
2484
diff
changeset
|
93 endif |
580f57b07547
commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents:
2484
diff
changeset
|
94 endif |
580f57b07547
commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents:
2484
diff
changeset
|
95 if line('.') == line('$') |
580f57b07547
commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents:
2484
diff
changeset
|
96 break |
580f57b07547
commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents:
2484
diff
changeset
|
97 endif |
580f57b07547
commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents:
2484
diff
changeset
|
98 endwhile |
461 | 99 endif |
100 | |
9963
580f57b07547
commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents:
2484
diff
changeset
|
101 " 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
|
102 let lnum = line('.') |
580f57b07547
commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents:
2484
diff
changeset
|
103 silent! /^msgid\> |
580f57b07547
commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents:
2484
diff
changeset
|
104 if line('.') == lnum |
461 | 105 break |
106 endif | |
107 endwhile | |
108 | |
1599 | 109 " Check that error code in msgid matches the one in msgstr. |
110 " | |
111 " Examples of mismatches found with msgid "E123: ..." | |
112 " - msgstr "E321: ..." error code mismatch | |
113 " - msgstr "W123: ..." warning instead of error | |
114 " - msgstr "E123 ..." missing colon | |
115 " - msgstr "..." missing error code | |
116 " | |
117 1 | |
118 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
|
119 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
|
120 if error == 0 |
580f57b07547
commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents:
2484
diff
changeset
|
121 let error = line('.') |
580f57b07547
commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents:
2484
diff
changeset
|
122 endif |
1599 | 123 endif |
124 | |
11702
48a95b916781
patch 8.0.0734: the script to check translations can be improved
Christian Brabandt <cb@256bit.org>
parents:
9963
diff
changeset
|
125 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
|
126 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
|
127 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
|
128 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
|
129 endfor |
48a95b916781
patch 8.0.0734: the script to check translations can be improved
Christian Brabandt <cb@256bit.org>
parents:
9963
diff
changeset
|
130 return nl |
48a95b916781
patch 8.0.0734: the script to check translations can be improved
Christian Brabandt <cb@256bit.org>
parents:
9963
diff
changeset
|
131 endfunc |
48a95b916781
patch 8.0.0734: the script to check translations can be improved
Christian Brabandt <cb@256bit.org>
parents:
9963
diff
changeset
|
132 |
11828
5a07a3ff56c1
patch 8.0.0794: checking translations fails with multiple NL
Christian Brabandt <cb@256bit.org>
parents:
11702
diff
changeset
|
133 " 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
|
134 " 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
|
135 1 |
11702
48a95b916781
patch 8.0.0734: the script to check translations can be improved
Christian Brabandt <cb@256bit.org>
parents:
9963
diff
changeset
|
136 /^"MIME-Version: |
48a95b916781
patch 8.0.0734: the script to check translations can be improved
Christian Brabandt <cb@256bit.org>
parents:
9963
diff
changeset
|
137 while 1 |
48a95b916781
patch 8.0.0734: the script to check translations can be improved
Christian Brabandt <cb@256bit.org>
parents:
9963
diff
changeset
|
138 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
|
139 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
|
140 break |
48a95b916781
patch 8.0.0734: the script to check translations can be improved
Christian Brabandt <cb@256bit.org>
parents:
9963
diff
changeset
|
141 endif |
48a95b916781
patch 8.0.0734: the script to check translations can be improved
Christian Brabandt <cb@256bit.org>
parents:
9963
diff
changeset
|
142 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
|
143 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
|
144 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
|
145 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
|
146 endif |
48a95b916781
patch 8.0.0734: the script to check translations can be improved
Christian Brabandt <cb@256bit.org>
parents:
9963
diff
changeset
|
147 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
|
148 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
|
149 " 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
|
150 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
|
151 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
|
152 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
|
153 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
|
154 endif |
48a95b916781
patch 8.0.0734: the script to check translations can be improved
Christian Brabandt <cb@256bit.org>
parents:
9963
diff
changeset
|
155 endif |
48a95b916781
patch 8.0.0734: the script to check translations can be improved
Christian Brabandt <cb@256bit.org>
parents:
9963
diff
changeset
|
156 endwhile |
48a95b916781
patch 8.0.0734: the script to check translations can be improved
Christian Brabandt <cb@256bit.org>
parents:
9963
diff
changeset
|
157 |
11900
39e46ae74c69
patch 8.0.0830: translating messages is not ideal
Christian Brabandt <cb@256bit.org>
parents:
11828
diff
changeset
|
158 " 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
|
159 if executable("msgfmt") |
39e46ae74c69
patch 8.0.0830: translating messages is not ideal
Christian Brabandt <cb@256bit.org>
parents:
11828
diff
changeset
|
160 let filename = expand("%") |
12756
3b26420fc639
Long overdue runtime update.
Christian Brabandt <cb@256bit.org>
parents:
11910
diff
changeset
|
161 " 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
|
162 " environment. |
3b26420fc639
Long overdue runtime update.
Christian Brabandt <cb@256bit.org>
parents:
11910
diff
changeset
|
163 let $OLD_PO_FILE_INPUT = 'yes' |
3b26420fc639
Long overdue runtime update.
Christian Brabandt <cb@256bit.org>
parents:
11910
diff
changeset
|
164 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
|
165 if v:shell_error != 0 |
39e46ae74c69
patch 8.0.0830: translating messages is not ideal
Christian Brabandt <cb@256bit.org>
parents:
11828
diff
changeset
|
166 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
|
167 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
|
168 endif |
39e46ae74c69
patch 8.0.0830: translating messages is not ideal
Christian Brabandt <cb@256bit.org>
parents:
11828
diff
changeset
|
169 endif |
39e46ae74c69
patch 8.0.0830: translating messages is not ideal
Christian Brabandt <cb@256bit.org>
parents:
11828
diff
changeset
|
170 |
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
|
171 " 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
|
172 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
|
173 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
|
174 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
|
175 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
|
176 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
|
177 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
|
178 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
|
179 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
|
180 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
|
181 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
|
182 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
|
183 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
|
184 " 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
|
185 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
|
186 |
14187
b79453d0d01c
patch 8.1.0111: .po files do not use recommended names
Christian Brabandt <cb@256bit.org>
parents:
13938
diff
changeset
|
187 " 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
|
188 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
|
189 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
|
190 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
|
191 if cte |
b79453d0d01c
patch 8.1.0111: .po files do not use recommended names
Christian Brabandt <cb@256bit.org>
parents:
13938
diff
changeset
|
192 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
|
193 " 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
|
194 " if error == 0 |
b79453d0d01c
patch 8.1.0111: .po files do not use recommended names
Christian Brabandt <cb@256bit.org>
parents:
13938
diff
changeset
|
195 " let error = cte |
b79453d0d01c
patch 8.1.0111: .po files do not use recommended names
Christian Brabandt <cb@256bit.org>
parents:
13938
diff
changeset
|
196 " endif |
b79453d0d01c
patch 8.1.0111: .po files do not use recommended names
Christian Brabandt <cb@256bit.org>
parents:
13938
diff
changeset
|
197 elseif ctc |
b79453d0d01c
patch 8.1.0111: .po files do not use recommended names
Christian Brabandt <cb@256bit.org>
parents:
13938
diff
changeset
|
198 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
|
199 " 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
|
200 " if error == 0 |
b79453d0d01c
patch 8.1.0111: .po files do not use recommended names
Christian Brabandt <cb@256bit.org>
parents:
13938
diff
changeset
|
201 " let error = ct |
b79453d0d01c
patch 8.1.0111: .po files do not use recommended names
Christian Brabandt <cb@256bit.org>
parents:
13938
diff
changeset
|
202 " endif |
b79453d0d01c
patch 8.1.0111: .po files do not use recommended names
Christian Brabandt <cb@256bit.org>
parents:
13938
diff
changeset
|
203 elseif ctu |
b79453d0d01c
patch 8.1.0111: .po files do not use recommended names
Christian Brabandt <cb@256bit.org>
parents:
13938
diff
changeset
|
204 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
|
205 " 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
|
206 " if error == 0 |
b79453d0d01c
patch 8.1.0111: .po files do not use recommended names
Christian Brabandt <cb@256bit.org>
parents:
13938
diff
changeset
|
207 " let error = ct |
b79453d0d01c
patch 8.1.0111: .po files do not use recommended names
Christian Brabandt <cb@256bit.org>
parents:
13938
diff
changeset
|
208 " endif |
b79453d0d01c
patch 8.1.0111: .po files do not use recommended names
Christian Brabandt <cb@256bit.org>
parents:
13938
diff
changeset
|
209 endif |
b79453d0d01c
patch 8.1.0111: .po files do not use recommended names
Christian Brabandt <cb@256bit.org>
parents:
13938
diff
changeset
|
210 |
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
|
211 |
461 | 212 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
|
213 " 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
|
214 call winrestview(wsv) |
9963
580f57b07547
commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents:
2484
diff
changeset
|
215 echomsg "OK" |
580f57b07547
commit https://github.com/vim/vim/commit/ec42059b78c1932a44f2bf36ac982109884dc7c7
Christian Brabandt <cb@256bit.org>
parents:
2484
diff
changeset
|
216 else |
14187
b79453d0d01c
patch 8.1.0111: .po files do not use recommended names
Christian Brabandt <cb@256bit.org>
parents:
13938
diff
changeset
|
217 " 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
|
218 exe error |
461 | 219 endif |
220 | |
2484
e037ee8698b3
Set 'wrapscan' when checking the .po files. (Mike Williams)
Bram Moolenaar <bram@vim.org>
parents:
1952
diff
changeset
|
221 let &wrapscan = s:save_wrapscan |
e037ee8698b3
Set 'wrapscan' when checking the .po files. (Mike Williams)
Bram Moolenaar <bram@vim.org>
parents:
1952
diff
changeset
|
222 unlet s:save_wrapscan |
e037ee8698b3
Set 'wrapscan' when checking the .po files. (Mike Williams)
Bram Moolenaar <bram@vim.org>
parents:
1952
diff
changeset
|
223 |
461 | 224 endif |