blob: 5a3a0e3f4631fc46e07b544a4c0611c7bc97ba14 [file] [log] [blame]
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00001" Vim script for checking .po files.
2"
Bram Moolenaar595f51c2008-06-09 12:46:00 +00003" 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".
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +00006
7if 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.
12func! 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
Bram Moolenaara5792f52005-11-23 21:25:05 +000023 " remove '%', not used for formatting.
24 let idline = substitute(idline, "'%'", '', 'g')
25
Bram Moolenaar1c6136a2009-09-11 11:00:05 +000026 " remove '%' used for plural forms.
27 let idline = substitute(idline, '\\nPlural-Forms: .\+;\\n', '', '')
28
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +000029 " remove everything but % items.
30 return substitute(idline, '[^%]*\(%[-+ #''.0-9*]*l\=[dsuxXpoc%]\)\=', '\1', 'g')
31endfunc
32
Bram Moolenaara411e5d2010-08-04 15:47:08 +020033" This only works when 'wrapscan' is set.
34let s:save_wrapscan = &wrapscan
35set wrapscan
36
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +000037" Start at the first "msgid" line.
381
39/^msgid
40let startline = line('.')
41let error = 0
42
43while 1
44 if getline(line('.') - 1) !~ "no-c-format"
45 let fromline = GetMline()
46 if getline('.') !~ '^msgstr'
47 echo 'Missing "msgstr" in line ' . line('.')
48 let error = 1
49 endif
50 let toline = GetMline()
51 if fromline != toline
52 echo 'Mismatching % in line ' . (line('.') - 1)
Bram Moolenaara5792f52005-11-23 21:25:05 +000053 echo 'msgid: ' . fromline
54 echo 'msgstr: ' . toline
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +000055 let error = 1
56 endif
57 endif
58
59 " Find next msgid.
60 " Wrap around at the end of the file, quit when back at the first one.
61 /^msgid
62 if line('.') == startline
63 break
64 endif
65endwhile
66
Bram Moolenaar595f51c2008-06-09 12:46:00 +000067" Check that error code in msgid matches the one in msgstr.
68"
69" Examples of mismatches found with msgid "E123: ..."
70" - msgstr "E321: ..." error code mismatch
71" - msgstr "W123: ..." warning instead of error
72" - msgstr "E123 ..." missing colon
73" - msgstr "..." missing error code
74"
751
76if search('msgid "\("\n"\)\?\([EW][0-9]\+:\).*\nmsgstr "\("\n"\)\?[^"]\@=\2\@!') > 0
77 echo 'Mismatching error/warning code in line ' . line('.')
78 let error = 1
79endif
80
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +000081if error == 0
82 echo "OK"
83endif
84
Bram Moolenaara411e5d2010-08-04 15:47:08 +020085let &wrapscan = s:save_wrapscan
86unlet s:save_wrapscan
87
Bram Moolenaar1d94f9b2005-08-04 21:29:45 +000088endif