<commit_before>Laravel Translator
==================

![image](https://raw.githubusercontent.com/vinkla/vinkla.github.io/master/images/laravel-translator.png)

This package gives you an easy way to translate Eloquent models into multiple languages.

[![Build Status](https://img.shields.io/travis/vinkla/translator/master.svg?style=flat)](https://travis-ci.org/vinkla/translator)
	[![Latest Stable Version](http://img.shields.io/packagist/v/vinkla/translator.svg?style=flat)](https://packagist.org/packages/vinkla/translator)
	[![License](https://img.shields.io/packagist/l/vinkla/translator.svg?style=flat)](https://packagist.org/packages/vinkla/translator)

## Install

Require this package in your `composer.json` and update composer.

```json
{
    "require": {
        "vinkla/translator": "~0.4"
    }
}
```

Add the service provider to `config/app.php` in the providers array.

```bash
'Vinkla\Translator\TranslatorServiceProvider'
```

To add the configuration files to the `app/config/packages` directory, run the command below.
```bash
php artisan publish:config vinkla/translator
```

## Usage

Below we have some example [migrations](#migrations) and [models](#models).

#### Migrations
Here's an example of the localisations migration.

```php
Schema::create('locales', function(Blueprint $table)
{
    $table->increments('id');
    $table->string('language', 2); // en, sv, da, no, etc.
    $table->timestamps();
});
```

Add the Laravel migration for the base table which you want to translate.

```php
Schema::create('articles', function(Blueprint $table)
{
    $table->increments('id');
    $table->string('thumbnail');
    $table->timestamps();
});
```

Add the Laravel migration for the translatable relation table.

```php
Schema::create('article_translations', function(Blueprint $table)
{
    $table->increments('id');

    // Translatable attributes
    $table->string('title');
    $table->string('content');
    // Translatable attributes

    $table->integer('article_id')->unsigned()->index();
    $table->foreign('article_id')->references('id')->on('articles')->onDelete('cascade');

    $table->integer('locale_id')->unsigned()->index();
    $table->foreign('locale_id')->references('id')->on('locales')->onDelete('cascade');

    $table->unique(['article_id', 'locale_id']);

    $table->timestamps();
});
```

#### Models

Here's an example of a translatable Laravel Eloquent model.

```php
<?php namespace Acme\Articles;

use Illuminate\Database\Eloquent\Model;
use Vinkla\Translator\TranslatorTrait;

class Article extends Model {

	use TranslatorTrait;

	/**
     * @var string
     */
    protected $translator = 'Acme\Articles\ArticleTranslation';

	/**
     * @var array
     */
    protected $translatedAttributes = ['title', 'content'];

}
```

### Fetching data

That's it! You're done. Now you can do:
```php
<h1>{{ $article->translate()->title }}</h1>
<img src="{{ $article->thumbnail }}">
<p>{{ $article->translate()->content }}</p>
```

Or if you added the `$translatedAttributes` array to your model (not required), you can do:
```php
<h1>{{ $article->title }}</h1>
<img src="{{ $article->thumbnail }}">
<p>{{ $article->content }}</p>
```

## Future Features

Below is a list of features that I would like to see in future releases. Please submit and [issue](https://github.com/vinkla/translator/issues) if you want to add anything, or better yet, create an [pull request](https://github.com/vinkla/translator/pulls)!

- Add create, update, delete functionality to the translator trait.
- Add bootstrap command to generate the localisations migration.
- Add generator command to scaffold new translations migrations.

## Contributing

Thank you for considering contributing to the Translator package. If you are submitting a bug-fix, or an enhancement that is **not** a breaking change, submit your pull request to the the latest stable release of the package, the `master` branch. If you are submitting a breaking change or an entirely new component, submit your pull request to the `develop` branch.

## License

The Translator package is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT).<commit_msg>Add a short overview of the strengths of this package.<commit_after>Laravel Translator
==================

![image](https://raw.githubusercontent.com/vinkla/vinkla.github.io/master/images/laravel-translator.png)

This package gives you an easy way to translate Eloquent models into multiple languages.

```php
// Fetch the Eloquent object.
$foo = Foo::first();

// Display the default title.
echo $foo->title;

// Change the current language to Swedish.
App::setLocale('sv');

// Display the translated title in Swedish.
echo $foo->title;
```

[![Build Status](https://img.shields.io/travis/vinkla/translator/master.svg?style=flat)](https://travis-ci.org/vinkla/translator)
	[![Latest Stable Version](http://img.shields.io/packagist/v/vinkla/translator.svg?style=flat)](https://packagist.org/packages/vinkla/translator)
	[![License](https://img.shields.io/packagist/l/vinkla/translator.svg?style=flat)](https://packagist.org/packages/vinkla/translator)

## Installation

The library requires at least **PHP version 5.4** and comes with a **Laravel Service Provider** to simplify the framework integration.

Require this package in your `composer.json` and update composer.

```json
{
	"require": {
		"vinkla/translator": "~0.4"
	}
}
```

Add the service provider to `config/app.php` in the providers array.

```bash
'Vinkla\Translator\TranslatorServiceProvider'
```

To add the configuration files to the `app/config/packages` directory, run the command below.
```bash
php artisan publish:config vinkla/translator
```

## Getting started

Below we have examples of [migrations](#migrations), [models](#models) and [templating](#templating).

#### Migrations
Here's an example of the localisations migration.

```php
Schema::create('locales', function(Blueprint $table)
{
	$table->increments('id');
	$table->string('language', 2); // en, sv, da, no, etc.
	$table->timestamps();
});
```

Add the Laravel migration for the base table which you want to translate.

```php
Schema::create('articles', function(Blueprint $table)
{
	$table->increments('id');
	$table->string('thumbnail');
	$table->timestamps();
});
```

Add the Laravel migration for the translatable relation table.

```php
Schema::create('article_translations', function(Blueprint $table)
{
	$table->increments('id');

	// Translatable attributes
	$table->string('title');
	$table->string('content');
	// Translatable attributes

	$table->integer('article_id')->unsigned()->index();
	$table->foreign('article_id')->references('id')->on('articles')->onDelete('cascade');

	$table->integer('locale_id')->unsigned()->index();
	$table->foreign('locale_id')->references('id')->on('locales')->onDelete('cascade');

	$table->unique(['article_id', 'locale_id']);

	$table->timestamps();
});
```

#### Models

Here's an example of a translatable Laravel Eloquent model.

```php
<?php namespace Acme\Articles;

use Illuminate\Database\Eloquent\Model;
use Vinkla\Translator\TranslatorTrait;

class Article extends Model {

	use TranslatorTrait;

	/**
	 * @var string
	 */
	protected $translator = 'Acme\Articles\ArticleTranslation';

	/**
	 * @var array
	 */
	protected $translatedAttributes = ['title', 'content'];

}
```

### Templating

That's it! You're done. Now you can do:
```php
<h1>{{ $article->translate()->title }}</h1>
<img src="{{ $article->thumbnail }}">
<p>{{ $article->translate()->content }}</p>
```

Or if you added the `$translatedAttributes` array to your model (not required), you can do:
```php
<h1>{{ $article->title }}</h1>
<img src="{{ $article->thumbnail }}">
<p>{{ $article->content }}</p>
```

## Contributing

Thank you for considering contributing to the Translator package. If you are submitting a bug-fix, or an enhancement that is **not** a breaking change, submit your pull request to the the latest stable release of the package, the `master` branch. If you are submitting a breaking change or an entirely new component, submit your pull request to the `develop` branch.

## License

The Translator package is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT).
{'fraction_non_alphanumeric': 0.1654380664652568, 'fraction_numerical': 0.001933534743202417, 'mean_word_length': 5.054133138258961, 'pattern_counts': {'":': 4, '<': 25, '<?xml version=': 0, '>': 91, 'https://': 14, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6282635', 'n_tokens_mistral': 2648, 'n_tokens_neox': 2499, 'n_words': 710}