Skip to content

Commit 5feb57e

Browse files
committed
Add lang to trans helper
1 parent e00f25c commit 5feb57e

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# CHANGELOG
22

3+
## 1.0.1 (released 2016-05-20)
4+
5+
- Add lang to trans helper
6+
37
## 1.0.0 (released 2016-05-11)
48

59
- First stable release

src/helpers.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*
1818
* @param array $groups
1919
*
20-
* @throws BadFunctionCallException
20+
* @throws \BadFunctionCallException
2121
*
2222
* @return void
2323
*/
@@ -40,17 +40,22 @@ function register_translations(array $groups)
4040
* Get translations by their strings.
4141
*
4242
* @param string $key
43+
* @param string|null $lang
4344
*
44-
* @throws BadFunctionCallException
45+
* @throws \BadFunctionCallException
4546
*
4647
* @return string
4748
*/
48-
function trans($key)
49+
function trans($key, $lang = null)
4950
{
5051
if (!function_exists('pll__')) {
5152
throw new BadFunctionCallException('Please active the Polylang plugin.');
5253
}
5354

55+
if ($lang) {
56+
return pll_translate_string($key, $lang);
57+
}
58+
5459
return pll__($key);
5560
}
5661
}

0 commit comments

Comments
 (0)