/** * Get the correct form of a word * * @param string $word The word to fetch * @param string $patterns A particular patterns array to fetch from * @return string Correct form of the word */ protected static function getWord($word, $patterns = 'patterns') { // If the world is invariable, don't touch it if (static::invariable($word)) { return $word; } // If it's irregular, return the correct form if (!is_null(static::irregular($word))) { return static::irregular($word); } // Else look for patterns ans replace foreach (Babel::translate('accord/' . static::$repository . '.' . $patterns) as $pattern => $replace) { if (preg_match($pattern, $word)) { return preg_replace($pattern, $replace, $word); } } // Special case for english language to use Laravel's plural function if (Babel::lang() == 'en' and static::$repository == 'plurals') { return Str::plural($word); } return $word; }
/** * Automatic transation and verb setting * * @param string $method The kind of word to translate * @param string $parameters The key to get * @return string Translated word */ public static function __callStatic($method, $parameters) { // Check for an extended sentence if (isset(static::$extend[$method])) { return call_user_func_array(static::$extend[$method], $parameters); } // Get a custom translation if (in_array($method, array('adjective', 'article', 'bit', 'noun', 'number', 'plural', 'state', 'verb'))) { $word = array_get($parameters, 0); if (is_null($word)) { return false; } return Babel::translate($method . 's.' . $word, $word); } // Verb setting $parameters[] = rtrim($method, 'd'); return call_user_func_array('static::many', $parameters); }