Skip to content

Commit ef7eab3

Browse files
Gummibeergitbook-bot
authored andcommitted
GitBook: [master] 4 pages modified
1 parent cc23b2a commit ef7eab3

File tree

4 files changed

+103
-2
lines changed

4 files changed

+103
-2
lines changed

docs/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,14 @@
22

33
[![Total Downloads](https://img.shields.io/packagist/dt/astrotomic/laravel-translatable.svg?style=flat-square)](https://packagist.org/packages/astrotomic/laravel-translatable) [![CircleCI](https://img.shields.io/circleci/build/github/Astrotomic/laravel-translatable/master.svg?label=CircleCI&style=flat-square)](https://circleci.com/gh/Astrotomic/laravel-translatable) [![StyleCI](https://styleci.io/repos/192333549/shield)](https://styleci.io/repos/192333549) [![Code Quality](https://img.shields.io/scrutinizer/quality/g/Astrotomic/laravel-translatable/master.svg?style=flat-square)](https://scrutinizer-ci.com/g/Astrotomic/laravel-translatable/) [![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/Astrotomic/laravel-translatable/master.svg?style=flat-square)](https://scrutinizer-ci.com/g/Astrotomic/laravel-translatable/) [![Latest Version](http://img.shields.io/packagist/v/astrotomic/laravel-translatable.svg?style=flat-square)](https://packagist.org/packages/astrotomic/laravel-translatable) ![MIT License](https://img.shields.io/github/license/Astrotomic/laravel-translatable.svg?color=blue&style=flat-square)
44

5+
![](.gitbook/assets/laravel-translatable.png)
6+
7+
**If you want to store translations of your models into the database, this package is for you.**
8+
9+
This is a Laravel package for translatable models. Its goal is to remove the complexity in retrieving and storing multilingual model instances. With this package you write less code, as the translations are being fetched/saved when you fetch/save your instance.
10+
11+
#### Tutorials
12+
13+
* [How To Add Multilingual Support to Eloquent](https://laravel-news.com/how-to-add-multilingual-support-to-eloquent)
14+
* [How To Build An Efficient and SEO Friendly Multilingual Architecture For Your Laravel Application](https://mydnic.be/post/how-to-build-an-efficient-and-seo-friendly-multilingual-architecture-for-your-laravel-application)
15+

docs/SUMMARY.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Table of contents
22

33
* [Introduction](README.md)
4-
* [Changelog](changelog.md)
54
* [Issues](issues.md)
5+
* [Changelog](changelog.md)
6+
7+
## Usage
8+
9+
* [Installation](usage/installation.md)
610

docs/changelog.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# Changelog
22

3-
## next release
3+
## v11.0.0
44

55
* Add PHP7 type-hints [\#557](https://github.com/dimsav/laravel-translatable/pull/557)
6+
* Move to `Astrotomic` [\#1](https://github.com/Astrotomic/laravel-translatable/pull/1) & [\#4](https://github.com/Astrotomic/laravel-translatable/pull/4)
67

78
## v10.0.0
89

docs/usage/installation.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Installation
2+
3+
### Install package
4+
5+
Add the package in your `composer.json` by executing the command.
6+
7+
```bash
8+
composer require astrotomic/laravel-translatable
9+
```
10+
11+
### Configuration
12+
13+
We copy the configuration file to our project.
14+
15+
```bash
16+
php artisan vendor:publish --tag=translatable
17+
```
18+
19+
{% hint style="info" %}
20+
There isn't any restriction for the format of the locales. Feel free to use whatever suits you better, like "eng" instead of "en", or "el" instead of "gr". The important is to define your locales and stick to them.
21+
{% endhint %}
22+
23+
### Migrations
24+
25+
In this example, we want to translate the model `Post`. We will need an extra table `post_translations`:
26+
27+
{% code-tabs %}
28+
{% code-tabs-item title="create\_posts\_table.php" %}
29+
```php
30+
Schema::create('posts', function(Blueprint $table) {
31+
$table->increments('id');
32+
$table->string('author');
33+
$table->timestamps();
34+
});
35+
```
36+
{% endcode-tabs-item %}
37+
{% endcode-tabs %}
38+
39+
{% code-tabs %}
40+
{% code-tabs-item title="create\_post\_translations\_table" %}
41+
```php
42+
Schema::create('post_translations', function(Blueprint $table) {
43+
$table->increments('id');
44+
$table->integer('post_id')->unsigned();
45+
$table->string('locale')->index();
46+
$table->string('title');
47+
$table->text('content');
48+
49+
$table->unique(['post_id', 'locale']);
50+
$table->foreign('post_id')->references('id')->on('posts')->onDelete('cascade');
51+
});
52+
```
53+
{% endcode-tabs-item %}
54+
{% endcode-tabs %}
55+
56+
### Models
57+
58+
The translatable model `Post` should [use the trait](http://www.sitepoint.com/using-traits-in-php-5-4/) `Astrotomic\Translatable\Translatable`. The default convention for the translation model is `PostTranslation`. The array `$translatedAttributes` contains the names of the fields being translated in the `PostTranslation` model.
59+
60+
{% code-tabs %}
61+
{% code-tabs-item title="Post.php" %}
62+
```php
63+
class Post extends Eloquent
64+
{
65+
use \Astrotomic\Translatable\Translatable;
66+
67+
public $translatedAttributes = ['title', 'content'];
68+
protected $fillable = ['author'];
69+
}
70+
```
71+
{% endcode-tabs-item %}
72+
{% endcode-tabs %}
73+
74+
{% code-tabs %}
75+
{% code-tabs-item title="PostTranslation.php" %}
76+
```php
77+
class PostTranslation extends Eloquent
78+
{
79+
public $timestamps = false;
80+
protected $fillable = ['title', 'content'];
81+
}
82+
```
83+
{% endcode-tabs-item %}
84+
{% endcode-tabs %}
85+

0 commit comments

Comments
 (0)