blob: 50ed9a40f12d3014f23dd21b5ceb57e8d36a62d7 [file] [log] [blame]
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00001" 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
6if 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.
11func! 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
Bram Moolenaara5792f52005-11-23 21:25:05 +000022 " remove '%', not used for formatting.
23 let idline = substitute(idline, "'%'", '', 'g')
24
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +000025 " remove everything but % items.
26 return substitute(idline, '[^%]*\(%[-+ #''.0-9*]*l\=[dsuxXpoc%]\)\=', '\1', 'g')
27endfunc
28
29" Start at the first "msgid" line.
301
31/^msgid
32let startline = line('.')
33let error = 0
34
35while 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)
Bram Moolenaara5792f52005-11-23 21:25:05 +000045 echo 'msgid: ' . fromline
46 echo 'msgstr: ' . toline
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +000047 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
57endwhile
58
59if error == 0
60 echo "OK"
61endif
62
63endif