view src/po/check.vim @ 625:81fe2ccc1207 v7.0179

updated for version 7.0179
author vimboss
date Thu, 12 Jan 2006 23:22:24 +0000
parents 862863033fdd
children 2f016b638c0c
line wrap: on
line source

" Vim script for checking .po files.
"
" Go through the file and verify that all %...s items in "msgid" are identical
" to the ones in "msgstr".

if 1	" Only execute this if the eval feature is available.

" Function to get a split line at the cursor.
" Used for both msgid and msgstr lines.
" Removes all text except % items and returns the result.
func! GetMline()
  let idline = substitute(getline('.'), '"\(.*\)"$', '\1', '')
  while line('.') < line('$')
    +
    let line = getline('.')
    if line[0] != '"'
      break
    endif
    let idline .= substitute(line, '"\(.*\)"$', '\1', '')
  endwhile

  " remove '%', not used for formatting.
  let idline = substitute(idline, "'%'", '', 'g')

  " remove everything but % items.
  return substitute(idline, '[^%]*\(%[-+ #''.0-9*]*l\=[dsuxXpoc%]\)\=', '\1', 'g')
endfunc

" Start at the first "msgid" line.
1
/^msgid
let startline = line('.')
let error = 0

while 1
  if getline(line('.') - 1) !~ "no-c-format"
    let fromline = GetMline()
    if getline('.') !~ '^msgstr'
      echo 'Missing "msgstr" in line ' . line('.')
      let error = 1
    endif
    let toline = GetMline()
    if fromline != toline
      echo 'Mismatching % in line ' . (line('.') - 1)
      echo 'msgid: ' . fromline
      echo 'msgstr: ' . toline
      let error = 1
    endif
  endif

  " Find next msgid.
  " Wrap around at the end of the file, quit when back at the first one.
  /^msgid
  if line('.') == startline
    break
  endif
endwhile

if error == 0
  echo "OK"
endif

endif