Replace non-latin chars to latin pairs

@param string $original_text
@param int    $max_length maximum length of converted string

@return string
182810
public static function text2uid($original_text, $max_length = 30): string
    {
        $original_text = mb_strtolower($original_text, 'utf-8');

        // Changes from east language
        $original_text = str_replace(
            [' - ', ' ', '&', ':', 'æ', 'ǽ', 'é', 'è', 'ê', 'ē', 'ë', 'ĕ', 'ė', 'ę', 'ě', 'е', 'э', 'ё', 'ø', 'œ', 'ö', 'ó', 'ò', 'ô', 'о', 'ä', 'â', 'å', 'à', 'á', 'ā', 'ã', 'ǻ', 'ă', 'ą', 'ǎ', 'ª', 'а', 'ă', 'ü', 'ū', 'у', 'і', 'ī', 'ï', 'î', 'ì', 'í', 'ï', 'ĭ', 'ǐ', 'ı', 'į', 'ы', 'и', 'š', 'ш', 'щ', 'ģ', 'ĝ', 'ğ', 'ġ', 'ґ', 'г', 'ķ', 'к', 'ļ', 'ĺ', 'ľ', 'ŀ', 'ł', 'л', 'ž', 'ж', 'č', 'ч', 'ņ', 'ñ', 'ń', 'ņ', 'ň', 'ŉ', 'н', 'й', 'ц', 'з', 'ĥ', 'ħ', 'х', 'ф', 'в', 'п', 'р', 'д', 'я', 'с', 'ș', 'м', 'т', 'ț', 'б', 'ю', '.', ',', 'ъ', 'ь', 'ç', 'ć', 'ć', 'ć', 'ð', 'ð', 'đ', 'ĵ'],
            ['-', '-', '-and-', '-', 'ae', 'ae', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'e', 'oe', 'o', 'o', 'o', 'o', 'o', 'o', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'u', 'u', 'u', 'i', 'i', 'i', 'i', 'i', 'i', 'i', 'i', 'i', 'i', 'i', 'i', 'i', 'sh', 'sh', 'sh', 'g', 'g', 'g', 'g', 'g', 'g', 'k', 'k', 'l', 'l', 'l', 'l', 'l', 'l', 'zh', 'zh', 'ch', 'ch', 'n', 'n', 'n', 'n', 'n', 'n', 'n', 'y', 'c', 'z', 'h', 'h', 'h', 'f', 'v', 'p', 'r', 'd', 'ya', 's', 's', 'm', 't', 't', 'b', 'yu', '-', '-', '', '', 'c', 'c', 'c', 'c', 'd', 'd', 'd', 'j'],
            $original_text
        );

        // Changes from west languages
        $transliteration = [
            'ä' => 'ae',
            'æ' => 'ae',
            'ǽ' => 'ae',
            'ö' => 'oe',
            'œ' => 'oe',
            'ü' => 'ue',
            'Ä' => 'Ae',
            'Ü' => 'Ue',
            'Ö' => 'Oe',
            'À' => 'A',
            'Á' => 'A',
            'Â' => 'A',
            'Ã' => 'A',
            'Å' => 'A',
            'Ǻ' => 'A',
            'Ā' => 'A',
            'Ă' => 'A',
            'Ą' => 'A',
            'Ǎ' => 'A',
            'à' => 'a',
            'á' => 'a',
            'â' => 'a',
            'ã' => 'a',
            'å' => 'a',
            'ǻ' => 'a',
            'ā' => 'a',
            'ă' => 'a',
            'ą' => 'a',
            'ǎ' => 'a',
            'ª' => 'a',
            'Ç' => 'C',
            'Ć' => 'C',
            'Ĉ' => 'C',
            'Ċ' => 'C',
            'Č' => 'C',
            'ç' => 'c',
            'ć' => 'c',
            'ĉ' => 'c',
            'ċ' => 'c',
            'č' => 'c',
            'Ð' => 'D',
            'Ď' => 'D',
            'Đ' => 'D',
            'ð' => 'd',
            'ď' => 'd',
            'đ' => 'd',
            'È' => 'E',
            'É' => 'E',
            'Ê' => 'E',
            'Ë' => 'E',
            'Ē' => 'E',
            'Ĕ' => 'E',
            'Ė' => 'E',
            'Ę' => 'E',
            'Ě' => 'E',
            'è' => 'e',
            'é' => 'e',
            'ê' => 'e',
            'ë' => 'e',
            'ē' => 'e',
            'ĕ' => 'e',
            'ė' => 'e',
            'ę' => 'e',
            'ě' => 'e',
            'Ĝ' => 'G',
            'Ğ' => 'G',
            'Ġ' => 'G',
            'Ģ' => 'G',
            'Ґ' => 'G',
            'ĝ' => 'g',
            'ğ' => 'g',
            'ġ' => 'g',
            'ģ' => 'g',
            'ґ' => 'g',
            'Ĥ' => 'H',
            'Ħ' => 'H',
            'ĥ' => 'h',
            'ħ' => 'h',
            'І' => 'I',
            'Ì' => 'I',
            'Í' => 'I',
            'Î' => 'I',
            'Ї' => 'Yi',
            'Ï' => 'I',
            'Ĩ' => 'I',
            'Ī' => 'I',
            'Ĭ' => 'I',
            'Ǐ' => 'I',
            'Į' => 'I',
            'İ' => 'I',
            'і' => 'i',
            'ì' => 'i',
            'í' => 'i',
            'î' => 'i',
            'ï' => 'i',
            'ї' => 'yi',
            'ĩ' => 'i',
            'ī' => 'i',
            'ĭ' => 'i',
            'ǐ' => 'i',
            'į' => 'i',
            'ı' => 'i',
            'Ĵ' => 'J',
            'ĵ' => 'j',
            'Ķ' => 'K',
            'ķ' => 'k',
            'Ĺ' => 'L',
            'Ļ' => 'L',
            'Ľ' => 'L',
            'Ŀ' => 'L',
            'Ł' => 'L',
            'ĺ' => 'l',
            'ļ' => 'l',
            'ľ' => 'l',
            'ŀ' => 'l',
            'ł' => 'l',
            'Ñ' => 'N',
            'Ń' => 'N',
            'Ņ' => 'N',
            'Ň' => 'N',
            'ñ' => 'n',
            'ń' => 'n',
            'ņ' => 'n',
            'ň' => 'n',
            'ŉ' => 'n',
            'Ò' => 'O',
            'Ó' => 'O',
            'Ô' => 'O',
            'Õ' => 'O',
            'Ō' => 'O',
            'Ŏ' => 'O',
            'Ǒ' => 'O',
            'Ő' => 'O',
            'Ơ' => 'O',
            'Ø' => 'O',
            'Ǿ' => 'O',
            'ò' => 'o',
            'ó' => 'o',
            'ô' => 'o',
            'õ' => 'o',
            'ō' => 'o',
            'ŏ' => 'o',
            'ǒ' => 'o',
            'ő' => 'o',
            'ơ' => 'o',
            'ø' => 'o',
            'ǿ' => 'o',
            'º' => 'o',
            'Ŕ' => 'R',
            'Ŗ' => 'R',
            'Ř' => 'R',
            'ŕ' => 'r',
            'ŗ' => 'r',
            'ř' => 'r',
            'Ś' => 'S',
            'Ŝ' => 'S',
            'Ş' => 'S',
            'Ș' => 'S',
            'Š' => 'S',
            'ẞ' => 'SS',
            'ś' => 's',
            'ŝ' => 's',
            'ş' => 's',
            'ș' => 's',
            'š' => 's',
            'ſ' => 's',
            'Ţ' => 'T',
            'Ț' => 'T',
            'Ť' => 'T',
            'Ŧ' => 'T',
            'ţ' => 't',
            'ț' => 't',
            'ť' => 't',
            'ŧ' => 't',
            'Ù' => 'U',
            'Ú' => 'U',
            'Û' => 'U',
            'Ũ' => 'U',
            'Ū' => 'U',
            'Ŭ' => 'U',
            'Ů' => 'U',
            'Ű' => 'U',
            'Ų' => 'U',
            'Ư' => 'U',
            'Ǔ' => 'U',
            'Ǖ' => 'U',
            'Ǘ' => 'U',
            'Ǚ' => 'U',
            'Ǜ' => 'U',
            'ù' => 'u',
            'ú' => 'u',
            'û' => 'u',
            'ũ' => 'u',
            'ū' => 'u',
            'ŭ' => 'u',
            'ů' => 'u',
            'ű' => 'u',
            'ų' => 'u',
            'ư' => 'u',
            'ǔ' => 'u',
            'ǖ' => 'u',
            'ǘ' => 'u',
            'ǚ' => 'u',
            'ǜ' => 'u',
            'Ý' => 'Y',
            'Ÿ' => 'Y',
            'Ŷ' => 'Y',
            'ý' => 'y',
            'ÿ' => 'y',
            'ŷ' => 'y',
            'Ŵ' => 'W',
            'ŵ' => 'w',
            'Ź' => 'Z',
            'Ż' => 'Z',
            'Ž' => 'Z',
            'ź' => 'z',
            'ż' => 'z',
            'ž' => 'z',
            'Æ' => 'AE',
            'Ǽ' => 'AE',
            'ß' => 'ss',
            'Ĳ' => 'IJ',
            'ĳ' => 'ij',
            'Œ' => 'OE',
            'ƒ' => 'f',
            'Þ' => 'TH',
            'þ' => 'th',
            'Є' => 'Ye',
            'є' => 'ye',
        ];

        $original_text = str_replace(array_keys($transliteration), array_values($transliteration), $original_text);

        $original_text = preg_replace('/[^a-z0-9\-\_]+/i', '', $original_text);

        while (strpos($original_text, '--') !== false) {
            $original_text = str_replace('--', '-', $original_text);
        }

        // Removed odd char from name ends
        $original_text = trim($original_text, '-');

        return substr($original_text, 0, $max_length);
    }
