Initialize a new gettext class

@param string $directory
@param string $domain
@param string $locale

@return TranslatorInterface|null
4402
public function translator(string $locale, string $domain, string $directory): ?TranslatorInterface
    {
        $class = GETTEXT_EXTENSION ? GettextTranslator::class : Translator::class;

        $previous = self::$translator;
        self::$translator = new $class($locale, $domain, $directory);

        if ($previous === null) {
            require __DIR__ . DIRECTORY_SEPARATOR . 'helpers.php';
        }

        $this->locale = $locale;

        return $previous;
    }
1160191
public function getCatalogs($locale = null, $domain = null) {
		$cache   = $this->getCacheFrontend();
		$cacheId = $this->prepareCacheId($locale, $domain);
		
		// Many
		if (is_array($cacheId)) {
			$catalogsRaw = $cache->getMany($cacheId);
			
			if (empty($catalogsRaw)) {
				return;
			}
			
			$catalogs = [];
			
			foreach ($catalogsRaw as $catalogId => $catalog) {
				list($localePart, $domainPart) = explode('_', $catalogId);
				
				if (! isset($catalogs[$localePart])) {
					$catalogs[$localePart] = [];
				}
				
				$catalogs[$localePart][$domainPart] = $catalog;
			}
			
			return $catalogs;
		}
		
		// One
		$catalog = $cache->get($cacheId);
				
		if ($catalog === null) {
			return;
		}

		return [
			$locale => [
				$domain => $catalog
			]
		];
	}
1340000
protected function prepareCacheId($locale, $domain) {
		if (is_array($locale)) {
			$list = [];
			
			// many locales to many domains
			if (is_array($domain)) {
				foreach ($locale as $part1) {
					foreach ($domain as $part2) {
						$list[] = $part1 . '_' . $part2;
					}
				}
				
				return $list;
			}
			
			// many locales to one domain
			foreach ($locale as $part) {
				$list[] = $part1 . '_' . $domain;
			}
			
			return $list;
		}
		
		// one locale to many domains
		if (is_array($domain)) {
			$list = [];
			
			foreach ($domain as $part) {
				$list[] = $locale . '_' . $part;
			}
			
			return $list;
		}
		
		// one locale to one domain
		return $locale . '_' . $domain;
	}
560213
public function getTranslations($locale, $domain)
    {
        $conn = $this->getEntityManager()->getConnection();
        $stmt = $conn->executeQuery(
            'SELECT m.message, t.translation FROM message m JOIN message_translation t ON (t.message_id = m.id AND t.locale = ? ) WHERE m.domain = ?',
            [$locale, $domain]
        );
        while ($row = $stmt->fetch()) {
            yield $row['message'] => $row['translation'];
        }
    }
848863
protected function handlePreinit($locale, $domain) {
		if (! empty($this->preinitLocales)) {
			$locale = array_unique(array_merge(
				(array) $locale, 
				$this->preinitLocales
			));
		}

		if (! empty($this->preinitDomains)) {
			$domain = array_unique(array_merge(
				(array) $domain,
				$this->preinitDomains
			));
		}
		
		$this->preinitNeed = false;
		
		return [$locale, $domain];
	}
161720
protected function getManyCatalogs(array $locale, $domain = null) {
		if ($domain === null) {
			return array_intersect_key(
				$this->catalogs,
				array_flip($locale)
			);
		}

		if (is_string($domain)) {
			$result = [];

			foreach ($locale as $part) {
				if (isset($this->catalogs[$part][$domain])) {
					$result[$part][$domain] = $this->catalogs[$part][$domain];
				}
			}

			return $result;
		}

		if (is_array($domain)) {
			$result = [];

			foreach ($locale as $part) {
				if (isset($this->catalogs[$part])) {
					$result[$part] = array_intersect_key(
						$this->catalogs[$part],
						array_flip($domain)
					);
				}
			}

			return $result;
		}

		throw new InvalidParameter('Domain must be a string or an array');
	}
431823
protected function t($key, array $parameters = [], $domain = null, $locale = null)
    {
        return $this->getContainer()->get('translator')->trans($key, $parameters, $domain, $locale);
    }
633839
public function getCatalogs($locale = null, $domain = null) {
		if ($locale === null && $domain === null) {
			return $this->catalogs;
		}
		
		if (is_string($locale)) {
			return $this->getSingleCatalog($locale, $domain);
		}
		
		if (is_array($locale)) {
			return $this->getManyCatalogs($locale, $domain);
		}
		
		throw new InvalidParameter('Locale must be a string or an array');
	}
396112
public static function setupGettext()
    {
        $path = '@DATA-DIR@/Swat/locale';
        if (mb_substr($path, 0, 1) === '@') {
            $path = __DIR__ . '/../locale';
        }

        bindtextdomain(self::GETTEXT_DOMAIN, $path);
        bind_textdomain_codeset(self::GETTEXT_DOMAIN, 'UTF-8');
    }
