coderscantina/laravel-translations

Database driven translation for your Laravel application.
6,623
Install
composer require coderscantina/laravel-translations
Latest Version:v1.1.0
PHP:^8.0
License:MIT
Last Updated:Mar 10, 2025
Links: GitHub  ·  Packagist
Maintainer: badmike

Laravel Database Translation from Coder's Cantina

A powerful, database-driven translation system for Laravel applications. Store, manage, and retrieve translations directly from your database, with full integration with Laravel's built-in translation system.

Features

  • Database Storage: Store all translations in your database for easy management
  • Laravel Integration: Seamlessly integrates with Laravel's built-in translation system
  • Placeholder Support: Full support for placeholders in translations
  • Fallback Support: Cascading language fallbacks
  • Import/Export: Import and export translations from/to JSON files
  • Command Line Tools: Comprehensive set of Artisan commands to manage translations

Getting started

  • Install this package

Installation

Requirements

  • PHP 8.0 or higher
  • Laravel 8.0 or higher

Via Composer

composer require coderscantina/translations

The package will automatically register its service provider.

Publish Configuration

Optionally publish the configuration file:

php artisan vendor:publish --provider="CodersCantina\Translations\ServiceProvider" --tag="config"

Run Migrations

Create the translations table:

php artisan migrate

Usage

Adding Translations

Via Artisan Command

# Basic usage
php artisan translations:add welcome.message 'Welcome to our application'

# With language option
php artisan translations:add welcome.message 'Willkommen in unserer Anwendung' --lang=de

# With namespace
php artisan translations:add welcome.message 'Welcome to our application' --namespace=frontend

Via Code

use CodersCantina\Translations\Translation;

Translation::create([
    'key' => 'welcome.message',
    'value' => 'Welcome to our application',
    'language_iso' => 'en'
]);

Retrieving Translations

Use Laravel's built-in methods for retrieving translations, such as Lang::get(), __ and trans helpers.

// Using the __ helper
echo __('welcome.message'); // 'Welcome to our application'

// With replacements
echo __('welcome.user', ['name' => 'John']); // 'Welcome, John'

// Specifying language
echo __('welcome.message', [], 'de'); // 'Willkommen in unserer Anwendung'

// Using the trans helper
echo trans('welcome.message');

// Using the facade
use Illuminate\Support\Facades\Lang;
echo Lang::get('welcome.message');

Organizing Translations

We strongly recommend using dot notation to logically group translations:

auth.login.title
auth.login.email
auth.login.password
auth.register.title
errors.validation.required
errors.server.unavailable

Change log

Please see CHANGELOG for more information on what has changed recently.

Testing

$ composer test

Related Packages

arcanedev/laravel-lang

Translations manager and checker for Laravel 5 based on 'caouecs/laravel4-lang'...

71,636 70
barryvdh/laravel-translation-manager

Manage Laravel Translations

4,060,841 1,701
vsch/laravel-translation-manager

Enhanced Laravel Translation Manager

191,586 183
cipherpols/laravel-translation

In-database Translator for Laravel

224 8