Download the PHP package rawnoq/laravel-locale-detector without Composer

On this page you can find all versions of the php package rawnoq/laravel-locale-detector. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-locale-detector

Laravel Locale Detector

A professional Laravel package for automatic locale detection from HTTP headers and translation key extraction from your codebase.

๐Ÿ“‹ Table of Contents

โœจ Features

๐Ÿ“ฆ Requirements

๐Ÿš€ Installation

Step 1: Install via Composer

The package will be automatically discovered and registered by Laravel.

Step 2: Publish Configuration (Optional)

This will publish the configuration file to config/locale-detector.php.

Step 3: Publish Language Files (Optional)

This will publish language files to lang/ directory. The package includes translation files for 40+ languages (auth, pagination, passwords, validation).

โš™๏ธ Configuration

The configuration file is located at config/locale-detector.php:

Environment Variables

You can configure the package using environment variables in your .env file:

๐ŸŽฏ Usage

Automatic Locale Detection

The middleware automatically detects the user's preferred language from the Accept-Language header and sets the application locale accordingly.

No additional code required! The middleware is automatically registered and works out of the box.

Manual Locale Setting

You can still manually set the locale in your code:

Accessing Current Locale

๐Ÿ” Translation Key Extraction

The package provides a powerful command to extract all translation keys from your codebase.

Basic Usage

Options

Option Description Default
--path The path to search for translation keys base_path()
--output The output file path for extracted keys Display in console
--format Output format (json, php, array) json
--exclude Comma-separated paths to exclude None
--namespace Filter keys by namespace None
--with-location Include file path and line number for each key false

Examples

Extract Keys from App Directory

Extract Keys and Save to File

Extract Keys in PHP Format

Exclude Vendor and Storage Directories

Filter Keys by Namespace

This will only extract keys that start with blog::.

Extract Keys with Location Information

This will extract keys with file path and line number information. The output will include:

Example output:

Supported Translation Patterns

The command extracts keys from the following patterns:

Output Formats

JSON Format

PHP Format

Array Format

๐ŸŒ Translatable Models

The package provides a wrapper for Astrotomic Translatable with additional helper methods and utilities.

Using the Translatable Trait

Creating Models with Translations

Converting Translation Formats

The package provides helper functions to convert between different translation formats:

Using Helper Functions

Using Model Methods

Database Migrations with Translations

The package provides helper traits and classes for creating translation tables:

Using MigrationWithTranslations

Using the Trait Directly

Using UUID for Foreign Keys

๐ŸŽ“ Advanced Usage

Custom Locale Detection

You can customize the locale detection logic by modifying the middleware or creating your own:

Integration with HMVC Modules

If you're using the rawnoq/laravel-hmvc package, you can extract translation keys from modules:

Automated Translation Key Management

You can create a script to automatically extract and update translation files:

๐Ÿ”ง Troubleshooting

Middleware Not Working

If locale detection is not working:

  1. Check if middleware is registered: php artisan route:list
  2. Verify configuration: php artisan config:show locale-detector
  3. Check Accept-Language header in requests
  4. Ensure supported locales are configured correctly

Translation Keys Not Found

If the extraction command finds no keys:

  1. Verify the path contains PHP files
  2. Check if translation functions are used correctly
  3. Ensure files are readable
  4. Check excluded paths

Command Not Found

If locale:extract-keys command is not found:

  1. Run php artisan package:discover
  2. Clear cache: php artisan optimize:clear
  3. Verify Service Provider is registered

๐Ÿ“ Examples

Example 1: Extract All Keys

Example 2: Extract from Specific Path

Example 3: Extract and Save to File

Example 4: Extract with Exclusions

Example 5: Extract Namespaced Keys Only

๐Ÿค Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

๐Ÿงช Testing

The package comes with a comprehensive test suite:

Test Coverage

The test suite includes:

๐Ÿ“„ License

This package is open-sourced software licensed under the MIT license.

๐Ÿ™ Credits


Made with โค๏ธ for the Laravel community


All versions of laravel-locale-detector with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
astrotomic/laravel-translatable Version ^11.16
illuminate/http Version ^11.0|^12.0
illuminate/support Version ^11.0|^12.0
symfony/http-foundation Version ^7.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package rawnoq/laravel-locale-detector contains the following files

Loading the files please wait ...