lang
List of 126 languages for Laravel Framework, Laravel Jetstream, Laravel Fortify, Laravel Breeze, Laravel Cashier, Laravel Nova, Laravel Spark and Laravel UI.
Top Related Projects
A Laravel package for multilingual models
Easy localization for Laravel
Manage Laravel translation files
List of 126 languages for Laravel Framework, Laravel Jetstream, Laravel Fortify, Laravel Breeze, Laravel Cashier, Laravel Nova, Laravel Spark and Laravel UI.
Quick Overview
Laravel-Lang/lang is a comprehensive language localization package for Laravel applications. It provides translations for Laravel's built-in validation messages, authentication strings, and pagination labels in numerous languages, making it easier for developers to create multilingual applications.
Pros
- Extensive language support with over 100 languages available
- Regular updates and community contributions to improve translations
- Easy integration with Laravel projects
- Includes JSON translations for JavaScript-based localization
Cons
- Some less common languages may have incomplete translations
- Occasional inconsistencies in translation quality across different languages
- Requires manual updates to stay current with the latest Laravel version
- May increase project size due to the inclusion of numerous language files
Code Examples
- Publishing language files:
php artisan lang:publish
This command publishes the language files to your Laravel project's resources/lang
directory.
- Setting the application locale:
App::setLocale('fr');
This code sets the application's locale to French.
- Using translations in views:
{{ __('auth.failed') }}
This Blade syntax retrieves the localized string for the 'auth.failed' key.
- Using translations in controllers:
$message = trans('validation.required', ['attribute' => 'email']);
This code retrieves a localized validation message, replacing the :attribute placeholder with 'email'.
Getting Started
-
Install the package via Composer:
composer require laravel-lang/lang
-
Publish the language files:
php artisan lang:publish
-
Set the desired locale in your
config/app.php
file:'locale' => 'es',
-
Use the
__()
helper function ortrans()
method in your application to retrieve localized strings:echo __('messages.welcome');
Competitor Comparisons
A Laravel package for multilingual models
Pros of laravel-translatable
- Allows for dynamic content translation within database models
- Supports multiple languages for each translatable field
- Provides a flexible and scalable solution for multilingual applications
Cons of laravel-translatable
- Requires additional database setup and model configuration
- May introduce complexity for simple translation needs
- Performance impact due to additional database queries for translations
Code Comparison
laravel-translatable:
use Astrotomic\Translatable\Translatable;
class Product extends Model
{
use Translatable;
public $translatedAttributes = ['name', 'description'];
}
lang:
// resources/lang/en/products.php
return [
'name' => 'Product Name',
'description' => 'Product Description',
];
Summary
laravel-translatable is ideal for complex, database-driven multilingual applications, offering dynamic content translation within models. However, it requires more setup and may impact performance. lang provides a simpler, file-based approach for static translations, which is easier to implement but less flexible for dynamic content. Choose based on your project's specific needs and complexity.
Easy localization for Laravel
Pros of laravel-localization
- Provides route localization and URL generation for multi-language applications
- Offers middleware for automatic language detection and switching
- Includes helper functions for language-related operations
Cons of laravel-localization
- Focuses on routing and URL management rather than translation management
- Requires manual creation and management of language files
- May have a steeper learning curve for beginners
Code Comparison
laravel-localization:
Route::group(['prefix' => LaravelLocalization::setLocale()], function() {
Route::get('/', 'HomeController@index');
});
lang:
// No equivalent routing functionality
// Translation usage:
__('messages.welcome');
Key Differences
lang is primarily a collection of pre-translated language files for Laravel applications, while laravel-localization is a package that provides routing and URL management tools for multi-language applications. lang offers a vast array of ready-to-use translations across numerous languages, making it easier to implement basic localization. On the other hand, laravel-localization gives developers more control over language switching and URL structure in multi-language applications but requires more setup and configuration.
Choose lang if you need quick access to pre-translated strings for multiple languages. Opt for laravel-localization if you require advanced routing and URL management for a multi-language application with custom language switching logic.
Manage Laravel translation files
Pros of laravel-translation-manager
- Provides a user-friendly interface for managing translations
- Allows real-time editing and importing of language files
- Supports automatic translation using Google Translate API
Cons of laravel-translation-manager
- Requires additional setup and configuration
- May introduce complexity for smaller projects
- Less frequently updated compared to lang
Code Comparison
lang:
return [
'accepted' => 'The :attribute must be accepted.',
'active_url' => 'The :attribute is not a valid URL.',
'after' => 'The :attribute must be a date after :date.',
// ...
];
laravel-translation-manager:
use Barryvdh\TranslationManager\Manager;
$manager = app(Manager::class);
$manager->importTranslations();
$translations = $manager->getTranslations();
lang focuses on providing pre-translated language files for Laravel applications, while laravel-translation-manager offers a more dynamic approach to managing translations. lang is easier to integrate and use out of the box, especially for projects that don't require frequent translation updates. laravel-translation-manager, on the other hand, provides more flexibility and control over the translation process, making it suitable for projects with complex localization needs or frequent updates to translations.
List of 126 languages for Laravel Framework, Laravel Jetstream, Laravel Fortify, Laravel Breeze, Laravel Cashier, Laravel Nova, Laravel Spark and Laravel UI.
Pros of lang
- More comprehensive language support with 85+ languages
- Active community contributions and frequent updates
- Includes validation messages and other Laravel-specific translations
Cons of lang
- Larger repository size due to extensive language files
- May include unnecessary languages for some projects
- Potentially slower to load all translations in memory
Code Comparison
lang:
return [
'accepted' => 'The :attribute must be accepted.',
'active_url' => 'The :attribute is not a valid URL.',
'after' => 'The :attribute must be a date after :date.',
// ... more translations
];
lang:
return [
'accepted' => 'The :attribute must be accepted.',
'active_url' => 'The :attribute is not a valid URL.',
'after' => 'The :attribute must be a date after :date.',
// ... more translations
];
Summary
Both repositories provide language translations for Laravel applications. lang offers a wider range of languages and more frequent updates, making it suitable for projects requiring extensive language support. However, this comes at the cost of a larger repository size and potentially slower loading times. The code structure is similar in both repositories, with lang potentially offering more comprehensive translations for Laravel-specific features.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Laravel Lang
Documentation
See the documentation for detailed installation.
Communication
We also have official chats in Telegram.
Contributing
Please see CONTRIBUTING for details.
Support Us
â¤ï¸ Laravel Lang? Please consider supporting our collective on Boosty.
License
This package is licensed under the MIT License.
Top Related Projects
A Laravel package for multilingual models
Easy localization for Laravel
Manage Laravel translation files
List of 126 languages for Laravel Framework, Laravel Jetstream, Laravel Fortify, Laravel Breeze, Laravel Cashier, Laravel Nova, Laravel Spark and Laravel UI.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot