<commit_before><?php

namespace MarcosHoo\LaravelPHPTAL;

// github enhancement request #1 by towel (https://github.com/towel)
// This an example of implementing your own Translation Service
class PHPTALTranslator implements \PHPTAL_TranslationService
{
    protected $language = 'en';
    protected $encoding = 'UTF-8';
    protected $path = '';
    protected $domains = array();
    protected $context = array();

    /**
     * Set the target language for translations.
     * From the func_get_args()
     *
     * @return string - chosen language
     */
    function setLanguage()
    {
        $languages = func_get_args();
        foreach ($languages as $language) {
            $this->language = $language;
            break;
        }
        return $this->language;
    }

    /**
     * PHPTAL will inform translation service what encoding page uses.
     * Output of translate() must be in this encoding.
     */
    function setEncoding($encoding)
    {
        $this->encoding = $encoding;
    }

    /**
     * Set the domain to use for translations (if different parts of application are translated in different files.
     * This is not for language selection).
     */
    function useDomain($domain)
    {
        if (!array_key_exists($domain, $this->domains)) {
            $files = [
                base_path() . "/resources/lang/{$this->language}/{$domain}.php",
                base_path() . "/resources/lang/{$this->language}/domains/{$domain}.php",
                base_path() . "/lang/{$this->language}/domains/{$domain}.php"
            ];
            $found = false;
            foreach ($files as $file) {
                if (is_readable($file)) {
                    $found = true;
                    break;
                }
            }
            if ($found) {
                $this->domains[$domain] = include($file);
                $this->context = $this->domains[$domain];
            }
        } else {
            $this->context = $this->domains[$domain];
        }
    }

    /**
     * Set XHTML-escaped value of a variable used in translation key.
     *
     * You should use it to replace all ${key}s with values in translated strings.<commit_msg>PHPTALTranslator useDomain fix<commit_after><?php

namespace MarcosHoo\LaravelPHPTAL;

// github enhancement request #1 by towel (https://github.com/towel)
// This an example of implementing your own Translation Service
class PHPTALTranslator implements \PHPTAL_TranslationService
{
    protected $language = 'en';
    protected $encoding = 'UTF-8';
    protected $path = '';
    protected $domains = array();
    protected $context = array();

    /**
     * Set the target language for translations.
     * From the func_get_args()
     *
     * @return string - chosen language
     */
    function setLanguage()
    {
        $languages = func_get_args();
        foreach ($languages as $language) {
            $this->language = $language;
            break;
        }
        return $this->language;
    }

    /**
     * PHPTAL will inform translation service what encoding page uses.
     * Output of translate() must be in this encoding.
     */
    function setEncoding($encoding)
    {
        $this->encoding = $encoding;
    }

    /**
     * Set the domain to use for translations (if different parts of application are translated in different files.
     * This is not for language selection).
     */
    function useDomain($domain)
    {
        if (!array_key_exists($domain, $this->domains)) {
            $files = [
                base_path() . "/resources/lang/{$this->language}/{$domain}.php",
                base_path() . "/resources/lang/{$this->language}/domains/{$domain}.php",
                base_path() . "/lang/{$this->language}/domains/{$domain}.php"
            ];
            $found = false;
            foreach ($files as $file) {
                if (is_readable($file)) {
                    $found = true;
                    break;
                }
            }
            if ($found) {
                $this->domains[$domain] = include($file);
                $this->context = $this->domains[$domain];
            }
        } else {
            $this->context = $this->domains[$domain];
        }
        return $domain;
    }

    /**
     * Set XHTML-escaped value of a variable used in translation key.
     *
     * You should use it to replace all ${key}s with values in translated strings.
{'fraction_non_alphanumeric': 0.12266065388951522, 'fraction_numerical': 0.0009019165727170237, 'mean_word_length': 1.8823911630929175, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 27, 'https://': 2, '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': '889206', 'n_tokens_mistral': 1206, 'n_tokens_neox': 1151, 'n_words': 327}