<commit_before><?php

class Twig_Extensions_Extension_Gettext extends Twig_Extension {
    
    protected $useShortnames = true;
    
    public function __construct($useShortnames = true) {
        $this->useShortnames = $useShortnames;
    }
    
    public function getName() {
        return 'gettext';
    }
    
    public function getFunctions() {
        $gettext      = new Twig_Function_Function('gettext');
        $fgettext     = new Twig_Function_Method($this, 'fgettext');
        $pgettext     = new Twig_Function_Method($this, 'pgettext');
        $pfgettext    = new Twig_Function_Method($this, 'pfgettext');
        $ngettext     = new Twig_Function_Function('ngettext');
        $nfgettext    = new Twig_Function_Method($this, 'nfgettext');
        $npgettext    = new Twig_Function_Method($this, 'npgettext');
        $npfgettext   = new Twig_Function_Method($this, 'npfgettext');
        $dgettext     = new Twig_Function_Function('dgettext');
        $dfgettext    = new Twig_Function_Method($this, 'dfgettext');
        $dpgettext    = new Twig_Function_Method($this, 'dpgettext');
        $dpfgettext   = new Twig_Function_Method($this, 'dpfgettext');
        $dngettext    = new Twig_Function_Function('dngettext');
        $dnfgettext   = new Twig_Function_Method($this, 'dnfgettext');
        $dnpgettext   = new Twig_Function_Method($this, 'dnpgettext');
        $dnpfgettext  = new Twig_Function_Method($this, 'dnpfgettext');
        $dcgettext    = new Twig_Function_Function('dcgettext');
        $dcfgettext   = new Twig_Function_Method($this, 'dcfgettext');
        $dcpgettext   = new Twig_Function_Method($this, 'dcpgettext');
        $dcpfgettext  = new Twig_Function_Method($this, 'dcpfgettext');
        $dcngettext   = new Twig_Function_Function('dcngettext');
        $dcnfgettext  = new Twig_Function_Method($this, 'dcnfgettext');
        $dcnpgettext  = new Twig_Function_Method($this, 'dcnpgettext');
        $dcnpfgettext = new Twig_Function_Method($this, 'dcnpfgettext');
        
        $functions = array(
            'gettext'      => $gettext,
            'fgettext'     => $fgettext,
            'pgettext'     => $pgettext,
            'pfgettext'    => $pfgettext,
            'ngettext'     => $ngettext,
            'nfgettext'    => $nfgettext,
            'npgettext'    => $npgettext,
            'npfgettext'   => $npfgettext,
            'dgettext'     => $dgettext,
            'dfgettext'    => $dfgettext,
            'dpgettext'    => $dpgettext,
            'dpfgettext'   => $dpfgettext,
            'dngettext'    => $dngettext,
            'dnfgettext'   => $dnfgettext,
            'dnpgettext'   => $dnpgettext,
            'dnpfgettext'  => $dnpfgettext,
            'dcgettext'    => $dcgettext,
            'dcfgettext'   => $dcfgettext,
            'dcpgettext'   => $dcpgettext,
            'dcpfgettext'  => $dcpfgettext,
            'dcngettext'   => $dcngettext,
            'dcnfgettext'  => $dcnfgettext,
            'dcnpgettext'  => $dcnpgettext,
            'dcnpfgettext' => $dcnpfgettext
        );
        
        if ($this->useShortnames) {
            $functions += array(
                '_'      => $gettext,
                '_f'     => $fgettext,
                '_p'     => $pgettext,
                '_pf'    => $pfgettext,
                '_n'     => $ngettext,
                '_nf'    => $nfgettext,
                '_np'    => $npgettext,
                '_npf'   => $npfgettext,
                '_d'     => $dgettext,
                '_df'    => $dfgettext,
                '_dp'    => $dpgettext,
                '_dpf'   => $dpfgettext,
                '_dn'    => $dngettext,
                '_dnf'   => $dnfgettext,
                '_dnp'   => $dnpgettext,
                '_dnpf'  => $dnpfgettext,
                '_dc'    => $dcgettext,
                '_dcf'   => $dcfgettext,
                '_dcp'   => $dcpgettext,
                '_dcpf'  => $dcpfgettext,
                '_dcn'   => $dcngettext,
                '_dcnf'  => $dcnfgettext,
                '_dcnp'  => $dcnpgettext,
                '_dcnpf' => $dcnpfgettext
            );
        }
        
        return $functions;
    }
    
