-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding translator interface and implementation
- Loading branch information
1 parent
a7be49f
commit 15573db
Showing
2 changed files
with
51 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace Solspace\Commons\Translators; | ||
|
||
class CraftTranslator implements TranslatorInterface | ||
{ | ||
/** | ||
* Translates a string | ||
* Replaces any variables in the $string with variables from $variables | ||
* User brackets to specify variables in string | ||
* | ||
* Example: | ||
* Translation string: "Hello, {firstName}!" | ||
* Variables: ["firstName": "Icarus"] | ||
* End result: "Hello, Icarus!" | ||
* | ||
* @param string $category | ||
* @param string $string | ||
* @param array $variables | ||
* | ||
* @return string | ||
*/ | ||
public function translate(string $category, string$string, array $variables = []): string | ||
{ | ||
return \Craft::t($category, $string, $variables); | ||
} | ||
} |
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,24 @@ | ||
<?php | ||
|
||
namespace Solspace\Commons\Translators; | ||
|
||
interface TranslatorInterface | ||
{ | ||
/** | ||
* Translates a string | ||
* Replaces any variables in the $string with variables from $variables | ||
* User brackets to specify variables in string | ||
* | ||
* Example: | ||
* Translation string: "Hello, {firstName}!" | ||
* Variables: ["firstName": "Icarus"] | ||
* End result: "Hello, Icarus!" | ||
* | ||
* @param string $category | ||
* @param string $string | ||
* @param array $variables | ||
* | ||
* @return string | ||
*/ | ||
public function translate(string $category, string $string, array $variables = []): string; | ||
} |