<commit_before><?php

/**
 * This file contains the abstract definition for the
 * Gettext Localization Provider.
 *
 * PHP Version 5.3
 *
 * @category   Libraries
 * @package    L10n
 * @subpackage Libraries
 * @author     M2Mobi <<EMAIL>>
 * @author     <NAME> <<EMAIL>>
 */

/**
 * Gettext Localization Provider class
 *
 * @category   Libraries
 * @package    L10n
 * @subpackage Libraries
 * @author     M2Mobi <<EMAIL>>
 * @author     <NAME> <<EMAIL>>
 */
class L10nProviderGettext extends L10nProvider
{

    /**
     * Constructor.
     *
     * @param String $language POSIX locale definition
     */
    public function __construct($language)
    {
        $this->language = $language;
    }

    /**
     * Destructor.
     */
    public function __destruct()
    {

    }

    /**
     * Initialization method for setting up the provider.
     *
     * @param String $language POSIX locale definition
     *
     * @return void
     */
    protected function init($language)
    {
        global $config;
        setlocale(LC_MESSAGES, $language);
        bindtextdomain($config['l10n']['domain'], $config['l10n']['locales']);
        textdomain($config['l10n']['domain']);
    }

    /**
     * Return a translated string.
     *
     * @param String $identifier Identifier for the requested string
     * @param String $context    Context information fot the requested string
     *
     * @return String $string Translated string, identifier by default
     */
    public function lang($identifier, $context = "")
    {
        global $config;
        $this->init($this->language);
        if ($context == "")
        {
            $output = gettext($identifier);
            return $output;
        }
        else
        {
            // Glue msgctxt and msgid together, with ASCII character 4
            // (EOT, End Of Text)
            $composed = "{$context}\004{$identifier}";
            $output = dcgettext(
                $config['l10n']['domain'],
                $composed,
                LC_MESSAGES
            );

            if ($output == $composed
                && $this->language != $config['l10n']['default_language'])
            {
                return $identifier;
            }
            else
            {
                return $output;
            }
        }
    }

    /**
     * Return a translated string, with proper singular/plural form.
     *
     * @param String  $singular Identifier for the singular version of
     *                          the string
     * @param String  $plural   Identifier for the plural version of
     *                          the string
     * @param Integer $amount   The amount the translation should be based on
     * @param String  $context  Context information fot the requested string
     *
     * @return String $string Translated string, identifier by default
     */
    public function nlang($singular, $plural, $amount, $context = "")
    {
        $this->init($this->language);
        if ($context == "")
        {
            $output = ngettext($singular, $plural, $amount);
            return $output;
        }
        else
        {
            global $config;
            // Glue msgctxt and msgid together, with ASCII character 4
            // (EOT, End Of Text)
            $composed = "{$context}\004{$singular}";
            $output = dcngettext(
                $config['l10n']['domain'],
                $composed,
                $plural,
                $amount,
                LC_MESSAGES
            );

            if ((($output == $composed) || ($output == $plural))
                && $this->language != $config['l10n']['default_language'])
            {
                return ($amount == 1 ? $singular : $plural);
            }
            else
            {
                return $output;
            }
        }
    }

}

?>
<commit_msg>system: Check l10n identifiers for gettext size limits.<commit_after><?php

/**
 * This file contains the abstract definition for the
 * Gettext Localization Provider.
 *
 * PHP Version 5.3
 *
 * @category   Libraries
 * @package    L10n
 * @subpackage Libraries
 * @author     M2Mobi <<EMAIL>>
 * @author     <NAME> <<EMAIL>>
 */

/**
 * Gettext Localization Provider class
 *
 * @category   Libraries
 * @package    L10n
 * @subpackage Libraries
 * @author     M2Mobi <<EMAIL>>
 * @author     <NAME> <<EMAIL>>
 */
class L10nProviderGettext extends L10nProvider
{

    const GETTEXT_MAX_MSGID_LENGTH = 4096;

    /**
     * Constructor.
     *
     * @param String $language POSIX locale definition
     */
    public function __construct($language)
    {
        $this->language = $language;
    }

    /**
     * Destructor.
     */
    public function __destruct()
    {

    }

    /**
     * Initialization method for setting up the provider.
     *
     * @param String $language POSIX locale definition
     *
     * @return void
     */
    protected function init($language)
    {
        global $config;
        setlocale(LC_MESSAGES, $language);
        bindtextdomain($config['l10n']['domain'], $config['l10n']['locales']);
        textdomain($config['l10n']['domain']);
    }

    /**
     * Return a translated string.
     *
     * @param String $identifier Identifier for the requested string
     * @param String $context    Context information fot the requested string
     *
     * @return String $string Translated string, identifier by default
     */
    public function lang($identifier, $context = "")
    {
        if (strlen($identifier) + strlen($context) + 1 > self::GETTEXT_MAX_MSGID_LENGTH)
        {
            Output::error("Identifier too long: " . $identifier);
        }

        $this->init($this->language);
        if ($context == "")
        {
            $output = gettext($identifier);
            return $output;
        }
        else
        {
            global $config;
            // Glue msgctxt and msgid together, with ASCII character 4
            // (EOT, End Of Text)
            $composed = "{$context}\004{$identifier}";
            $output = dcgettext(
                $config['l10n']['domain'],
                $composed,
                LC_MESSAGES
            );

            if ($output == $composed
                && $this->language != $config['l10n']['default_language'])
            {
                return $identifier;
            }
            else
            {
                return $output;
            }
        }
    }

    /**
     * Return a translated string, with proper singular/plural form.
     *
     * @param String  $singular Identifier for the singular version of
     *                          the string
     * @param String  $plural   Identifier for the plural version of
     *                          the string
     * @param Integer $amount   The amount the translation should be based on
     * @param String  $context  Context information fot the requested string
     *
     * @return String $string Translated string, identifier by default
     */
    public function nlang($singular, $plural, $amount, $context = "")
    {
        if (strlen($singular) + strlen($context) + 1 > self::GETTEXT_MAX_MSGID_LENGTH)
        {
            Output::error("Identifier too long: " . $identifier);
        }

        $this->init($this->language);
        if ($context == "")
        {
            $output = ngettext($singular, $plural, $amount);
            return $output;
        }
        else
        {
            global $config;
            // Glue msgctxt and msgid together, with ASCII character 4
            // (EOT, End Of Text)
            $composed = "{$context}\004{$singular}";
            $output = dcngettext(
                $config['l10n']['domain'],
                $composed,
                $plural,
                $amount,
                LC_MESSAGES
            );

            if ((($output == $composed) || ($output == $plural))
                && $this->language != $config['l10n']['default_language'])
            {
                return ($amount == 1 ? $singular : $plural);
            }
            else
            {
                return $output;
            }
        }
    }

}

?>

{'fraction_non_alphanumeric': 0.1179349155860044, 'fraction_numerical': 0.009542451676045999, 'mean_word_length': 1.6353965183752417, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2556719', 'n_tokens_mistral': 2279, 'n_tokens_neox': 2149, 'n_words': 576}