File "translate.class.php"

Full path: /home/kosmetik/public_html/wp-content/plugins/unlimited-elements-for-elementor/inc_php/framework/translate.class.php
File size: 1.93 B
MIME-type: text/x-php
Charset: utf-8

Download   Open   Edit   Advanced Editor   Back

<?php

defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
class UniteTranslateUC
{
    private $entries;
    private $domain;
    public function __construct($domain)
    {
        $this->domain = $domain;
        $this->get_translations_for_domain($domain);
    }
    private function get_translations_for_domain($domain = "default")
    {
        if ($this->entries != null) {
            return true;
        }
        $mo = new MO();
        $current_language = JFactory::getLanguage();
        $mo_file = JPATH_COMPONENT . DIRECTORY_SEPARATOR . "language" . DIRECTORY_SEPARATOR . $domain . "-" . $current_language->getTag() . ".mo";
        if (!file_exists($mo_file)) {
            $mo_file = JPATH_COMPONENT . DIRECTORY_SEPARATOR . "language" . DIRECTORY_SEPARATOR . $domain . "-" . str_replace("-", "_", $current_language->getTag()) . ".mo";
            if (!file_exists($mo_file)) {
                return false;
            }
        }
        if (!$mo->import_from_file($mo_file)) {
            return false;
        }
        if (!isset($lang[$domain])) {
            $lang[$domain] = $mo;
        }
        $this->merge_with($lang[$domain]);
    }
    private function translate_singular($singular, $context = null)
    {
        $entry = new Translation_Entry(array('singular' => $singular, 'context' => $context));
        $translated = $this->translate_entry($entry);
        return $translated && !empty($translated->translations) ? $translated->translations[0] : $singular;
    }
    private function merge_with(&$other)
    {
        foreach ($other->entries as $entry) {
            $this->entries[$entry->key()] = $entry;
        }
    }
    private function translate_entry(&$entry)
    {
        $key = $entry->key();
        return isset($this->entries[$key]) ? $this->entries[$key] : false;
    }
    public function translate($text)
    {
        $translations = $this->translate_singular($text);
        return $translations;
    }
}