-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add translator aware & ReturnKeyTranslator
- Loading branch information
Showing
4 changed files
with
53 additions
and
1 deletion.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace Packaged\I18n; | ||
|
||
use Packaged\I18n\Translators\Translator; | ||
|
||
interface TranslatorAware | ||
{ | ||
public function setTranslator(Translator $translator): self; | ||
|
||
public function getTranslator(): Translator; | ||
|
||
public function hasTranslator(): bool; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace Packaged\I18n; | ||
|
||
use Packaged\I18n\Translators\ReplacementsOnlyTranslator; | ||
use Packaged\I18n\Translators\Translator; | ||
|
||
trait TranslatorAwareTrait | ||
{ | ||
private ?Translator $_translator; | ||
|
||
public function setTranslator(Translator $translator): self | ||
{ | ||
$this->_translator = $translator; | ||
return $this; | ||
} | ||
|
||
public function getTranslator(): Translator | ||
{ | ||
return $this->_translator ?? new ReplacementsOnlyTranslator(); | ||
} | ||
|
||
public function hasTranslator(): bool | ||
{ | ||
return $this->_translator !== null; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
namespace Packaged\I18n\Translators; | ||
|
||
class ReturnKeyTranslator implements Translator | ||
{ | ||
public function _($msgId, $default, array $replacements = null, $choice = null) | ||
{ | ||
return $msgId; | ||
} | ||
} |