# How to use Language Translation?

**URL:** <https://discourse.cakephp.org/t/how-to-use-language-translation/2772>\
**Category:** Need Help\
**Created:** [June 24, 2017, 11:04am UTC](https://discourse.cakephp.org/t/how-to-use-language-translation/2772 "2017-06-24T11:04:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![pankajd](https://avatars.discourse-cdn.com/v4/letter/p/c2a13f/32.png) [@pankajd](https://discourse.cakephp.org/u/pankajd)\
**Post date:** [June 24, 2017, 11:04am UTC](https://discourse.cakephp.org/t/how-to-use-language-translation/2772/1 "2017-06-24T11:04:44Z")

</div>

currently I am studying cake php .  
i am doing language translation tutorial.  
so I want to load translation from database.  
I am doing following steps

1. created table  
i18n  
2)created entity

\<?php use Cake\ORM\Behavior\Translate\TranslateTrait; use Cake\ORM\Entity; class Category extends Entity { use TranslateTrait; } ?\>

3)created table

\<?php namespace App\Model\Table; use Cake\ORM\Table; use Cake\ORM\Behavior\Translate\TranslateTrait; class Category extends Table { public $useTable = 'Category'; public function initialize(array $config) { $this-\>addBehavior('Translate', ['fields' =\> ['name']]); } } ?\>
1. printed translation value in controller

I18n::locale(‘es’);  
$this-\>loadModel(‘Category’);  
echo $this-\>Category-\>translation(‘es’)-\>name;

1. but when executed this,following error comes.

Unknown method “translation”

---

<div class="post-metadata">

**Author:** ![Graziel](https://avatars.discourse-cdn.com/v4/letter/g/71c47a/32.png) [@Graziel](https://discourse.cakephp.org/u/Graziel)\
**Post date:** [June 25, 2017, 4:31am UTC](https://discourse.cakephp.org/t/how-to-use-language-translation/2772/2 "2017-06-25T04:31:22Z")

</div>

`->translations` is method in entity, and you are trying to use is on `Table` object, you need to get any record before you can translate it ie

```php
//in controller:
$category = $this->Category->get($id);
$this->set(compact($category));
//and in view:
echo $category->translation('es')->name;

```
