X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FCore%2FL10n.php;h=24be0109554b2e4ba0a02e98502ffbddc4a83e2a;hb=3e797547a37f8c8f22e88965b4a4d278bcc192e0;hp=3e9ba3859f27d765f95a0c64ec651d58bcd07bb0;hpb=f7e9b74dca7b19b21164318b0ab7f537fb271d28;p=friendica.git diff --git a/src/Core/L10n.php b/src/Core/L10n.php index 3e9ba3859f..24be010955 100644 --- a/src/Core/L10n.php +++ b/src/Core/L10n.php @@ -132,24 +132,29 @@ class L10n * string interpolation (sprintf) with additional optional arguments. * * Usages: - * - t('This is an example') - * - t('URL %s returned no result', $url) - * - t('Current version: %s, new version: %s', $current_version, $new_version) + * - L10n::t('This is an example') + * - L10n::t('URL %s returned no result', $url) + * - L10n::t('Current version: %s, new version: %s', $current_version, $new_version) * * @param string $s + * @param array $vars Variables to interpolate in the translation string * @return string */ - public static function t($s) + public static function t($s, ...$vars) { $a = get_app(); + if (empty($s)) { + return ''; + } + if (x($a->strings, $s)) { $t = $a->strings[$s]; $s = is_array($t) ? $t[0] : $t; } - if (func_num_args() > 1) { - $args = array_slice(func_get_args(), 1); - $s = @vsprintf($s, $args); + + if (count($vars) > 0) { + $s = sprintf($s, ...$vars); } return $s; @@ -165,8 +170,8 @@ class L10n * is performed using the count as parameter. * * Usages: - * - tt('Like', 'Likes', $count) - * - tt("%s user deleted", "%s users deleted", count($users)) + * - L10n::tt('Like', 'Likes', $count) + * - L10n::tt("%s user deleted", "%s users deleted", count($users)) * * @global type $lang * @param string $singular