    public function fgettext($message) {
        $args = func_get_args();
        return vsprintf(gettext($message), array_slice($args, 1));
    }
    
    public function pgettext($context, $message) {
        return gettext($context . "\04" . $message);
    }
    
    public function pfgettext($context, $message) {
        $args = func_get_args();
        return vsprintf($this->pgettext($context, $message), array_slice($args, 2));
    }
    
    public function nfgettext($msgid1, $msgid2, $n) {
        $args = func_get_args();
        return vsprintf(ngettext($msgid1, $msgid2, $n), array_slice($args, 3));
    }
    
    public function npgettext($context, $msgid1, $msgid2, $n) {
        return ngettext($context . "\04" . $msgid1, $context . "\04" . $msgid2, $n);
    }
    
    public function npfgettext($context, $msgid1, $msgid2, $n) {
        $args = func_get_args();
        return vsprintf($this->npgettext($context, $msgid1, $msgid2, $n), array_slice($args, 4));
    }
    
    public function dfgettext($domain, $message) {
        $args = func_get_args();
        return vsprintf(dgettext($domain, $message), array_slice($args, 2));
    }
    
    public function dpgettext($context, $domain, $message) {
        return dgettext($domain, $context . "\04" . $message);
    }

    public function dpfgettext($context, $domain, $message) {
        $args = func_get_args();
        return vsprintf($this->dpgettext($context, $domain, $message), array_slice($args, 3));
    }
    
    public function dnfgettext($domain, $msgid1, $msgid2, $n) {
        $args = func_get_args();
        return vsprintf(dngettext($domain, $msgid1, $msgid2, $n), array_slice($args, 4));
    }

    public function dnpgettext($context, $domain, $msgid1, $msgid2, $n) {
        return dngettext($domain, $context . "\04" . $msgid1, $context . "\04" . $msgid2, $n);
    }

    public function dnpfgettext($context, $domain, $msgid1, $msgid2, $n) {
        $args = func_get_args();
        return vsprintf($this->dnpgettext($context, $domain, $msgid1, $msgid2, $n), array_slice($args, 5));
    }

    public function dcfgettext($domain, $message, $category) {
        $args = func_get_args();
        return vsprintf(dcgettext($domain, $message, $category), array_slice($args, 3));
    }
    
    public function dcpgettext($context, $domain, $message, $category) {
        return dcgettext($domain, $context . "\04" . $message, $category);
    }
    
    public function dcpfgettext($context, $domain, $message, $category) {
        $args = func_get_args();
        return vsprintf($this->dcpgettext($context, $domain, $message, $category), array_slice($args, 4));
    }
    
    public function dcnfgettext($domain, $msgid1, $msgid2, $n, $category) {
        $args = func_get_args();
        return vsprintf(dcngettext($domain, $msgid1, $msgid2, $n, $category), array_slice($args, 5));
    }
    
    public function dcnpgettext($context, $domain, $msgid1, $msgid2, $n, $category) {
        return dcngettext($domain, $context . "\04" . $msgid1, $context . "\04" . $msgid2, $n, $category);
    }
    
    public function dcnpfgettext($context, $domain, $msgid1, $msgid2, $n, $category) {
        $args = func_get_args();
        return vsprintf($this->dcnpgettext($context, $domain, $msgid1, $msgid2, $n, $category), array_slice($args, 6));
    }
    
}<commit_msg>experimentally adding filter interface in addition to functions<commit_after><?php

