From 5feb57ef649563a5a62bb056d596cdef873852ec Mon Sep 17 00:00:00 2001 From: Vincent Klaiber Date: Fri, 20 May 2016 15:57:37 +0200 Subject: [PATCH] Add lang to trans helper --- CHANGELOG.md | 4 ++++ src/helpers.php | 11 ++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b0fa4a..00b5b44 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/helpers.php b/src/helpers.php index 6f0dd46..bce1352 100644 --- a/src/helpers.php +++ b/src/helpers.php @@ -17,7 +17,7 @@ * * @param array $groups * - * @throws BadFunctionCallException + * @throws \BadFunctionCallException * * @return void */ @@ -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); } }