Created
July 21, 2014 09:31
-
-
Save ivankravchenko/43ef686145aeed9c39b5 to your computer and use it in GitHub Desktop.
wordpress translate helper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* tr – translation helper | |
* examples: | |
* tr("Hello") -> "Привіт" // simply translates given string | |
* tr("%s products", $category) -> "Продукти категорії " // translates format and uses sprintf for substitutions | |
* tr(array("%d comment", "%d comments"), $commentCount) -> "1 comment" // pluralized format version | |
*/ | |
function tr() { | |
$context = 'theme'; | |
$args = func_get_args(); | |
if (count($args) == 0) throw new ErrorException("Incorrect tr() usage."); | |
$phrase = array_shift($args); | |
if (is_string($phrase)) { | |
$phrase = __($phrase, $context); | |
} elseif (is_array($phrase) && count($phrase) == 2 && count($argv) > 0) { | |
$phrase = _n($phrase, $context, $args[0]); | |
} | |
if (count($args) > 0) { | |
return call_user_func_array('sprintf', array_merge(array($phrase), $args)); | |
} else { | |
return $phrase; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment