2013-06-07 05:44:37 -04:00
|
|
|
<?php
|
2026-03-26 12:46:27 -04:00
|
|
|
|
|
|
|
|
// SPDX-FileCopyrightText: 2018 Icinga GmbH <https://icinga.com>
|
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
2013-06-07 05:44:37 -04:00
|
|
|
|
2021-05-20 03:28:12 -04:00
|
|
|
use ipl\Stdlib\Contract\Translator;
|
|
|
|
|
use ipl\I18n\StaticTranslator;
|
2014-01-29 10:25:08 -05:00
|
|
|
|
2015-09-16 08:16:40 -04:00
|
|
|
/**
|
|
|
|
|
* No-op translate
|
|
|
|
|
*
|
|
|
|
|
* Supposed to be used for marking a string as available for translation without actually translating it immediately.
|
|
|
|
|
* The returned string is the one given in the input. This does only work with the standard gettext macros t() and mt().
|
|
|
|
|
*
|
|
|
|
|
* @param string $messageId
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2022-01-19 08:29:51 -05:00
|
|
|
function N_(string $messageId): string
|
2015-09-16 08:16:40 -04:00
|
|
|
{
|
|
|
|
|
return $messageId;
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-25 12:07:29 -05:00
|
|
|
// Workaround for test issues, this is required unless our tests are able to
|
|
|
|
|
// accomplish "real" bootstrapping
|
|
|
|
|
if (function_exists('t')) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2015-09-16 08:16:40 -04:00
|
|
|
|
2014-01-29 10:25:08 -05:00
|
|
|
if (extension_loaded('gettext')) {
|
2014-09-16 09:19:23 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @see Translator::translate() For the function documentation.
|
|
|
|
|
*/
|
2022-01-19 08:29:51 -05:00
|
|
|
function t(string $messageId, ?string $context = null): string
|
2013-06-07 05:44:37 -04:00
|
|
|
{
|
2021-05-20 03:28:12 -04:00
|
|
|
return StaticTranslator::$instance->translate($messageId, $context);
|
2013-06-07 05:44:37 -04:00
|
|
|
}
|
|
|
|
|
|
2014-09-16 09:19:23 -04:00
|
|
|
/**
|
2021-05-20 03:28:12 -04:00
|
|
|
* @see Translator::translateInDomain() For the function documentation.
|
2014-09-16 09:19:23 -04:00
|
|
|
*/
|
2022-01-19 08:29:51 -05:00
|
|
|
function mt(string $domain, string $messageId, ?string $context = null): string
|
2013-06-07 05:44:37 -04:00
|
|
|
{
|
2021-05-20 03:28:12 -04:00
|
|
|
return StaticTranslator::$instance->translateInDomain($domain, $messageId, $context);
|
2013-06-07 05:44:37 -04:00
|
|
|
}
|
2014-09-15 08:11:42 -04:00
|
|
|
|
2014-09-16 09:19:23 -04:00
|
|
|
/**
|
|
|
|
|
* @see Translator::translatePlural() For the function documentation.
|
|
|
|
|
*/
|
2022-01-19 08:29:51 -05:00
|
|
|
function tp(string $messageId, string $messageId2, ?int $number, ?string $context = null): string
|
2014-09-15 08:11:42 -04:00
|
|
|
{
|
2022-01-19 08:29:51 -05:00
|
|
|
return StaticTranslator::$instance->translatePlural($messageId, $messageId2, $number ?? 0, $context);
|
2014-09-15 08:11:42 -04:00
|
|
|
}
|
|
|
|
|
|
2014-09-16 09:19:23 -04:00
|
|
|
/**
|
2021-05-20 03:28:12 -04:00
|
|
|
* @see Translator::translatePluralInDomain() For the function documentation.
|
2014-09-16 09:19:23 -04:00
|
|
|
*/
|
2022-01-19 08:29:51 -05:00
|
|
|
function mtp(string $domain, string $messageId, string $messageId2, ?int $number, ?string $context = null): string
|
2014-09-11 12:04:10 -04:00
|
|
|
{
|
2021-05-20 03:28:12 -04:00
|
|
|
return StaticTranslator::$instance->translatePluralInDomain(
|
|
|
|
|
$domain,
|
|
|
|
|
$messageId,
|
|
|
|
|
$messageId2,
|
2022-01-19 08:29:51 -05:00
|
|
|
$number ?? 0,
|
2021-05-20 03:28:12 -04:00
|
|
|
$context
|
|
|
|
|
);
|
2014-09-11 12:04:10 -04:00
|
|
|
}
|
2014-09-16 09:19:23 -04:00
|
|
|
|
2013-06-07 05:44:37 -04:00
|
|
|
} else {
|
2014-09-16 09:19:23 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @see Translator::translate() For the function documentation.
|
|
|
|
|
*/
|
2022-01-19 08:29:51 -05:00
|
|
|
function t(string $messageId, ?string $context = null): string
|
2013-06-07 05:44:37 -04:00
|
|
|
{
|
|
|
|
|
return $messageId;
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-16 09:19:23 -04:00
|
|
|
/**
|
|
|
|
|
* @see Translator::translate() For the function documentation.
|
|
|
|
|
*/
|
2022-01-19 08:29:51 -05:00
|
|
|
function mt(string $domain, string $messageId, ?string $context = null): string
|
2013-06-07 05:44:37 -04:00
|
|
|
{
|
|
|
|
|
return $messageId;
|
|
|
|
|
}
|
2014-09-15 08:11:42 -04:00
|
|
|
|
2014-09-16 09:19:23 -04:00
|
|
|
/**
|
|
|
|
|
* @see Translator::translatePlural() For the function documentation.
|
|
|
|
|
*/
|
2022-01-19 08:29:51 -05:00
|
|
|
function tp(string $messageId, string $messageId2, ?int $number, ?string $context = null): string
|
2014-09-15 08:11:42 -04:00
|
|
|
{
|
2014-09-16 09:19:23 -04:00
|
|
|
if ((int) $number !== 1) {
|
2014-09-15 08:11:42 -04:00
|
|
|
return $messageId2;
|
|
|
|
|
}
|
2021-05-20 03:28:12 -04:00
|
|
|
|
2014-09-15 08:11:42 -04:00
|
|
|
return $messageId;
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-16 09:19:23 -04:00
|
|
|
/**
|
|
|
|
|
* @see Translator::translatePlural() For the function documentation.
|
|
|
|
|
*/
|
2022-01-19 08:29:51 -05:00
|
|
|
function mtp(string $domain, string $messageId, string $messageId2, ?int $number, ?string $context = null): string
|
2014-09-15 08:11:42 -04:00
|
|
|
{
|
2014-09-16 09:19:23 -04:00
|
|
|
if ((int) $number !== 1) {
|
2014-09-15 08:11:42 -04:00
|
|
|
return $messageId2;
|
|
|
|
|
}
|
2021-05-20 03:28:12 -04:00
|
|
|
|
2014-09-15 08:11:42 -04:00
|
|
|
return $messageId;
|
|
|
|
|
}
|
2014-09-16 09:19:23 -04:00
|
|
|
|
2013-06-07 05:44:37 -04:00
|
|
|
}
|