PHPackages                             giovani/spelling - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Validation &amp; Sanitization](/categories/validation)
4. /
5. giovani/spelling

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

giovani/spelling
================

PHP spell checking library with Composite Pattern — Brazilian Portuguese (pt\_BR) and American English (en\_US) rules, Enchant dictionary support, and custom word lists.

v2.0.0(1mo ago)02MITPHPPHP ^8.1

Since Apr 28Pushed 2mo agoCompare

[ Source](https://github.com/GiovaniRodrigo/laravel-spelling-lib)[ Packagist](https://packagist.org/packages/giovani/spelling)[ Docs](https://github.com/giovani/spelling)[ RSS](/packages/giovani-spelling/feed)WikiDiscussions dev Synced 3w ago

READMEChangelog (1)Dependencies (4)Versions (4)Used By (0)

giovani/spelling
================

[](#giovanispelling)

**PHP spell checking library with Composite Pattern — Brazilian Portuguese (pt\_BR) and American English (en\_US).**

[![PHP Version](https://camo.githubusercontent.com/7535257ca228724c93658bd52583d4e47a9bab02c356abf6e54c1d575f2151e6/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e312532422d626c75652e737667)](https://php.net)[![License: MIT](https://camo.githubusercontent.com/784362b26e4b3546254f1893e778ba64616e362bd6ac791991d2c9e880a3a64e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d677265656e2e737667)](LICENSE)[![Latest Stable Version](https://camo.githubusercontent.com/34f8746c27cc759ff279a0ddfa02f112a783194fbe36eb40f734dd2cf9bf9c45/68747470733a2f2f706f7365722e707567782e6f72672f67696f76616e692f7370656c6c696e672f762f737461626c65)](https://packagist.org/packages/giovani/spelling)[![Total Downloads](https://camo.githubusercontent.com/034e062bf6a35eaf1f2459fafaed61b091b56b495ebd722a1c50ebb668c9f3c8/68747470733a2f2f706f7365722e707567782e6f72672f67696f76616e692f7370656c6c696e672f646f776e6c6f616473)](https://packagist.org/packages/giovani/spelling)

---

Features
--------

[](#features)

- **Brazilian Portuguese rules** — 2009 Spelling Reform: trema removal, open diphthong accents, hyphenation
- **American English rules** — US vs UK spelling, pronoun `I` capitalization, days/months enforcement
- **System dictionary support** — via PHP `ext-enchant` (Hunspell, Aspell), any language
- **Custom word lists** — allowlist domain-specific vocabulary at runtime
- **Composite Pattern** — chain multiple checkers transparently with unanimous AND logic
- **Spell suggestions** — every checker surfaces correction candidates via `getSuggestions()`

---

Requirements
------------

[](#requirements)

DependencyVersionNotesPHP`^8.1`Required`doctrine/inflector``^2.0`Required`ext-enchant`anyOptional — only needed for `EnchantChecker`---

Installation
------------

[](#installation)

```
composer require giovani/spelling
```

### Optional: system dictionaries for `EnchantChecker`

[](#optional-system-dictionaries-for-enchantchecker)

```
# Ubuntu / Debian
sudo apt-get install aspell-pt-br hunspell-pt-br

# macOS
brew install enchant
```

Verify the extension is loaded:

```
php -m | grep enchant
```

---

Quick Start
-----------

[](#quick-start)

### Brazilian Portuguese (recommended)

[](#brazilian-portuguese-recommended)

```
use Giovani\Spelling\SpellingFactory;

$checker = SpellingFactory::createDefault();

// Post-reform words are accepted
$checker->isValid('ideia');    // true
$checker->isValid('linguiça'); // true

// Pre-reform forms are rejected and corrected
$checker->isValid('idéia');    // false
$checker->getSuggestions('idéia');    // ['ideia']
$checker->getSuggestions('lingüiça'); // ['linguiça']

// Months and days of the week must be lowercase in pt_BR
$checker->isValid('janeiro');  // true
$checker->isValid('Janeiro');  // false
$checker->getSuggestions('Janeiro'); // ['janeiro']
```

### With a custom vocabulary

[](#with-a-custom-vocabulary)

Pass additional words that should always be accepted (brand names, technical terms, etc.):

```
$checker = SpellingFactory::createDefault(['MinhaMarca', 'Laravel', 'NomeTécnico']);

$checker->isValid('minhamarca'); // true
$checker->isValid('laravel');    // true
```

### American English

[](#american-english)

```
use Giovani\Spelling\Checkers\CompositeSpellingChecker;
use Giovani\Spelling\Checkers\AmericanEnglishRulesChecker;
use Giovani\Spelling\Checkers\EnchantChecker;

$composite = new CompositeSpellingChecker();
$composite->addChecker(new AmericanEnglishRulesChecker());
$composite->addChecker(new EnchantChecker('en_US'));

$composite->isValid('color');   // true
$composite->isValid('colour');  // false — British spelling rejected
$composite->getSuggestions('colour'); // ['color']

$composite->isValid('I');       // true
$composite->isValid('i');       // false — pronoun must be capitalized
$composite->getSuggestions('i'); // ['I']

$composite->isValid('Monday');  // true
$composite->isValid('monday');  // false
```

### Building fully custom composites

[](#building-fully-custom-composites)

```
use Giovani\Spelling\Checkers\CompositeSpellingChecker;
use Giovani\Spelling\Checkers\PortugueseRulesChecker;
use Giovani\Spelling\Checkers\SimpleSpellingChecker;

$composite = new CompositeSpellingChecker();
$composite->addChecker(new PortugueseRulesChecker());
$composite->addChecker(new SimpleSpellingChecker(['PHP', 'Composer', 'Packagist']));

$composite->isValid('php');    // true
$composite->isValid('idéia');  // false — Portuguese rule violation
```

---

Available Checkers
------------------

[](#available-checkers)

CheckerDescriptionLanguage`SimpleSpellingChecker`Validates against a custom in-memory allowlistAny`CompositeSpellingChecker`Chains multiple checkers (unanimous AND logic)Any`EnchantChecker`System dictionary via `ext-enchant`Any (`pt_BR`, `en_US`, …)`PortugueseRulesChecker`2009 Spelling Reform rules for pt\_BRPortuguese`AmericanEnglishRulesChecker`US spelling and capitalization conventionsEnglish (US)`InflectorChecker`Word normalization via Doctrine InflectorEnglishAll checkers implement the same interface:

```
interface SpellingCheckerInterface
{
    public function isValid(string $word): bool;

    /** @return string[] */
    public function getSuggestions(string $word): array;
}
```

---

Architecture
------------

[](#architecture)

The library is built on the **Composite design pattern**. `CompositeSpellingChecker` holds a collection of `SpellingCheckerInterface` leaves and requires **unanimous approval** — all checkers must return `true` for a word to be considered valid. Suggestions are aggregated from every checker and deduplicated.

```
SpellingCheckerInterface
├── CompositeSpellingChecker   ← groups checkers, AND logic, deduplicates suggestions
│   ├── PortugueseRulesChecker
│   ├── InflectorChecker
│   ├── EnchantChecker
│   └── SimpleSpellingChecker
└── (any custom checker implementing the interface)

```

`SpellingFactory::createDefault()` assembles the recommended pt\_BR stack automatically, with `EnchantChecker` added gracefully when `ext-enchant` is available.

---

Running Tests
-------------

[](#running-tests)

```
composer install
vendor/bin/phpunit
```

---

Documentation
-------------

[](#documentation)

Full documentation is available in the [`docs/`](docs/) directory:

- [Installation guide](docs/INSTALL.md)
- [Usage examples](docs/USAGE.md)
- [Architecture](docs/ARCHITECTURE.md)
- [Changelog](docs/CHANGELOG.md)
- [Contributing](docs/CONTRIBUTING.md)

---

Contributing
------------

[](#contributing)

Contributions, bug reports, and feature requests are welcome. Please open an issue or pull request on GitHub.

---

License
-------

[](#license)

MIT — see [LICENSE](LICENSE).

###  Health Score

37

—

LowBetter than 81% of packages

Maintenance88

Actively maintained with recent releases

Popularity2

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~56 days

Total

2

Last Release

31d ago

Major Versions

v0.1.0 → v2.0.02026-06-23

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/109702583?v=4)[Giovani](/maintainers/GiovaniRodrigo)[@GiovaniRodrigo](https://github.com/GiovaniRodrigo)

---

Top Contributors

[![GiovaniRodrigo](https://avatars.githubusercontent.com/u/109702583?v=4)](https://github.com/GiovaniRodrigo "GiovaniRodrigo (2 commits)")

---

Tags

validationspellingnlpenglishspell-checkerspell-checkportuguesept-BRen\_USortografiaenchantcomposite-patternreforma-ortografica

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/giovani-spelling/health.svg)

```
[![Health](https://phpackages.com/badges/giovani-spelling/health.svg)](https://phpackages.com/packages/giovani-spelling)
```

###  Alternatives

[composer/semver

Version comparison library that offers utilities, version constraint parsing and validation.

3.3k522.3M1.0k](/packages/composer-semver)[giggsey/libphonenumber-for-php

A library for parsing, formatting, storing and validating international phone numbers, a PHP Port of Google's libphonenumber.

5.0k159.6M539](/packages/giggsey-libphonenumber-for-php)[api-platform/core

Build a fully-featured hypermedia or GraphQL API in minutes!

2.6k51.2M353](/packages/api-platform-core)[respect/validation

The most awesome validation engine ever created for PHP

6.0k39.9M418](/packages/respect-validation)[propaganistas/laravel-phone

Adds phone number functionality to Laravel based on Google's libphonenumber API.

3.0k39.7M151](/packages/propaganistas-laravel-phone)[opis/json-schema

Json Schema Validator for PHP

65543.6M320](/packages/opis-json-schema)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