1093639
public function pgettext($context, $original)
    {
        $message = $context."\x04".$original;
        $translation = gettext($message);

        return ($translation === $message) ? $original : $translation;
    }
285991
public static function transliterate($text)
    {
        self::init();

        if (preg_match_all(self::$regex, $text, $matches)) {
            for ($i = 0; $i < count($matches[0]); $i++) {
                $char = $matches[0][$i];
                if (isset (self::$map[$char])) {
                    $text = str_replace($char, self::$map[$char], $text);
                }
            }
        }

        return $text;
    }
198162
public static function REPLACE($oldText = '', $start = 1, $chars = null, $newText)
    {
        $oldText = PHPExcel_Calculation_Functions::flattenSingleValue($oldText);
        $start   = PHPExcel_Calculation_Functions::flattenSingleValue($start);
        $chars   = PHPExcel_Calculation_Functions::flattenSingleValue($chars);
        $newText = PHPExcel_Calculation_Functions::flattenSingleValue($newText);

        $left = self::LEFT($oldText, $start-1);
        $right = self::RIGHT($oldText, self::STRINGLENGTH($oldText)-($start+$chars)+1);

        return $left.$newText.$right;
    }
287427
def _replace_greek_characters(line):
    """"""
    for greek_char, replacement in iteritems(_GREEK_REPLACEMENTS):
        try:
            line = line.replace(greek_char, replacement)
        except UnicodeDecodeError:
            current_app.logger.exception("Unicode decoding error.")
            return ""
    return line
