You are here

public static function OffsetFilterTranslator::translate in Persian Date for Drupal 8 8.4

Parameters

$text string Text to translate:

Return value

string Translated text

2 calls to OffsetFilterTranslator::translate()
Date::opBetween in src/Plugin/views/filter/Date.php
Filters by operator between.
Date::opSimple in src/Plugin/views/filter/Date.php

File

src/Service/Translation/OffsetFilterTranslator.php, line 11

Class

OffsetFilterTranslator

Namespace

Drupal\persian_date\Service\Translation

Code

public static function translate($text) {
  $text = trim(preg_replace('/\\s+/', ' ', $text));
  $text = self::standardPersianInput($text);
  $translations = self::translations();
  foreach ($translations['strict'] as $english_word => $persian_words) {
    foreach ($persian_words as $persian_word) {
      if ($text === $persian_word) {
        $text = str_replace($persian_word, $english_word, $text);
      }
    }
  }
  foreach ($translations['relative'] as $english_word => $persian_words) {
    foreach ($persian_words as $persian_word) {
      $text = str_replace($persian_word, $english_word, $text);
    }
  }
  return $text;
}