PHPackages                             joelstein/laravel-t - 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. [Localization &amp; i18n](/categories/localization)
4. /
5. joelstein/laravel-t

ActiveLibrary[Localization &amp; i18n](/categories/localization)

joelstein/laravel-t
===================

Gettext PO-based translations for Laravel with ICU MessageFormat support

v0.2.0(1mo ago)192MITPHPPHP ^8.2

Since Apr 24Pushed 5d agoCompare

[ Source](https://github.com/joelstein/laravel-t)[ Packagist](https://packagist.org/packages/joelstein/laravel-t)[ Docs](https://github.com/joelstein/laravel-t)[ RSS](/packages/joelstein-laravel-t/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependencies (7)Versions (3)Used By (0)

Laravel T
=========

[](#laravel-t)

Gettext PO-based translations for Laravel with ICU MessageFormat support. Use source strings as keys — no more `auth.failed` style lookup tables — and manage translations with standard PO files that every translation tool already understands.

What It Does
------------

[](#what-it-does)

Replaces Laravel's key-based translator with a `t()` helper (and `@t()` Blade directive) that looks up translations by their English source string:

```
t('Hello, :name!', ['name' => $user->name])
```

- **PO files as the source of truth.** One `.po` file per locale, loaded via [gettext/gettext](https://github.com/php-gettext/Gettext). Works with Poedit, Crowdin, Weblate, and every other gettext-aware tool.
- **Readable fallbacks.** When a translation is missing, the source string renders as-is — no `translation.missing.key` artifacts.
- **ICU MessageFormat.** Full plural, select, and number formatting via PHP's `MessageFormatter`: `t('{count, plural, one {# item} other {# items}}', ['count' => $total])`.
- **Contextual translations.** Disambiguate identical strings with `msgctxt`: `t('May', context: 'month')`.
- **Closure-based inline markup.** Wrap translated text in dynamic tags without splitting the sentence: `t('Click here.', ['a' => fn ($s) => "{$s}"])`.
- **Cached in production.** Parsed PO files are cached through Laravel's cache system.

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

[](#requirements)

- PHP 8.2+
- Laravel 11 or 12
- `ext-intl` (for ICU MessageFormat)

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

[](#installation)

```
composer require joelstein/laravel-t
php artisan vendor:publish --tag=t-config
```

The service provider is auto-discovered. Create your translation directory (default `lang/t/`) and add a PO file per locale.

Usage
-----

[](#usage)

```
// Plain strings
t('Hello, world!')

// Named placeholders
t('Hello, :name!', ['name' => $user->name])

// ICU plurals
t('{count, plural, one {# item} other {# items}}', ['count' => $total])

// Contexts (for homographs)
t('May', context: 'month')

// Inline markup via closures
t('Click here.', [
    'a' => fn ($text) => "{$text}",
])

// Explicit locale override
t('Saved.', locale: 'es')
```

In Blade:

```
@t('Welcome back, :name!', ['name' => $user->name])
```

Commands
--------

[](#commands)

```
# Scan source files and update PO files for every configured locale
php artisan t:extract

# List untranslated strings, optionally for one locale
php artisan t:untranslated
php artisan t:untranslated es

# Validate PO files (parse errors, placeholder mismatches, invalid ICU)
php artisan t:lint
php artisan t:lint es

# Clear the translation cache
php artisan t:clear
```

`t:extract` preserves existing translations, adds new entries, and marks strings that no longer exist in source as obsolete (`#~` entries in the PO file). Obsolete translations keep the translator's work so they snap back if the source string reappears. Run `t:extract --purge` to hard-delete obsolete entries instead. The source locale (default `en`) gets `msgstr = msgid` auto-populated.

Fallback Chain
--------------

[](#fallback-chain)

When a translation is missing, the lookup walks a fallback chain:

1. The requested locale (e.g. `es_MX`)
2. The base locale, if the requested one has a region suffix (`es_MX` → `es`)
3. The configured `fallback_locale`, if set

If nothing in the chain has the string, the original msgid is returned. ICU formatting always uses the originally requested locale, so plural rules and number formats still match the user's region even when the translation comes from a fallback.

Configuration
-------------

[](#configuration)

`config/t.php`:

```
return [
    'path' => lang_path('t'),
    'source_locale' => 'en',
    'locales' => ['en'],
    'fallback_locale' => null,
    'scan_paths' => ['app', 'resources/views'],
    'cache' => null,       // null = cache in production only
    'cache_ttl' => 86400,
    'log_missing' => null, // true, a channel name, or null to disable
];
```

CI Integration
--------------

[](#ci-integration)

```
- name: Check translations are extracted
  run: |
    php artisan t:extract
    git diff --exit-code lang/t
```

Combine with `t:untranslated` to fail on missing translations when that matters for your release.

License
-------

[](#license)

MIT

###  Health Score

40

—

FairBetter than 86% of packages

Maintenance95

Actively maintained with recent releases

Popularity15

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity37

Early-stage or recently created project

 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 ~0 days

Total

2

Last Release

46d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0059aaf8eed7ca19ce7ed1aa4434990350f92e09b86c9fdf57e98f536ef4c765?d=identicon)[joelstein](/maintainers/joelstein)

---

Top Contributors

[![joelstein](https://avatars.githubusercontent.com/u/152397?v=4)](https://github.com/joelstein "joelstein (3 commits)")

---

Tags

laraveli18ntranslationsicugettextpo

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/joelstein-laravel-t/health.svg)

```
[![Health](https://phpackages.com/badges/joelstein-laravel-t/health.svg)](https://phpackages.com/packages/joelstein-laravel-t)
```

###  Alternatives

[spatie/laravel-pdf

Create PDFs in Laravel apps

1.0k4.3M41](/packages/spatie-laravel-pdf)[osama-98/laravel-enum-translatable

A Laravel package that provides translatable enum functionality with easy-to-use methods for working with enum values and their translations

561.1k](/packages/osama-98-laravel-enum-translatable)[askdkc/breezejp

Laravel Starter Kit (Livewire+Breeze+Laravel UI+Jetstream)や標準のバリデーションメッセージを全て一瞬で日本語化し、言語切替機能も提供するパッケージです / This package provides all-in-one Japanese translation for Laravel StarterKit (Livewire StarterKit, Breeze, Laravel UI and Jetstream) packages and validation messages with language switching feature.

594266.8k1](/packages/askdkc-breezejp)[outhebox/laravel-translations

Manage your Laravel translations with a beautiful UI. Add, edit, delete, import, and export translations with ease.

81096.3k](/packages/outhebox-laravel-translations)[rawilk/profile-filament-plugin

Profile &amp; MFA starter kit for filament.

3913.7k](/packages/rawilk-profile-filament-plugin)[elegantly/laravel-translator

All on one translations management for Laravel

6326.3k](/packages/elegantly-laravel-translator)

PHPackages © 2026

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