Archive for the ‘Gettext’ tag
Question Marks Instead of Non-ASCII Chars when using Gettext in PHP
Yesterday I’ve ported a PHP website to use Gettext for localizations (l10n). After reading through the Gettext documentation and going through the documentation in the PHP site, I’ve manged to get everything working (almost). I had one problem, all the non-ASCII characters (accented Latin chars, Japanese and Chinese) where displayed as question marks (?) instead of the correct form. This happend despite me using UTF-8 encoded files.
While some people (e.g. this one) suggested that it’s not possible to use non-ASCII characters when using a UTF-8 encoded message files, their is a soultion and it’s quiet simple one. All you have to do is to call bind_textdomain_codset and pass it UTF-8 as charset.
Vim Macros for Wrapping Strings for Gettext
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.