Adding translations | laravel-tags | Spatie

 SPATIE

  Laravel Tags
===============

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-tags](https://spatie.be/docs/laravel-tags/v4)  Advanced-usage  Adding translations

 Version   v4   v3

 Other versions for crawler [v4](https://spatie.be/docs/laravel-tags/v4) [v3](https://spatie.be/docs/laravel-tags/v3)

- [ Introduction ](https://spatie.be/docs/laravel-tags/v4/introduction)
- [ Postcardware ](https://spatie.be/docs/laravel-tags/v4/postcardware)
- [ Requirements ](https://spatie.be/docs/laravel-tags/v4/requirements)
- [ Installation and Setup ](https://spatie.be/docs/laravel-tags/v4/installation-and-setup)
- [ Questions and issues ](https://spatie.be/docs/laravel-tags/v4/questions-and-issues)
- [ Changelog ](https://spatie.be/docs/laravel-tags/v4/changelog)
- [ About us ](https://spatie.be/docs/laravel-tags/v4/about-us)

Basic usage
-----------

- [ Using tags ](https://spatie.be/docs/laravel-tags/v4/basic-usage/using-tags)
- [ Retrieving tagged models ](https://spatie.be/docs/laravel-tags/v4/basic-usage/retrieving-tagged-models)

Advanced usage
--------------

- [ Adding translations ](https://spatie.be/docs/laravel-tags/v4/advanced-usage/adding-translations)
- [ Using types ](https://spatie.be/docs/laravel-tags/v4/advanced-usage/using-types)
- [ Sorting tags ](https://spatie.be/docs/laravel-tags/v4/advanced-usage/sorting-tags)
- [ Using your own tag model ](https://spatie.be/docs/laravel-tags/v4/advanced-usage/using-your-own-tag-model)
- [ Using another default locale ](https://spatie.be/docs/laravel-tags/v4/advanced-usage/using-another-default-locale)

 Adding translations
===================

When using the package like described in the basic usage section all tags will be stored in the locale your app is running. If you're creating a multilingual app it's really easy to translate the tags. Here's a quick example.

```
$tag = Tag::findOrCreate('my tag'); //store in the current locale of your app

//let's add some translation for other languages
$tag->setTranslation('name', 'fr', 'mon tag');
$tag->setTranslation('name', 'nl', 'mijn tag');

//don't forget to save the model
$tag->save();

$tag->getTranslation('name', 'fr'); // returns 'mon tag'

$tag->name // returns the name of the tag in current locale of your app.
```

The translations of the tags are stored in the `name` column of the `tags` table. It's a `json` column. To find a tag with a specific translation you can just use Laravel's query builder which has support for `json` columns.

```
 \Spatie\Tags\Tag::query()
   ->where('name->fr', 'mon tag')
   ->first();
```

Behind the scenes [spatie/laravel-translatable](https://github.com/spatie/laravel-translatable) is used. You can use any method provided by that package.
