Adds helper method to translate shortcodes
Adds translations to Date shortcode
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user