1 " Vim script for checking .po files.
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".
7 if 1 " Only execute this if the eval feature is available.
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.
13 let idline = substitute(getline('.'), '"\(.*\)"$', '\1', '')
14 while line('.') < line('$')
16 let line = getline('.')
20 let idline .= substitute(line, '"\(.*\)"$', '\1', '')
23 " remove '%', not used for formatting.
24 let idline = substitute(idline, "'%'", '', 'g')
26 " remove everything but % items.
27 return substitute(idline, '[^%]*\(%[-+ #''.0-9*]*l\=[dsuxXpoc%]\)\=', '\1', 'g')
30 " Start at the first "msgid" line.
33 let startline = line('.')
37 if getline(line('.') - 1) !~ "no-c-format"
38 let fromline = GetMline()
39 if getline('.') !~ '^msgstr'
40 echo 'Missing "msgstr" in line ' . line('.')
43 let toline = GetMline()
45 echo 'Mismatching % in line ' . (line('.') - 1)
46 echo 'msgid: ' . fromline
47 echo 'msgstr: ' . toline
53 " Wrap around at the end of the file, quit when back at the first one.
55 if line('.') == startline
60 " Check that error code in msgid matches the one in msgstr.
62 " Examples of mismatches found with msgid "E123: ..."
63 " - msgstr "E321: ..." error code mismatch
64 " - msgstr "W123: ..." warning instead of error
65 " - msgstr "E123 ..." missing colon
66 " - msgstr "..." missing error code
69 if search('msgid "\("\n"\)\?\([EW][0-9]\+:\).*\nmsgstr "\("\n"\)\?[^"]\@=\2\@!') > 0
70 echo 'Mismatching error/warning code in line ' . line('.')