frank-l93 / ai-inflector
AI-powered singular and plural inflection for Laravel using Google Gemini.
Fund package maintenance!
Requires
- php: ^8.3
- illuminate/console: ^12.0||^13.0
- illuminate/http: ^12.0||^13.0
- illuminate/support: ^12.0||^13.0
Requires (Dev)
- larastan/larastan: ^3.9
- laravel/pao: ^1.0
- laravel/pint: ^1.29
- orchestra/testbench: ^10.0||^11.0
- pestphp/pest: ^4.6||^5.0
- pestphp/pest-plugin-laravel: ^4.1||^5.0
- pestphp/pest-plugin-type-coverage: ^4.0||^5.0
- phpstan/extension-installer: ^1.4
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Ai Inflector
AI-powered singular and plural inflection for Laravel, using Google Gemini with cached results and a Laravel string fallback.
Requirements
- PHP 8.3 or later
- Laravel 12 or 13
- A Google Gemini API key for AI-powered inflection
Without an API key, or when the Gemini request fails, the package falls back to Laravel's Str::plural() and Str::singular() helpers. These fallbacks use Laravel's English inflection rules and may not match the requested locale.
Installation
Install the package with Composer:
composer require frank-l93/ai-inflector
Laravel discovers the service provider automatically. Set the API key and, optionally, a default locale and Gemini model in your application's .env file:
GEMINI_API_KEY=your-gemini-api-key AI_INFLECTOR_LOCALE=nl GEMINI_INFLECTOR_MODEL=gemini-2.0-flash
The default locale is nl, and the default model is gemini-2.0-flash. You can keep the package defaults or publish the config file to review and customize them:
php artisan vendor:publish --tag=ai-inflector-config
The published file is config/ai-inflector.php. Environment values are read from that config file, so they work with Laravel's config cache.
Usage
Use the facade to get plural or singular forms. The locale argument overrides the configured default for that call:
use AiInflector\AiInflector\Facades\AiInflector; $plural = AiInflector::plural('computer', 2, 'nl'); $singular = AiInflector::singular('computers', 'nl');
The plural method accepts a count and returns the original word without an API call when the count is 1. Non-empty results are cached indefinitely in Laravel's default cache store.
The package also provides an Artisan command. Plural is the default type; the command accepts plural or singular and an optional locale:
php artisan ai-inflector:inflect computer php artisan ai-inflector:inflect computers --type=singular --locale=nl
Clear cached inflection results without flushing unrelated application cache entries:
php artisan ai-inflector:cache:clear
Changelog
See CHANGELOG.md for release history.
Contributing
Bug reports and pull requests are welcome. See the contribution guide and run the full validation suite before submitting changes:
composer test
Security
Please report vulnerabilities privately using the process in the security policy.
License
Ai Inflector is open-source software licensed under the MIT License.