<commit_before><?php
namespace DrdPlus\Codes\Partials;

/**
 * @method static TranslatableCode getIt($codeValue)
 */
abstract class TranslatableCode extends AbstractCode
{

    /**
     * @param string $languageCode
     * @param int|float $amount
     * @return string
     */
    public function translateTo(string $languageCode, $amount = 1): string
    {
        $code = $this->getValue();
        $translations = $this->getTranslations($languageCode);
        $plural = $this->convertAmountToPlural($amount);
        if (($translations[$code][$plural] ?? null) !== null) {
            return $translations[$code][$plural];
        }
        if ($languageCode === 'en') {
            return str_replace('_', ' ', $code); // just replacing underscores by spaces
        }
        trigger_error(
            "Missing translation for value '{$code}', language '{$languageCode}' and plural '{$plural}'"
            . ', english will be used instead',
            E_USER_WARNING
        );
        $translations = $this->getTranslations('en');
        if (($translations[$code][$plural] ?? null) !== null) {
            return $translations[$code][$plural]; // explicit english translation
        }

        return str_replace('_', ' ', $code); // just replacing underscores by spaces
    }

    /**
     * @param number $amount
     * @return string
     */
    private function convertAmountToPlural($amount): string
    {
        $amount = abs($amount);
        if ($amount <= 1) {
            return 'one';
        }
        if ($amount < 5) {
            return 'few';
        }

        return 'many';
    }<commit_msg>Few amount with decimal part can be translated<commit_after><?php
namespace DrdPlus\Codes\Partials;

/**
 * @method static TranslatableCode getIt($codeValue)
 */
abstract class TranslatableCode extends AbstractCode
{

    /**
     * @param string $languageCode
     * @param int|float $amount
     * @return string
     */
    public function translateTo(string $languageCode, $amount = 1): string
    {
        $code = $this->getValue();
        $translations = $this->getTranslations($languageCode);
        $plural = $this->convertAmountToPlural($amount);
        if (($translations[$code][$plural] ?? null) !== null) {
            return $translations[$code][$plural];
        }
        if ($plural === 'few_decimal') {
            $plural = 'few';
            if (($translations[$code][$plural] ?? null) !== null) {
                return $translations[$code][$plural];
            }
        }
        if ($languageCode === 'en') {
            return str_replace('_', ' ', $code); // just replacing underscores by spaces
        }
        trigger_error(
            "Missing translation for value '{$code}', language '{$languageCode}' and plural '{$plural}'"
            . ', english will be used instead',
            E_USER_WARNING
        );
        $translations = $this->getTranslations('en');
        if (($translations[$code][$plural] ?? null) !== null) {
            return $translations[$code][$plural]; // explicit english translation
        }

        return str_replace('_', ' ', $code); // just replacing underscores by spaces
    }

    /**
     * @param number $amount
     * @return string
     */
    private function convertAmountToPlural($amount): string
    {
        $amount = abs($amount);
        if ($amount === 1 || $amount === 1.1) {
            return 'one';
        }
        if ($amount < 5) {
            if (strpos((string)$amount, '.') !== false) {
                return 'few_decimal';
            }

            return 'few';
        }

        return 'many';
    }
{'fraction_non_alphanumeric': 0.1487603305785124, 'fraction_numerical': 0.0022038567493112946, 'mean_word_length': 2.1601392515230637, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 11, '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': '813397', 'n_tokens_mistral': 1023, 'n_tokens_neox': 996, 'n_words': 243}