1172542
protected function getI18nDirectoryText($directory, $isValid)
    {
        if ($this->translator !== null) {
            if ($isValid) {
                $sentence = 'The directory %directory% is writable';
            } else {
                $sentence = 'The directory %directory% is not writable';
            }

            $translatedText = $this->translator->trans(
                $sentence,
                array(
                    '%directory%' => $directory
                )
            );
        } else {
            $translatedText = sprintf('The directory %s should be writable', $directory);
        }

        return $translatedText;
    }
722132
public function removeTranslation($locale, $domain, $key)
    {
        $unit = $this->findByDomainAndKey($domain, $key);
        $unit->deleteTranslation($locale);
        $this->persist($unit);
    }
807374
private function getTranslationsForDomain($locale, $domain)
    {
        $allMessages = $this->getTranslationsForLocale($locale);

        if (!array_key_exists($domain, $allMessages)) {
            throw new \Exception('Domain ' . $domain . ' not found in the translations for locale ' . $locale);
        }

        return $allMessages[$domain];
    }
855085
protected static function loadTranslation($string, $text_domain)
    {
        /**
         * Locale file path
         *
         * @var string $file
         */
        $file = static::$dir . '/' . static::$locale . '/' . $text_domain . '.php';

        /**
         * Check if we have already loaded this file
         */
        if (array_key_exists($file, static::$loaded)) {

            /**
             * Save missing string if configured to
             */
            if (static::$autoGenerate && (!isset(static::$loaded[$file][$string]))) {
                return static::addTranslation($file, $string);
            }

            /** return processed string */
            return isset(static::$loaded[$file][$string]) && !empty(static::$loaded[$file][$string])
                ? self::$loaded[$file][$string] : $string;
        }

        /**
         * Check if the file exists
         */
        if (!file_exists($file)) {

            /**
             * Create file if not in configured to
             */
            if (static::$autoGenerate) {
                static::saveTranslationFile($file, [$string => '']);
            }

            return $string;
        }
        /** @noinspection PhpIncludeInspection */
        static::$loaded[$file] = (array)require $file;

        /**
         * Save missing string if not in production
         */
        if (static::$autoGenerate && (!isset(static::$loaded[$file][$string]))) {
            return static::addTranslation($file, $string);
        }

        /** return processed string */
        return isset(static::$loaded[$file][$string]) && !empty(static::$loaded[$file][$string])
            ? static::$loaded[$file][$string] : $string;
    }
153
public static function getLocales($domain = null)
    {
        // Optionally filter by domain
        $domainObj = Domain::getByDomain($domain);
        if ($domainObj) {
            return $domainObj->getLocales();
        }

        return Locale::getCached();
    }
1296448
public function gettext($attrib, $domain = null)
    {
        // load localization files if not done yet
        if (empty($this->texts)) {
            $this->load_language();
        }

        // extract attributes
        if (is_string($attrib)) {
            $attrib = array('name' => $attrib);
        }

        $name = (string) $attrib['name'];

        // attrib contain text values: use them from now
        if (($setval = $attrib[strtolower($_SESSION['language'])]) || ($setval = $attrib['en_us'])) {
            $this->texts[$name] = $setval;
        }

        // check for text with domain
        if ($domain && ($text = $this->texts[$domain.'.'.$name])) {
        }
        // text does not exist
        else if (!($text = $this->texts[$name])) {
            return "[$name]";
        }

        // replace vars in text
        if (is_array($attrib['vars'])) {
            foreach ($attrib['vars'] as $var_key => $var_value) {
                $text = str_replace($var_key[0] != '$' ? '$'.$var_key : $var_key, $var_value, $text);
            }
        }

        // replace \n with real line break
        $text = strtr($text, array('\n' => "\n"));

        // case folding
        if (($attrib['uppercase'] && strtolower($attrib['uppercase']) == 'first') || $attrib['ucfirst']) {
            $case_mode = MB_CASE_TITLE;
        }
        else if ($attrib['uppercase']) {
            $case_mode = MB_CASE_UPPER;
        }
        else if ($attrib['lowercase']) {
            $case_mode = MB_CASE_LOWER;
        }

        if (isset($case_mode)) {
            $text = mb_convert_case($text, $case_mode);
        }

        return $text;
    }
165563
public function loadLocaleFile($file, $domain) {
		$filename = $this->findLocaleFile($file);

		if ($filename !== null) {
			$locale = $this->getLocaleFromFilename($filename);
			$translator = $this->service->getTranslator();
			$translator->addResource('json', $filename, $locale, $domain);
		}
	}
344496
public function addDomain($domain, $path='./locale/')
    {
        bindtextdomain($domain, $path);
        if ($this->_encoding) {
            bind_textdomain_codeset($domain, $this->_encoding);
        }
        $this->useDomain($domain);
    }