461
|
1 " Vim script for checking .po files.
|
|
2 "
|
|
3 " Go through the file and verify that all %...s items in "msgid" are identical
|
|
4 " to the ones in "msgstr".
|
|
5
|
|
6 if 1 " Only execute this if the eval feature is available.
|
|
7
|
|
8 " Function to get a split line at the cursor.
|
|
9 " Used for both msgid and msgstr lines.
|
|
10 " Removes all text except % items and returns the result.
|
|
11 func! GetMline()
|
|
12 let idline = substitute(getline('.'), '"\(.*\)"$', '\1', '')
|
|
13 while line('.') < line('$')
|
|
14 +
|
|
15 let line = getline('.')
|
|
16 if line[0] != '"'
|
|
17 break
|
|
18 endif
|
|
19 let idline .= substitute(line, '"\(.*\)"$', '\1', '')
|
|
20 endwhile
|
|
21
|
557
|
22 " remove '%', not used for formatting.
|
|
23 let idline = substitute(idline, "'%'", '', 'g')
|
|
24
|
461
|
25 " remove everything but % items.
|
|
26 return substitute(idline, '[^%]*\(%[-+ #''.0-9*]*l\=[dsuxXpoc%]\)\=', '\1', 'g')
|
|
27 endfunc
|
|
28
|
|
29 " Start at the first "msgid" line.
|
|
30 1
|
|
31 /^msgid
|
|
32 let startline = line('.')
|
|
33 let error = 0
|
|
34
|
|
35 while 1
|
|
36 if getline(line('.') - 1) !~ "no-c-format"
|
|
37 let fromline = GetMline()
|
|
38 if getline('.') !~ '^msgstr'
|
|
39 echo 'Missing "msgstr" in line ' . line('.')
|
|
40 let error = 1
|
|
41 endif
|
|
42 let toline = GetMline()
|
|
43 if fromline != toline
|
|
44 echo 'Mismatching % in line ' . (line('.') - 1)
|
557
|
45 echo 'msgid: ' . fromline
|
|
46 echo 'msgstr: ' . toline
|
461
|
47 let error = 1
|
|
48 endif
|
|
49 endif
|
|
50
|
|
51 " Find next msgid.
|
|
52 " Wrap around at the end of the file, quit when back at the first one.
|
|
53 /^msgid
|
|
54 if line('.') == startline
|
|
55 break
|
|
56 endif
|
|
57 endwhile
|
|
58
|
|
59 if error == 0
|
|
60 echo "OK"
|
|
61 endif
|
|
62
|
|
63 endif
|