I’m working on a website and we decided to localize it using GNU gettext. Soon enough I found it tiring to wrap each string manually in _(
and )
and also to do it in Smarty (using {t}string{/t}
. So I decided that I need a macro that will let highlight the string that needs translation and the macro will wrap for me.
I ended up writing two macros one for PHP files (but it’s also good for C/C++ etc.) and one for smarty.
:vmap tg di_(<ESC>pa)<ESC> :vmap ts di{t}<ESC>pa{/t}<ESC>
To use these macros just highlight the string for translation in vim’s visual mode and press tg
(or ts
), and your string will be wrapped for translation.