Download the PHP package esign/laravel-translation-loader without Composer

On this page you can find all versions of the php package esign/laravel-translation-loader. 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-translation-loader

Load translations from the database or other sources

Latest Version on Packagist Total Downloads GitHub Actions

This package extends Laravel's default translation functionality, allowing you to load translations from different sources. It ships with a database loader that comes with automatic creation of missing keys and built-in caching support.

Installation

You can install the package via composer:

The package will automatically register a service provider.

This package comes with a migration to store translations in the database. You can publish the migration file with the following command:

This will publish the following migration:

Out of the box, it ships with support for the English language and uses our Underscore Translatable package to store these languages in different columns. You may add more languages as you wish.

Next up, you can optionally publish the configuration file:

The config file will be published as config/translation-loader.php with the following contents:

Usage

To create database translations you may use the create method on the Translation model:

For a more automated approach, consider automatic creation of database translations, eliminating the need for manual key creation.

Once created, you can retrieve the translations as usual in Laravel:

For all possibilities, please refer to the Localization docs from Laravel. Be aware that database-defined translations can overwrite file translations that may exist.

Handling missing translation keys

In situations where you request a translation key that doesn't exist, you have the option to provide a callback to the translator. This callback will be triggered when the requested translation key is not found. Please note that this callback will not be invoked if the translation key exists but has an empty or null value.

You can also customize the behavior of the translator by returning a specific value from the callback. This returned value will then be used as the translation for the missing key.

You may provide this callback using the setMissingKeyCallback method on the Esign\TranslationLoader\Facades\Translator facade:

In the provided closure, you can implement any custom logic you need to handle the missing translation keys. This might involve logging, sending notifications, or providing a default translation value based on your application's requirements.

Automatically creating missing translation keys

This package ships with the ability to automatically create database translations in case the key does not yet exist. You may activate this functionality by calling the createMissingTranslations on the Esign\TranslationLoader\Facades\Translator facade. This is typically done from a service provider within your application:

Note that this functionality will create translations under the * group. In case you need to change this behaviour you may do so by defining your own setMissingKeyCallback.

Registering a loader

If you need to gather translations from diverse sources, you can achieve this by creating a custom translation loader that implements the Esign\TranslationLoader\Contracts\TranslationLoaderContract interface:

Integrate your custom loader by including it in the loaders array within the configuration file of this package.

Caching database translations

By default, this package ensures efficient performance by caching your database translations for 24 hours. This caching mechanism uses the default cache driver that you have configured within your Laravel application.

If you wish to modify the cache duration or switch to a different cache store, please refer to the cache settings within the configuration file.

Clearing the translations cache

The translations cache is automatically maintained when you interact with the Esign\TranslationLoader\Models\Translation model. However, if you make changes outside of these operations, you need to manually clear the cache:

Importing file translations to the database

This package ships with an Artisan command that allows you to import file translations into the database. This can be useful when you want to migrate your translations from file-based to database-based storage. You should specify the locales you want to import translations for as a comma-separated list:

You can optionally specify the --overwrite flag to overwrite any existing translations.

FAQ

Installation conflict with [mcamara/laravel-localization](https://github.com/mcamara/laravel-localization) The laravel-localization package offers route translation functionality by leveraging Laravel's translator. However, conflicts may arise due to our package's override of Laravel's translator behavior. This can lead to potential database exceptions when querying translations, hindering the installation of our package. To tackle this problem, you can utilize contextual binding within a service provider of your application. This instructs Laravel to employ file-based translation solely when registering translated routes. Include the following code in a serviceprovider within your application: Note that this solution only works for any versions above `^2.0` of mcamara/laravel-localization.

Testing

License

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


All versions of laravel-translation-loader with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
esign/laravel-underscore-translatable Version ^1.1
illuminate/cache Version ^9.2|^10.0|^11.0
illuminate/console Version ^9.2|^10.0|^11.0
illuminate/database Version ^9.2|^10.0|^11.0
illuminate/support Version ^9.2|^10.0|^11.0
illuminate/translation Version ^9.2|^10.0|^11.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 esign/laravel-translation-loader contains the following files

Loading the files please wait ....