Skip to content

Commit

Permalink
Add lang to trans helper
Browse files Browse the repository at this point in the history
  • Loading branch information
vinkla committed May 20, 2016
1 parent e00f25c commit 5feb57e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## 1.0.1 (released 2016-05-20)

- Add lang to trans helper

## 1.0.0 (released 2016-05-11)

- First stable release
11 changes: 8 additions & 3 deletions src/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*
* @param array $groups
*
* @throws BadFunctionCallException
* @throws \BadFunctionCallException
*
* @return void
*/
Expand All @@ -40,17 +40,22 @@ function register_translations(array $groups)
* Get translations by their strings.
*
* @param string $key
* @param string|null $lang
*
* @throws BadFunctionCallException
* @throws \BadFunctionCallException
*
* @return string
*/
function trans($key)
function trans($key, $lang = null)
{
if (!function_exists('pll__')) {
throw new BadFunctionCallException('Please active the Polylang plugin.');
}

if ($lang) {
return pll_translate_string($key, $lang);
}

return pll__($key);
}
}

0 comments on commit 5feb57e

Please sign in to comment.