class Twig_Extensions_Extension_Gettext extends Twig_Extension {
    
    protected $useShortnames = true;
    
    public function __construct($useShortnames = true) {
        $this->useShortnames = $useShortnames;
    }
    
    public function getName() {
        return 'gettext';
    }
    
    public function getFunctions() {
        $gettext     = new Twig_Function_Function('gettext');
        $pgettext    = new Twig_Function_Method($this, 'pgettext');
        $ngettext    = new Twig_Function_Function('ngettext');
        $npgettext   = new Twig_Function_Method($this, 'npgettext');
        $dgettext    = new Twig_Function_Function('dgettext');
        $dpgettext   = new Twig_Function_Method($this, 'dpgettext');
        $dngettext   = new Twig_Function_Function('dngettext');
        $dnpgettext  = new Twig_Function_Method($this, 'dnpgettext');
        $dcgettext   = new Twig_Function_Method($this, 'dcgettext');
        $dcpgettext  = new Twig_Function_Method($this, 'dcpgettext');
        $dcngettext  = new Twig_Function_Method($this, 'dcngettext');
        $dcnpgettext = new Twig_Function_Method($this, 'dcnpgettext');
        
        $functions = array(
            'gettext'     => $gettext,
            'pgettext'    => $pgettext,
            'ngettext'    => $ngettext,
            'npgettext'   => $npgettext,
            'dgettext'    => $dgettext,
            'dpgettext'   => $dpgettext,
            'dngettext'   => $dngettext,
            'dnpgettext'  => $dnpgettext,
            'dcgettext'   => $dcgettext,
            'dcpgettext'  => $dcpgettext,
            'dcngettext'  => $dcngettext,
            'dcnpgettext' => $dcnpgettext
        );
        
        if ($this->useShortnames) {
            $functions += array(
                '_'     => $gettext,
                '_p'    => $pgettext,
                '_n'    => $ngettext,
                '_np'   => $npgettext,
                '_d'    => $dgettext,
                '_dp'   => $dpgettext,
                '_dn'   => $dngettext,
                '_dnp'  => $dnpgettext,
                '_dc'   => $dcgettext,
                '_dcp'  => $dcpgettext,
                '_dcn'  => $dcngettext,
                '_dcnp' => $dcnpgettext
            );
        }
        
        return $functions;
    }
    
    public function getFilters() {
        $gettext     = new Twig_Filter_Function('gettext');
        $pgettext    = new Twig_Filter_Method($this, 'pgettextFilter');
        $ngettext    = new Twig_Filter_Function('ngettext');
        $npgettext   = new Twig_Filter_Method($this, 'npgettextFilter');
        $dgettext    = new Twig_Filter_Method($this, 'dgettextFilter');
        $dpgettext   = new Twig_Filter_Method($this, 'dpgettextFilter');
        $dngettext   = new Twig_Filter_Method($this, 'dngettextFilter');
        $dnpgettext  = new Twig_Filter_Method($this, 'dnpgettextFilter');
        $dcgettext   = new Twig_Filter_Method($this, 'dcgettextFilter');
        $dcpgettext  = new Twig_Filter_Method($this, 'dcpgettextFilter');
        $dcngettext  = new Twig_Filter_Method($this, 'dcngettextFilter');
        $dcnpgettext = new Twig_Filter_Method($this, 'dcnpgettextFilter');
        
        $filters = array(
            'gettext'     => $gettext,
            'pgettext'    => $pgettext,
            'ngettext'    => $ngettext,
            'npgettext'   => $npgettext,
            'dgettext'    => $dgettext,
            'dpgettext'   => $dpgettext,
            'dngettext'   => $dngettext,
            'dnpgettext'  => $dnpgettext,
            'dcgettext'   => $dcgettext,
            'dcpgettext'  => $dcpgettext,
            'dcngettext'  => $dcngettext,
            'dcnpgettext' => $dcnpgettext,
            'sprintf'     => new Twig_Filter_Method($this, 'sprintf')
        );
        
        if ($this->useShortnames) {
            $filters += array(
                '_'     => $gettext,
                '_p'    => $pgettext,
                '_n'    => $ngettext,
                '_np'   => $npgettext,
                '_d'    => $dgettext,
                '_dp'   => $dpgettext,
                '_dn'   => $dngettext,
                '_dnp'  => $dnpgettext,
                '_dc'   => $dcgettext,
                '_dcp'  => $dcpgettext,
                '_dcn'  => $dcngettext,
                '_dcnp' => $dcnpgettext
            );
        }
        
        return $filters;
    }
    
