Let your WordPress theme support gettext

Has anyone tried translating your wordpress theme, using gettext?

I found I had to add a callback to the gettext filter in order to have wordpress recognize my *.mo files:


add_filter('gettext','patched_translate', 10, 3);

function patched_translate($translations, $text, $domain = 'default'){
  $translations = get_translations_for_domain( $domain );
  if($domain == 'default'){
    return $translations->translate($text);
  }
  $translation = $translations->translate( $domain.chr(4).$text );
  if($translation == $domain.chr(4).$text){
    return $text;
  }
  return $translation;
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: