Download the PHP package paschaldev/eloquent-translate without Composer

On this page you can find all versions of the php package paschaldev/eloquent-translate. 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 eloquent-translate

A package to translate Laravel eloquent Models easily

This package serves as the complete solution to handling translations in a laravel application for data stored in the database. Translations for every model are stored in a database table. By default, automatic translation is enabled. Automatic translation uses third party provider(s) to translate your database attributes, the default for now is Google Translate API. If you choose not to use a third party translation service, you can also manually set your translation for any model.

Installation

You can install easily via composer.

The package will automatically register itself for supported laravel versions, if not, you should add this to your providers array in config/app.php

Then after that you can publish

This will copy the configuration to your config path.

For Lumen, open your bootstrap/app.php and add this line to register a provider

And this line to setup configuration

Then run php artisan migrate to create the translations table. The default table name is translations but you can override this value in the configuration file.

Setup

In order to make a model translatable, you need to include the trait in your model and also set the translateAttributes property. This properties are the attributes you wish to translate in that particukar DB column.

Once you have this done on your model, any update or create action on your model will automatically create your translations if you have the auto_translate set to true in your configuration.

Resolving trait collisions

This package uses the getAttribute method in your model, you might already be using that or a library you have is using that. You'll start getting errors during translations because multiple packages are trying to set the same methods on a model.

If you don't have a package that uses the getAttribute property, you can skip this section.

In order to resolve this, you need to make use of the as keyword in your traits. For my own scenario, I had this library Metable that already uses the getAttribute method so here is how to resolve this issue.

As you can see, using the as, we can alias the getAttribute method of each individual package so that we can still have access to it. Lastly, you need to define a getAttribute method in your model if one does not exist and call the translation's method last and pass $attr as the second parameter. The $attr stands for the final resolved attribute from all library's after collusion. After that, you're good to go.

Usage

Setting Translation

Please see the configuration file eloquent-translate.php after publishing for all possible options.

Originally, this package registers an observer to listen to the created and updated event in your model then automatically translate the attributes if you have auto_translate set to true in your configuration using a third party provider, the default for now is Google Translate API.

If you're going to be using Google Translate API, you need to get a Google API Key from Google Console Cloud, make sure you enable translation API then copy and paste this key in your configuration file's google_api_key.

Automatic translation will likely slow down your app becuase it has to connect to Google and depending on the number of locales you set for it to translate to, your app will drag and might become unresponsive.

In order to fix this, make sure queue is set to true and you can optionally specify a queue_name to use. Please see Laravel's documentation on Queue if you don't understand how queues work.

Define your locales in the configuration file and when the package will translate your attributes to each of the locales defined.

If you prefer not to use automatic translation, you can manually set translations individually for your models. There are two methods available.

The attribute name, make sure it is defined in your $translateAttributes array in your model. The $locale you want to set and the translation.

The $force argument if set to true will make you add attribute even if the attributes are not defined in your model file.

You can also set all your translations for a model in multiple locales at a go.

Use it like this.

In the code above, we are setting translations for the name attribute on the model assuming the value is Good Morning to 3 locales at once: French, Igbo, Yoruba.

Fetching Translation


All versions of eloquent-translate with dependencies

PHP Build Version
Package Version
Requires viniciusgava/google-translate-api Version dev-master
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 paschaldev/eloquent-translate contains the following files

Loading the files please wait ....