Skip to content
This repository has been archived by the owner on Jun 23, 2023. It is now read-only.

Commit

Permalink
Changed handling of gettext
Browse files Browse the repository at this point in the history
  • Loading branch information
weberhofer committed Mar 19, 2015
1 parent b2db771 commit 3f0598e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 68 deletions.
64 changes: 0 additions & 64 deletions src/GettextInitializer.php

This file was deleted.

37 changes: 33 additions & 4 deletions src/Pel.php
Expand Up @@ -24,8 +24,6 @@
*/
namespace lsolesen\pel;

require_once 'GettextInitializer.php';

/**
* Class with miscellaneous static methods.
*
Expand All @@ -41,6 +39,14 @@
class Pel
{

/**
* Flag that controls if dgettext can be used.
* Is set to true or fals at the first access
*
* @var unknown
*/
private static $hasdgetext = null;

/**
* Flag for controlling debug information.
*
Expand Down Expand Up @@ -302,7 +308,7 @@ public static function warning()
*/
public static function tra($str)
{
return dgettext('pel', $str);
return self::dgettextWrapper('pel', $str);
}

/**
Expand Down Expand Up @@ -331,6 +337,29 @@ public static function fmt()
{
$args = func_get_args();
$str = array_shift($args);
return vsprintf(dgettext('pel', $str), $args);
return vsprintf(self::dgettextWrapper('pel', $str), $args);
}

/**
* Warapper for dgettext.
* The untranslated stub will be return in the case that dgettext is not available.
*
* @param string $domain
* @param string $str
* @return string
*/
private static function dgettextWrapper($domain, $str)
{
if (self::$hasdgetext === null) {
self::$hasdgetext = function_exists('dgettext');
if (self::$hasdgetext === true) {
bindtextdomain('pel', __DIR__ . '/locale');
}
}
if (self::$hasdgetext) {
return dgettext($domain, $str);
} else {
return $str;
}
}
}

0 comments on commit 3f0598e

Please sign in to comment.