Skip to content

Commit ae210ce

Browse files
committed
feat: ajout du trait Translatable pour traduire
1 parent 3421562 commit ae210ce

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

Support/Translatable.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
/**
4+
* This file is part of Blitz PHP framework.
5+
*
6+
* (c) 2022 Dimitri Sitchet Tomkeu <devcode.dst@gmail.com>
7+
*
8+
* For the full copyright and license information, please view
9+
* the LICENSE file that was distributed with this source code.
10+
*/
11+
12+
namespace BlitzPHP\Traits\Support;
13+
14+
use BlitzPHP\Translator\Translate;
15+
16+
/**
17+
* Trait pour les traductions
18+
* Necessite l'installation du package `blitz-php/translator`
19+
*/
20+
trait Translatable
21+
{
22+
protected string $_locale = 'en';
23+
24+
private ?Translate $translator = null;
25+
26+
/**
27+
* Analyse la chaîne de langue d'un fichier, charge le fichier, si nécessaire, et obtient la traduction souhaitée.
28+
*
29+
* @return string|string[]
30+
*/
31+
public function translate(string $line, array $args)
32+
{
33+
return $this->translator()->getLine($line, $args);
34+
}
35+
36+
/**
37+
* Instance du traducteur
38+
*/
39+
protected function translator(): Translate
40+
{
41+
if (null !== $this->translator) {
42+
return $this->translator;
43+
}
44+
45+
return $this->translator = new Translate($this->_locale ?? 'en');
46+
}
47+
}

0 commit comments

Comments
 (0)