Download the PHP package bambolee-digital/translatable-resource-kit without Composer

On this page you can find all versions of the php package bambolee-digital/translatable-resource-kit. 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 translatable-resource-kit

Bambolee Translatable Resource Kit

Latest Version on Packagist Total Downloads License

The Bambolee Translatable Resource Kit is a powerful extension for Laravel applications using Spatie's Laravel Translatable package. It simplifies the handling of translated attributes in API responses and dynamic JSON structures, making it easier to develop multilingual applications.

Features

Installation

You can install the package via composer:

Configuration

After installation, publish the configuration file:

This will create a config/translatable-resource-kit.php file where you can customize the behavior of the package.

You can customize the middleware behavior in this configuration file:

Added set_locale

To apply the SetLocale middleware to your API routes, you can add it to your routes/api.php file. Here's a comprehensive example of how to do this:

  1. Open your routes/api.php file.
  2. Add the middleware to your API route group like this:

Disabling the Middleware

If you want to disable the automatic registration of the middleware, set the disable_middleware option to true in your configuration file.

Usage

1. Use the TranslatesAttributes trait in your model:

2. Create a Resource for your model:

3. Create a Collection for your model:

4. Use in your controller:

5. Using the middleware:

The middleware is automatically registered by the package in the group specified in the configuration (default is 'api'). You can set the locale by adding a lang query parameter to your API requests, e.g., ?lang=pt for Portuguese.

If you've disabled the automatic middleware registration, you can manually register it using one of these methods:

  1. In your app/Providers/AppServiceProvider.php:

  2. In your routes/api.php:

  3. For Laravel versions with app/Http/Kernel.php:

Example

Here's an example of how the JSON response changes when using this package:

Before:

After (assuming the current locale is 'pt', set via ?lang=pt):

As you can see, the translated fields are automatically resolved to the current locale, simplifying the structure and making it easier to work with in frontend applications.

Advanced Usage

Customizing Recursion Depth

You can customize the maximum recursion depth for nested translations in the config/translatable-resource-kit.php file:

Handling Nested Relations

The TranslatesAttributes trait automatically handles nested relations. Make sure your relations are properly defined in your model's $with property:

Customizing the Query Parameter

If you want to use a different query parameter instead of lang, you can modify the SetLocale middleware. You'll need to publish the middleware to your application:

Then, edit the published middleware file in app/Http/Middleware/SetLocale.php to change the query parameter name.

Changelog

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

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security-related issues, please email [email protected] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.


All versions of translatable-resource-kit with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
illuminate/support Version ^9.0|^10.0|^11.0
spatie/laravel-translatable Version ^5.0|^6.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 bambolee-digital/translatable-resource-kit contains the following files

Loading the files please wait ....