Adds helper method to translate shortcodes

Adds translations to Date shortcode
This commit is contained in:
Vlad
2017-08-09 18:42:14 -04:00
parent 849a24ced7
commit fb5d43e975
4 changed files with 117 additions and 6 deletions

View File

@@ -1,4 +1,5 @@
<?php
namespace MailPoet\Newsletter\Shortcodes;
use MailPoet\Models\CustomField;
@@ -115,11 +116,24 @@ class ShortcodesHelper {
static function getCustomFields() {
$custom_fields = CustomField::findMany();
if(!$custom_fields) return false;
return array_map(function ($custom_field) {
return array_map(function($custom_field) {
return array(
'text' => $custom_field->name,
'shortcode' => '[subscriber:cf_' . $custom_field->id . ']'
);
}, $custom_fields);
}
static function translateShortcode($translations, $shortcode) {
$translations = self::prepareTranslations($translations);
return str_replace(array_keys($translations), array_values($translations), $shortcode);
}
static function prepareTranslations($translations = array()) {
$prepared_translations = array();
foreach($translations as $key => $translation) {
$prepared_translations[$key] = __($translation, 'mailpoet');
}
return $prepared_translations;
}
}