-
-
Notifications
You must be signed in to change notification settings - Fork 824
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24174 from totten/master-lang
Message Templates - Allow rendering & previewing of translated messages
- Loading branch information
Showing
11 changed files
with
423 additions
and
11 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
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,45 @@ | ||
<?php | ||
|
||
/** | ||
* Wrapper to swap in translated text. | ||
*/ | ||
class CRM_Core_BAO_TranslateGetWrapper { | ||
|
||
protected $fields; | ||
protected $translatedLanguage; | ||
|
||
/** | ||
* CRM_Core_BAO_TranslateGetWrapper constructor. | ||
* | ||
* This wrapper replaces values with configured translated values, if any exist. | ||
* | ||
* @param array $translated | ||
*/ | ||
public function __construct($translated) { | ||
$this->fields = $translated['fields']; | ||
$this->translatedLanguage = $translated['language']; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function fromApiInput($apiRequest) { | ||
return $apiRequest; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function toApiOutput($apiRequest, $result) { | ||
foreach ($result as &$value) { | ||
if (!isset($value['id'], $this->fields[$value['id']])) { | ||
continue; | ||
} | ||
$toSet = array_intersect_key($this->fields[$value['id']], $value); | ||
$value = array_merge($value, $toSet); | ||
$value['actual_language'] = $this->translatedLanguage; | ||
} | ||
return $result; | ||
} | ||
|
||
} |
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
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
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
Oops, something went wrong.