2019-03-25 19:27:10 +08:00
|
|
|
" MIT License. Copyright (c) 2013-2019 Bailey Ling, Christian Brabandt et al.
|
2016-03-01 05:38:39 +08:00
|
|
|
" vim: et ts=2 sts=2 sw=2
|
|
|
|
|
2016-09-24 08:16:30 +08:00
|
|
|
scriptencoding utf-8
|
|
|
|
|
2017-08-23 05:21:19 +08:00
|
|
|
function! airline#extensions#po#shorten()
|
2018-11-01 17:39:33 +08:00
|
|
|
" Format and shorte the output of msgfmt
|
|
|
|
let b:airline_po_stats = substitute(get(b:, 'airline_po_stats', ''), ' \(message\|translation\)s*\.*', '', 'g')
|
|
|
|
let b:airline_po_stats = substitute(b:airline_po_stats, ', ', '/', 'g')
|
2016-09-29 04:01:07 +08:00
|
|
|
if exists("g:airline#extensions#po#displayed_limit")
|
|
|
|
let w:displayed_po_limit = g:airline#extensions#po#displayed_limit
|
|
|
|
if len(b:airline_po_stats) > w:displayed_po_limit - 1
|
|
|
|
let b:airline_po_stats = b:airline_po_stats[0:(w:displayed_po_limit - 2)].(&encoding==?'utf-8' ? '…' : '.'). ']'
|
|
|
|
endif
|
|
|
|
endif
|
2019-02-04 00:30:55 +08:00
|
|
|
if strlen(get(b:, 'airline_po_stats', '')) >= 30 && airline#util#winwidth() < 150
|
2018-11-01 17:39:33 +08:00
|
|
|
let fuzzy = ''
|
|
|
|
let untranslated = ''
|
|
|
|
let messages = ''
|
|
|
|
" Shorten [120 translated, 50 fuzzy, 4 untranslated] to [120T/50F/4U]
|
2018-11-01 18:14:57 +08:00
|
|
|
if b:airline_po_stats =~ 'fuzzy'
|
2018-11-01 17:39:33 +08:00
|
|
|
let fuzzy = substitute(b:airline_po_stats, '.*\(\d\+\) fuzzy.*', '\1F', '')
|
2019-09-09 15:39:41 +08:00
|
|
|
if fuzzy == '0F'
|
|
|
|
let fuzzy = ''
|
|
|
|
endif
|
2018-11-01 18:14:57 +08:00
|
|
|
endif
|
|
|
|
if b:airline_po_stats =~ 'untranslated'
|
2018-11-01 17:39:33 +08:00
|
|
|
let untranslated = substitute(b:airline_po_stats, '.*\(\d\+\) untranslated.*', '\1U', '')
|
2019-09-09 15:39:41 +08:00
|
|
|
if untranslated == '0U'
|
|
|
|
let untranslated = ''
|
|
|
|
endif
|
2018-11-01 17:39:33 +08:00
|
|
|
endif
|
|
|
|
let messages = substitute(b:airline_po_stats, '\(\d\+\) translated.*', '\1T', '')
|
|
|
|
let b:airline_po_stats = printf('%s%s%s', fuzzy, (empty(fuzzy) || empty(untranslated) ? '' : '/'), untranslated)
|
|
|
|
if strlen(b:airline_po_stats) < 8
|
|
|
|
let b:airline_po_stats = messages. (!empty(b:airline_po_stats) ? '/':''). b:airline_po_stats
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
let b:airline_po_stats = '['.b:airline_po_stats. ']'
|
2016-09-29 04:01:07 +08:00
|
|
|
endfunction
|
|
|
|
|
2018-11-01 18:18:04 +08:00
|
|
|
function! airline#extensions#po#on_winenter()
|
|
|
|
" only reset cache, if the window size changed
|
2019-02-04 00:30:55 +08:00
|
|
|
if get(b:, 'airline_winwidth', 0) != airline#util#winwidth()
|
|
|
|
let b:airline_winwidth = airline#util#winwidth()
|
2018-11-01 18:18:04 +08:00
|
|
|
" needs re-formatting
|
|
|
|
unlet! b:airline_po_stats
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2016-03-01 05:38:39 +08:00
|
|
|
function! airline#extensions#po#apply(...)
|
|
|
|
if &ft ==# 'po'
|
|
|
|
call airline#extensions#prepend_to_section('z', '%{airline#extensions#po#stats()}')
|
2018-11-01 17:39:33 +08:00
|
|
|
" Also reset the cache variable, if a window has been split, e.g. the winwidth changed
|
2018-11-01 18:18:04 +08:00
|
|
|
autocmd airline BufWritePost * unlet! b:airline_po_stats
|
|
|
|
autocmd airline WinEnter * call airline#extensions#po#on_winenter()
|
2016-03-01 05:38:39 +08:00
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! airline#extensions#po#stats()
|
|
|
|
if exists('b:airline_po_stats') && !empty(b:airline_po_stats)
|
|
|
|
return b:airline_po_stats
|
|
|
|
endif
|
|
|
|
|
2016-09-29 04:01:07 +08:00
|
|
|
let cmd = 'msgfmt --statistics -o /dev/null -- '
|
2017-08-24 00:10:59 +08:00
|
|
|
if g:airline#init#vim_async
|
2017-08-23 05:21:19 +08:00
|
|
|
call airline#async#get_msgfmt_stat(cmd, expand('%:p'))
|
2017-08-23 06:00:47 +08:00
|
|
|
elseif has("nvim")
|
|
|
|
call airline#async#nvim_get_msgfmt_stat(cmd, expand('%:p'))
|
2016-09-29 04:01:07 +08:00
|
|
|
else
|
|
|
|
let airline_po_stats = system(cmd. shellescape(expand('%:p')))
|
|
|
|
if v:shell_error
|
|
|
|
return ''
|
2016-03-01 05:38:39 +08:00
|
|
|
endif
|
2016-09-29 04:01:07 +08:00
|
|
|
try
|
2018-11-01 17:39:33 +08:00
|
|
|
let b:airline_po_stats = split(airline_po_stats, '\n')[0]
|
2016-09-29 04:01:07 +08:00
|
|
|
catch
|
|
|
|
let b:airline_po_stats = ''
|
|
|
|
endtry
|
2017-08-23 05:21:19 +08:00
|
|
|
call airline#extensions#po#shorten()
|
2016-03-01 05:38:39 +08:00
|
|
|
endif
|
2016-09-29 04:01:07 +08:00
|
|
|
return get(b:, 'airline_po_stats', '')
|
2016-03-01 05:38:39 +08:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! airline#extensions#po#init(ext)
|
|
|
|
call a:ext.add_statusline_func('airline#extensions#po#apply')
|
|
|
|
endfunction
|