blob: a5f25aa0b2c36429f29ef186d4ab52bbc400a437 [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
22 " remove everything but % items.
23 return substitute(idline, '[^%]*\(%[-+ #''.0-9*]*l\=[dsuxXpoc%]\)\=', '\1', 'g')
24endfunc
25
26" Start at the first "msgid" line.
271
28/^msgid
29let startline = line('.')
30let error = 0
31
32while 1
33 if getline(line('.') - 1) !~ "no-c-format"
34 let fromline = GetMline()
35 if getline('.') !~ '^msgstr'
36 echo 'Missing "msgstr" in line ' . line('.')
37 let error = 1
38 endif
39 let toline = GetMline()
40 if fromline != toline
41 echo 'Mismatching % in line ' . (line('.') - 1)
42 let error = 1
43 endif
44 endif
45
46 " Find next msgid.
47 " Wrap around at the end of the file, quit when back at the first one.
48 /^msgid
49 if line('.') == startline
50 break
51 endif
52endwhile
53
54if error == 0
55 echo "OK"
56endif
57
58endif