Skip to content

Commit

Permalink
Adding translator interface and implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavs-gutmanis committed Feb 28, 2019
1 parent a7be49f commit 15573db
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/Translators/CraftTranslator.php
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);
}
}
24 changes: 24 additions & 0 deletions src/Translators/TranslatorInterface.php
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;
}

0 comments on commit 15573db

Please sign in to comment.