Download the PHP package sertxudeveloper/laravel-translatable without Composer

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

Laravel Translatable

Manage localized routes and use translatable models in a Laravel app.

Requirements

Installation

You can install this package using Composer.

Configuration

First you should publish the configuration file.

After running this command, you will now find a translatable.php`` file in theconfig` folder.

Locales available

You can set the locales availables in your application. The localized routes will be registered with all of these locales.

Fallback locale

The fallback locale should be the one that not require to be translated.

You can also hide the fallback locale from the URL prefix.

Routes

Register Routes

All the routes you want lo localize should be registered inside the Route::localized closure.

Inside this closure you can use Route Groups such as Middlewares, Namespaces or even Sub-Domain Routing. This closure will prepend the locale to the route's URI and name.

This will be the result of the viewed configuration examples.

URI Name Locale
/home home es - en - it
--- --- ---
/blog blog es
/es/blog es.blog es
/en/blog en.blog en
/it/blog it.blog it
--- --- ---
/{slug} page es
/es/{slug} es.page es
/en/{slug} en.page en
/it/{slug} it.page it
--- --- ---
/about about es - en - it

Beware that you don't register the same URL twice when omitting the locale. You can't have a localized /about route and also register a non-localized /about route in this case. The same idea applies to the / (root) route! Also note that the route names still have the locale prefix.

Generate Localized URLs

You should use the trans_route helper in order to get the requested route localized. To this helper you can pass a route name or a route url, in booth cases it will be localized.

If you pass only the route it will be localized using the current locale ('en').

You can also pass params to the helper.

The third param is a boolean to make it absolute or not.

The last param is used for specify the locale to use.

Switch Locale

If you're building a dropdown or similar with links to change the locale of the application, you should use the switch_to_locale helper.

Eloquent translations

Create translations tables

You can to customize the name of the translations tables.

The usage of this value will be the following one. If you have the model Page with the trait HasTranslations and the model table is pages. This package will look up for the translations at the table page_translations. Always the model table followed by the table suffix in the config file.

The translations tables should contain the translatable fields from the model, the id, a column locale to specify the language saved, created_at and updated_at. The column deleted_at should never be in the translations table, regardless the models is softDeleted or not.

As you can see in the following example,

Pages table

id name slug excerpt body image status created_at updated_at
int varchar varchar varchar text varchar enum datetime datetime

Pages translation table

id locale name excerpt body created_at updated_at
int varchar(2) varchar varchar text datetime datetime

Get Eloquent Translated Attribute

In order to get a translated attribute you should use the getTranslated method.

Cache Routes

In production, you can safely cache your routes per usual.



Copyright © 2022 Sertxu Developer


All versions of laravel-translatable with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1|^8.2
illuminate/contracts Version ^10.0|^11.0
illuminate/support Version ^10.0|^11.0
illuminate/database Version ^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 sertxudeveloper/laravel-translatable contains the following files

Loading the files please wait ....