    public function pgettext($context, $message) {
        return gettext($context . "\04" . $message);
    }
    
    public function npgettext($context, $msgid1, $msgid2, $n) {
        return ngettext($context . "\04" . $msgid1, $context . "\04" . $msgid2, $n);
    }
    
    public function dpgettext($context, $domain, $message) {
        return dgettext($domain, $context . "\04" . $message);
    }

    public function dnpgettext($context, $domain, $msgid1, $msgid2, $n) {
        return dngettext($domain, $context . "\04" . $msgid1, $context . "\04" . $msgid2, $n);
    }

    public function dcgettext($domain, $message, $category) {
        return dcgettext($domain, $message, constant($category));
    }
    
    public function dcpgettext($context, $domain, $message, $category) {
        return dcgettext($domain, $context . "\04" . $message, constant($category));
    }
    
    public function dcngettext($domain, $msgid1, $msgid2, $n, $category) {
        return dcngettext($domain, $msgid1, $msgid2, $n, constant($category));
    }
    
    public function dcnpgettext($context, $domain, $msgid1, $msgid2, $n, $category) {
        return dcngettext($domain, $context . "\04" . $msgid1, $context . "\04" . $msgid2, $n, constant($category));
    }
    
    public function pgettextFilter($message, $context) {
        return $this->pgettext($context, $message);
    }
    
    public function npgettextFilter($msgid1, $msgid2, $n, $context) {
        return $this->npgettext($context, $msgid1, $msgid2, $context);
    }
    
    public function dgettextFilter($message, $domain) {
        return dgettext($domain, $message);
    }
    
    public function dpgettextFilter($message, $domain, $context) {
        return $this->dpgettext($context, $domain, $message);
    }
    
    public function dngettextFilter($msgid1, $msgid2, $n, $domain) {
        return dngettext($domain, $msgid1, $msgid2, $n);
    }
    
    public function dnpgettextFilter($msgid1, $msgid2, $n, $domain, $context) {
        return $this->dnpgettext($context, $domain, $msgid1, $msgid2, $n);
    }
    
    public function dcgettextFilter($message, $domain, $category) {
        return $this->dcgettext($domain, $message, $category);
    }
    
    public function dcpgettextFilter($message, $domain, $category, $context) {
        return $this->dcpgettext($context, $domain, $message, $category);
    }
    
    public function dcngettextFilter($msgid1, $msgid2, $n, $domain, $category) {
        return $this->dcngettext($domain, $msgid1, $msgid2, $n, $category);
    }
    
    public function dcnpgettextFilter($msgid1, $msgid2, $n, $domain, $category, $context) {
        return $this->dcngettext($context, $domain, $msgid1, $msgid2, $n, $category);
    }
    
    public function sprintf($string /*, $arg, ... */) {
        $args = func_get_args();
        return vsprintf($string, array_slice($args, 1));
    }
    
}
{'fraction_non_alphanumeric': 0.14360138925995192, 'fraction_numerical': 0.00808175260486241, 'mean_word_length': 2.2151599742323382, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 119, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '400202', 'n_tokens_mistral': 5037, 'n_tokens_neox': 4876, 'n_words': 913}