Search by

frank-l93 / ai-inflector

Frank-L93

AI-powered singular and plural inflection for Laravel using Google Gemini.

Package info

github.com/Frank-L93/ai-inflector

Homepage

pkg:composer/frank-l93/ai-inflector

Fund package maintenance!

frank-l93

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 1

v0.1.0 2026-10-03 08:26 UTC

This package is auto-updated.

Last update: 2026-10-31 05:52:51 UTC


README

Ai Inflector

Latest version on Packagist Supported PHP versions Laravel versions Test workflow status Total Downloads

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.