pragmarx/glottos
Glottos is a Laravel package for managing application translations. It stores language strings in the database and gives developers a practical way to organize, edit, and serve multilingual content, reducing the need to maintain large language files by hand across projects.
Install the package
composer require pragmarx/glottos
Check the required PHP/Laravel versions in composer.json before pulling it in — the package targets PHP 5.3+ and an older Laravel era, so verify compatibility against your app first.
Register the service provider and facade in config/app.php:
'providers' => [
PragmaRX\Glottos\ServiceProvider::class,
],
'aliases' => [
'Glottos' => PragmaRX\Glottos\Facade::class,
],
Publish config and migrations
php artisan vendor:publish --provider="PragmaRX\Glottos\ServiceProvider"
php artisan migrate
The published config/glottos.php is the first file to open — it defines the translation services (Google, Bing, Yandex, etc.), their API keys, the storage driver, and the locale defaults.
Configure a translation service by adding the API key(s) in config/glottos.php (or your .env if the config reads from there). Without a key, external calls will fail.
First use case — translate a missing string and cache it:
use Glottos;
$translated = Glottos::translate('Welcome back', 'en', 'fr');
The value is returned and (depending on config) persisted to the glottos_* tables so subsequent lookups don't hit the external API.
First place to look after install: the published migrations (create_glottos_* tables) to understand the schema, then the package README's "Usage" section for the exact method signatures.
Translate-once, store-and-reuse. Glottos is a database-backed translation store as much as an API wrapper. Wrap lookups so the DB is checked before hitting an external service:
function t(string $text, string $from, string $to): string
{
return Cache::rememberForever("glottos:{$from}:{$to}:".md5($text), function () use ($text, $from, $to) {
return Glottos::translate($text, $from, $to);
});
}
Import → translate → export workflow. The most common day-to-day pattern is:
resources/lang/* files into Glottos (so the DB becomes the source of truth).Keep the exported files under version control so you can diff and review machine-translated strings before merging.
Use it as an authoring tool, not a runtime dependency. Calling an external API on every request is slow and rate-limited. Run translation as a build/deploy step (artisan command or queue job), commit the resulting lang files, and let Laravel's normal __()/trans() loader serve them. This decouples production traffic from Glottos entirely.
Service fallback chain. Configure more than one provider and catch failures at the call site — if Google is rate-limited, fall back to Bing/Yandex, and log the miss rather than throwing into the request:
try {
$value = Glottos::translate($text, 'en', 'de');
} catch (\Exception $e) {
Log::warning('glottos translate failed', ['text' => $text, 'e' => $e->getMessage()]);
$value = $text; // graceful degradation
}
Batch/queue translation. For large catalogs, dispatch translation jobs per-string or per-file so you don't block a request and can retry transient API errors with backoff.
Locale mapping. Keep your config/app.php locales and the package's glottos_languages rows in sync — mismatched codes (e.g. pt_BR vs pt-br) are the most common cause of "translation exists but isn't found."
Web UI for content editors. If you enable the package's management routes, put them behind admin middleware and keep them out of the public surface. It's an authoring interface, not a user-facing feature.
translate() will throw or return the source string — silently. Log and assert on missing keys at boot.:name and {count} — add a validation pass after export.php artisan config:clear, cache:clear, and view:clear. Stale config is a frequent "why isn't my key picked up" cause.glottos_-prefixed tables; if you already manage translations in the DB elsewhere, check for naming overlap before running migrate.resources/lang files are authoritative. Mixing both leads to drift; a common compromise is DB-authored, files exported, files deployed.How can I help you explore Laravel packages today?