1151225
public function truncateText($text = null, $length = 0) {
		$result = '';
		if (empty($text)) {
			return $result;
		}

		$text = (string)$text;
		$length = (int)$length;
		if ($length <= 0) {
			$length = 50;
		}

		if (($text === h($text)) && (mb_strlen($text) <= $length)) {
			return $text;
		}

		$truncateOpt = $this->_getOptionsForElem('truncateText.truncateOpt');
		$tuncatedText = $this->Text->truncate($text, $length, $truncateOpt);
		if ($tuncatedText === $text) {
			return $tuncatedText;
		}

		$result = $this->Html->div('collapse-text-truncated', $tuncatedText);
		$result .= $this->Html->div(
			'collapse-text-original',
			$text . $this->_getOptionsForElem('truncateText.collapseLink')
		);
		$result = $this->Html->div('collapse-text-expanded', $result);

		return $result;
	}
554572
def tmpl_delchars(text, chars):
        
        for char in chars:
            text = text.replace(char, '')
        return text
58931
function convert_text($text)
    {
        global $debug_object;
        if (is_object($debug_object)) {$debug_object->debug_log_entry(1);}

        $converted_text = $text;

        $sourceCharset = "";
        $targetCharset = "";

        if ($this->dom)
        {
            $sourceCharset = strtoupper($this->dom->_charset);
            $targetCharset = strtoupper($this->dom->_target_charset);
        }
        if (is_object($debug_object)) {$debug_object->debug_log(3, "source charset: " . $sourceCharset . " target charaset: " . $targetCharset);}

        if (!empty($sourceCharset) && !empty($targetCharset) && (strcasecmp($sourceCharset, $targetCharset) != 0))
        {
            // Check if the reported encoding could have been incorrect and the text is actually already UTF-8
            if ((strcasecmp($targetCharset, 'UTF-8') == 0) && ($this->is_utf8($text)))
            {
                $converted_text = $text;
            }
            else
            {
                $converted_text = @iconv($sourceCharset."//IGNORE", $targetCharset."//IGNORE", $text);
            }
        }

        // Lets make sure that we don't have that silly BOM issue with any of the utf-8 text we output.
        if ($targetCharset == 'UTF-8')
        {
            if (substr($converted_text, 0, 3) == "\xef\xbb\xbf")
            {
                $converted_text = substr($converted_text, 3);
            }
            if (substr($converted_text, -3) == "\xef\xbb\xbf")
            {
                $converted_text = substr($converted_text, 0, -3);
            }
        }

        return $converted_text;
    }
1108774
def transform(self, text):
        
        if type(text) is not unicode:
            text = unicode(text, 'utf-8')
        return text
