Code Monkey home page Code Monkey logo

Comments (5)

nexana avatar nexana commented on May 31, 2024

I am asking this because I have an entity "Page", for which I want translations in 3 different locales.
When I create a new Page in the database, I would expect that for each locale set in the config, a PageTranslation record is also created.

Current setup:

In my app config I have set the locales:
'locales' => array('nl','en','fr'),
'locale' => 'nl',

class Page extends Eloquent
{
use Dimsav\Translatable\Translatable;

public $translatedAttributes = array('title','content');
protected  $table = 'pages';
protected $fillable = array('name','order','showinmenu');
}


class PageTranslation extends Eloquent implements SluggableInterface
{
protected  $table = 'page_translations';
protected $fillable = array('title', 'description','order','locale');
}

And In my pagecontroller I create a new page:
class PageController extends \BaseController {
public function store()
{
$page = new Page();
$page->name = Input::get('name');
$page->showinmenu = Input::has('showinmenu');
$page->save();
}
}

from laravel-translatable.

jonasva avatar jonasva commented on May 31, 2024

It only adds a record in your model's translations table for the current locale. Why would you want it to add empty records for the other locales?

from laravel-translatable.

nexana avatar nexana commented on May 31, 2024

Thank you very much for your answer. Now I know this is default behaviour.

To answer yours:
The application I am making let's the admin user add pages to the front-end.
When he adds a new page in the backend, he is then taken to a form where he can enter the translated content for each locale available (ie a textfield for english, french, dutch,...content). So this is independent of his default locale.

It would be handy if the empty records for each locale were already available right after the user created the page.

from laravel-translatable.

jonasva avatar jonasva commented on May 31, 2024

You can still do that by using the translate() method mentioned in the documentation. Like this:

$country->translate('en')->name = 'abc';
$country->save();

In the form the user is taken to after creating a page you could then make specific fields and save them per locale.

For example:
in your view you could put fields like this:

 {{ Form::label('content_en', 'English Content') }} 
 {{ Form::text('content_en',null,array('class' => 'form-control', 'required' => 'required')) }}

Then in your controller you translate the correct field:

 $country->translate('en')->content = Input::get('content_en');
 $country->save();

from laravel-translatable.

dimsav avatar dimsav commented on May 31, 2024

Hey @nexana,

you don't need empty db records to show empty input forms. Laravel-translatable only adds db records for translations that are defined.

Cheers

from laravel-translatable.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.