Skip to content

Commit

Permalink
feat: translate answers for targets and notifications
Browse files Browse the repository at this point in the history
Signed-off-by: Thierry Bugier <tbugier@teclib.com>
  • Loading branch information
btry committed Feb 15, 2021
1 parent f73aa11 commit 9b30339
Show file tree
Hide file tree
Showing 20 changed files with 37 additions and 29 deletions.
3 changes: 2 additions & 1 deletion inc/field/actorfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@ public function getValueForDesign(): string {
return implode("\r\n", $value);
}

public function getValueForTargetText($richText): string {
public function getValueForTargetText($domain, $richText): string
{
$value = [];
foreach ($this->value as $item) {
if (filter_var($item, FILTER_VALIDATE_EMAIL) !== false) {
Expand Down
5 changes: 3 additions & 2 deletions inc/field/checkboxesfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,8 @@ public function hasInput($input): bool {
return isset($input['formcreator_field_' . $this->question->getID()]);
}

public function getValueForTargetText($richText): string {
public function getValueForTargetText($domain, $richText): string
{
$value = [];
$values = $this->getAvailableValues();

Expand All @@ -290,7 +291,7 @@ public function getValueForTargetText($richText): string {

foreach ($this->value as $input) {
if (in_array($input, $values)) {
$value[] = $input;
$value[] = __($input, $domain);
}
}

Expand Down
2 changes: 1 addition & 1 deletion inc/field/datefield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public function getValueForDesign(): string {
return $this->value;
}

public function getValueForTargetText($richText): string {
public function getValueForTargetText($domain, $richText): string {
return Html::convDate($this->value);
}

Expand Down
2 changes: 1 addition & 1 deletion inc/field/datetimefield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public function hasInput($input): bool {
return isset($input['formcreator_field_' . $this->question->getID()]);
}

public function getValueForTargetText($richText): string {
public function getValueForTargetText($domain, $richText): string {
return Html::convDateTime($this->value);
}

Expand Down
5 changes: 3 additions & 2 deletions inc/field/descriptionfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,11 @@ public function getValueForDesign(): string {
return '';
}

public function getValueForTargetText($richText): string {
public function getValueForTargetText($domain, $richText): string
{
$text = $this->question->fields['description'];
if (!$richText) {
$text = nl2br(strip_tags(html_entity_decode($text)));
$text = nl2br(strip_tags(html_entity_decode(__($text, $domain))));
}

return $text;
Expand Down
3 changes: 2 additions & 1 deletion inc/field/dropdownfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,8 @@ public function getValueForDesign(): string {
return $this->value;
}

public function getValueForTargetText($richText): string {
public function getValueForTargetText($domain, $richText): string
{
$DbUtil = new DbUtils();
$itemtype = $this->getSubItemtype();
if ($itemtype == User::class) {
Expand Down
3 changes: 2 additions & 1 deletion inc/field/filefield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ public function getValueForDesign(): string {
return '';
}

public function getValueForTargetText($richText): string {
public function getValueForTargetText($domain, $richText): string
{
return $this->value;
}

Expand Down
2 changes: 1 addition & 1 deletion inc/field/floatfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public function getValueForDesign(): string {
return $this->value;
}

public function getValueForTargetText($richText): string {
public function getValueForTargetText($domain, $richText): string {
return $this->value;
}

Expand Down
2 changes: 1 addition & 1 deletion inc/field/hiddenfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public static function getName(): string {
return _n('Hidden field', 'Hidden fields', 1);
}

public function getValueForTargetText($richText): string {
public function getValueForTargetText($domain, $richText): string {
return str_replace("\n", '\r\n', $this->value);
}

Expand Down
2 changes: 1 addition & 1 deletion inc/field/hostnamefield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function getValueForDesign(): string {
return '';
}

public function getValueForTargetText($richText): string {
public function getValueForTargetText($domain, $richText): string {
return $this->value;
}

Expand Down
2 changes: 1 addition & 1 deletion inc/field/ipfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function getValueForDesign(): string {
return $this->value;
}

public function getValueForTargetText($richText): string {
public function getValueForTargetText($domain, $richText): string {
return $this->value;
}

Expand Down
9 changes: 3 additions & 6 deletions inc/field/radiosfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,8 @@ public function parseDefaultValue($defaultValue) {
$this->value = array_shift($this->value);
}

<<<<<<< HEAD
public function serializeValue():string {
=======
public function serializeValue(): string
{
>>>>>>> f10ec68e... feat: translatable forms
if ($this->value === null || $this->value === '') {
return '';
}
Expand All @@ -224,8 +220,9 @@ public function getValueForDesign(): string {
return $this->value;
}

public function getValueForTargetText($richText): string {
return $this->value;
public function getValueForTargetText($domain, $richText): string
{
return __($this->value, $domain);
}

public function moveUploads() {
Expand Down
2 changes: 1 addition & 1 deletion inc/field/requesttypefield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public function hasInput($input): bool {
return isset($input['formcreator_field_' . $this->question->getID()]);
}

public function getValueForTargetText($richText): string {
public function getValueForTargetText($domain, $richText): string {
$available = $this->getAvailableValues();
return $available[$this->value];
}
Expand Down
3 changes: 2 additions & 1 deletion inc/field/tagfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ public function getValueForDesign(): string {
return implode("\r\n", $this->value);
}

public function getValueForTargetText($richText): string {
public function getValueForTargetText($domain, $richText): string
{
$value = Dropdown::getDropdownName(PluginTagTag::getTable(), $this->value);
return $value;
}
Expand Down
2 changes: 1 addition & 1 deletion inc/field/textareafield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ public function parseAnswerValues($input, $nonDestructive = false): bool {
return true;
}

public function getValueForTargetText($richText): string {
public function getValueForTargetText($domain, $richText): string {
$value = $this->value;
if (!$richText) {
$value = Toolbox::unclean_cross_side_scripting_deep($value);
Expand Down
2 changes: 1 addition & 1 deletion inc/field/textfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public function getValueForDesign(): string {
return $this->value;
}

public function getValueForTargetText($richText): string {
public function getValueForTargetText($domain, $richText): string {
return $this->value;
}

Expand Down
6 changes: 4 additions & 2 deletions inc/field/timefield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ public function getDesignSpecializationField(): array {
];
}

public function getRenderedHtml($domain, $canEdit = true): string {
public function getRenderedHtml($domain, $canEdit = true): string
{
if (!$canEdit) {
return $this->value;
}
Expand Down Expand Up @@ -117,7 +118,8 @@ public function getValueForDesign(): string {
return $this->value;
}

public function getValueForTargetText($richText): string {
public function getValueForTargetText($domain, $richText): string
{
$date = DateTime::createFromFormat("H:i:s", $this->value);
if ($date === false) {
return ' ';
Expand Down
3 changes: 2 additions & 1 deletion inc/field/urgencyfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ public function getValueForDesign(): string {
return $this->value;
}

public function getValueForTargetText($richText): string {
public function getValueForTargetText($domain, $richText): string
{
$available = $this->getAvailableValues();
return $available[$this->value];
}
Expand Down
5 changes: 3 additions & 2 deletions inc/fieldinterface.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,12 @@ public function getValueForDesign() : string;
/**
* Get the value of the field for display in a target
*
* @param boolean $richText Enable rich text mode for field rendering
* @param string $domain locales domain
* @param boolean $richText Enable rich text mode for field rendering
*
* @return string
*/
public function getValueForTargetText($richText) : string;
public function getValueForTargetText($domain, $richText): string;

/**
* Move uploaded files and make Document items
Expand Down
3 changes: 2 additions & 1 deletion inc/formanswer.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1094,14 +1094,15 @@ public function parseTags($content, PluginFormcreatorTargetInterface $target = n
$form = $this->getForm();
$this->getQuestionFields($form->getID());
$this->deserializeAnswers();
$domain = PluginFormcreatorForm::getTranslationDomain($form->getID());

foreach ($this->questionFields as $questionId => $field) {
$question = $field->getQuestion();
$name = '';
$value = '';
if (PluginFormcreatorFields::isVisible($question, $this->questionFields)) {
$name = $question->fields['name'];
$value = $this->questionFields[$questionId]->getValueForTargetText($richText);
$value = $this->questionFields[$questionId]->getValueForTargetText($domain, $richText);
}

$content = str_replace('##question_' . $questionId . '##', Toolbox::addslashes_deep($name), $content);
Expand Down

0 comments on commit 9b30339

Please sign in to comment.