1196800
public static function cutLongStrings(string $sentence, int $max_length = 50, string $separator = ' ', string $postfix = '...'): string
    {
        // Return actual string if have nothing to cut
        if (mb_strlen($sentence, 'utf-8') <= $max_length) {
            return $sentence;
        }

        $words = mb_split("[" . $separator . "]+", $sentence);
        $res = '';
        $count_of_words = count($words);

        for ($i = 0; $i < $count_of_words; $i++) {
            if (mb_strlen($res . $words[$i] . ' ', 'utf-8') < $max_length) {
                // Add to returned string
                $res .= $words[$i] . ' ';
            } else {
                // Enough
                break;
            }
        }

        return mb_substr($res, 0, -1, 'utf-8') . $postfix;
    }
745120
private Object getNext(String txt, String originalText) {
    if (invertible) {
      String str = prevWordAfter.toString();
      prevWordAfter.setLength(0);
      CoreLabel word = (CoreLabel) tokenFactory.makeToken(txt, yychar, yylength());
      word.set(OriginalTextAnnotation.class, originalText);
      word.set(BeforeAnnotation.class, str);
      prevWord.set(AfterAnnotation.class, str);
      prevWord = word;
      return word;
    } else {
      return tokenFactory.makeToken(txt, yychar, yylength());
   }
  }
1345555
public static function strtoupper($text, $charset='utf-8') {
        $charset = self::parse_charset($charset);

        if ($charset === 'utf-8' and function_exists('mb_strtoupper')) {
            return mb_strtoupper($text, 'UTF-8');
        }

        $oldlevel = error_reporting(E_PARSE);
        $result = self::typo3()->conv_case($charset, (string)$text, 'toUpper');
        error_reporting($oldlevel);

        return $result;
    }
1258351
public String replace(CharSequence text, ObsoleteReplacer replacer) throws IOException
    {
        if (text.length() == 0)
        {
            return "";
        }
        CharArrayWriter caw = new CharArrayWriter();
        InputReader reader = Input.getInstance(text);
        replace(reader, caw, replacer);
        return caw.toString();
    }
742614
def normalize_text(self, txt):
        ""
        # - for TTF unicode fonts: unicode object (utf8 encoding)
        # - for built-in fonts: string instances (latin 1 encoding)
        if self.unifontsubset and isinstance(txt, str) and not PY3K:
            txt = txt.decode('utf8')
        elif not self.unifontsubset and isinstance(txt, unicode) and not PY3K:
            txt = txt.encode('latin1')
        return txt
1186481
public function transliterate($str) {

      $str = self::preTransliterate($str);

      // Workflow:
      //  1/ Default characters
      //  2/ Sokuon
      //  3/ Choonpu

      $str = self::transliterateDefaultCharacters($str, $this->mapping);

      $str = self::transliterateSokuon($str);

      $str = self::transliterateChoonpu($str, $this->macrons);

      return self::postTransliterate($str);
    }
1285603
function(text) {
        return text.replace(/"([^"]|"")*"/g, function(value) {
            return value.replace(LF, CUSTOM_LF_SUBCHAR)
                .replace(CR, CUSTOM_CR_SUBCHAR);
        });
    }
1219182
protected function splitAlignText(string $data, int $maxlen): string
    {
        $RTLOrd = [
            215,
            216,
            217,
            218,
            219,
        ];

        $lines = explode("\n", $data);
        // more than 1 line : recursive calls
        if (count($lines) > 1) {
            $text = '';
            foreach ($lines as $line) {
                $text .= $this->splitAlignText($line, $maxlen) . "\n";
            }

            return $text;
        }
        // process current line word by word
        $split = explode(' ', $data);
        $text  = '';
        $line  = '';

        // do not split hebrew line
        $found = false;
        foreach ($RTLOrd as $ord) {
            if (strpos($data, chr($ord)) !== false) {
                $found = true;
            }
        }
        if ($found) {
            $line = $data;
        } else {
            foreach ($split as $word) {
                $len  = strlen($line);
                $wlen = strlen($word);
                if (($len + $wlen) < $maxlen) {
                    if (!empty($line)) {
                        $line .= ' ';
                    }
                    $line .= $word;
                } else {
                    $p = max(0, (int) (($maxlen - $len) / 2));
                    if (!empty($line)) {
                        $line = str_repeat(' ', $p) . $line; // center alignment using spaces
                        $text .= $line . "\n";
                    }
                    $line = $word;
                }
            }
        }
        // last line
        if (!empty($line)) {
            $len = strlen($line);
            if (in_array(ord($line{0}), $RTLOrd, true)) {
                $len /= 2;
            }
            $p    = max(0, (int) (($maxlen - $len) / 2));
            $line = str_repeat(' ', $p) . $line; // center alignment using spaces
            $text .= $line;
        }

        return $text;
    }