Git Product home page Git Product logo

Comments (36)

dimsav avatar dimsav commented on July 26, 2024 3

Ok guys we got the answer. PLEASE follow the installation instructions and define your "locales" in the configuration. Otherwise translatable is not able to determine if the fill keys are locales or not.

from laravel-translatable.

dimsav avatar dimsav commented on July 26, 2024

Can you please explain "does not work properly"? For instance do you get an exception or an error?

Edit: If you have this issue, make sure you have defined your project's locales, as described in the installation instructions.

from laravel-translatable.

wisepotato avatar wisepotato commented on July 26, 2024

it just does not work, no exception or error. It doesnt set the properties

I wish I could be more descriptive, Is the implementation as said in the README still valid?

(love the package btw :) )

from laravel-translatable.

dimsav avatar dimsav commented on July 26, 2024

I wish I could be more descriptive, Is the implementation as said in the README still valid?

Well, no one complained so far. Please copy paste your classes below. Also check the test classes (every feature is well tested).

I am glad you like the package :)

from laravel-translatable.

ilksan avatar ilksan commented on July 26, 2024

Add DB::table('your_table_name')->get(); code in your class before model::create($data)

from laravel-translatable.

vmartins avatar vmartins commented on July 26, 2024

Hi, I have a problem with filling multiple translations, using Foo::create().

This don't work (table foo is filled, but foo_translations is not filled):

Foo::create(array(
    'en' => array('name' => 'en Bar'),
    'pt' => array('name' => 'pt Bar')
));

This work:

$foo = new Foo;
$foo->translate('en')->name = 'en Bar';
$foo->save();

(dimsav/laravel-translatable v4.3.1)

from laravel-translatable.

wisepotato avatar wisepotato commented on July 26, 2024

vmartins is experiencing exactly what I'm experiencing

from laravel-translatable.

dimsav avatar dimsav commented on July 26, 2024

Here is a test that describes this behavior.

Please compare your classes with the classes Country and CountryTranslation

from laravel-translatable.

ilksan avatar ilksan commented on July 26, 2024

You can use Laravel translation function (trans()) in http://laravel.com/docs/helpers

from laravel-translatable.

vmartins avatar vmartins commented on July 26, 2024

When I run the test TranslatableTest.php, I get the result: OK (18 tests, 37 assertions), but if I change the database connection from sqlite to mysql driver, I get the error:

There was 1 failure:

1) TranslatableTests::it_creates_translations_using_mass_assignment_and_locales
Failed asserting that null matches expected 'Belgique'.

FAILURES!
Tests: 18, Assertions: 37, Failures: 1.
///vendor/dimsav/laravel-translatable/tests/TestsBase.php

    protected function getEnvironmentSetUp($app)
    {
        $app['path.base'] = __DIR__ . '/../Translatable';

        $app['config']->set('database.default', 'testbench');
//        $app['config']->set('database.connections.testbench', array(
//            'driver'   => 'sqlite',
//            'database' => ':memory:',
//            'prefix'   => '',
//        ));
//        DB::statement('PRAGMA foreign_keys = ON');
        $app['config']->set('database.connections.testbench', array(
            'driver'    => 'mysql',
            'host'      => 'localhost',
            'database'  => 'foo',
            'username'  => 'foo',
            'password'  => '',
            'charset'   => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix'    => '',
        ));

        $app['config']->set('app.locale', 'en');
        $app['config']->set('app.locales', array('el', 'en', 'fr', 'de', 'id'));
        $app['config']->set('app.fallback_locale', 'de');
    }

from laravel-translatable.

dimsav avatar dimsav commented on July 26, 2024

Hi @vmartins

I updated the tests to use mysql as database driver and I still don't get that error.

Locally, I run the tests using laravel homestead. (you have to manually create a database called "translatable_test") Please run the tests with homestead and let me know what happens.

from laravel-translatable.

vmartins avatar vmartins commented on July 26, 2024

Now the test its OK, but something unexpected occurred.
If I clear database, comment the code and run the test:

    private function resetDatabase($artisan)
    {
//        // This creates the "migrations" table if not existing
//        $artisan->call('migrate', [
//            '--database' => 'mysql',
//            '--path'     => '../tests/migrations',
//        ]);
//        // We empty the tables
//        $artisan->call('migrate:reset', [
//            '--database' => 'mysql',
//        ]);
        // We fill the tables
        $artisan->call('migrate', [
            '--database' => 'mysql',
            '--path'     => '../tests/migrations',
        ]);
    }

There was 1 failure:

  1. TranslatableTests::it_creates_translations_using_mass_assignment_and_locales
    Failed asserting that null matches expected 'Belgique'.

from laravel-translatable.

dimsav avatar dimsav commented on July 26, 2024

If you empty the database the migrations fail to run because the migrations table is not set.

Closing this issue since there is nothing wrong with the package. Please debug your code.

from laravel-translatable.

vmartins avatar vmartins commented on July 26, 2024

But the migration table its created with:

        $artisan->call('migrate', [
            '--database' => 'mysql',
            '--path'     => '../tests/migrations',
        ]);

(I clear database before run the test)

from laravel-translatable.

dimsav avatar dimsav commented on July 26, 2024

Indeed, the migration table is there. My mistake.

from laravel-translatable.

vmartins avatar vmartins commented on July 26, 2024

The way I described, your test return OK?

from laravel-translatable.

dimsav avatar dimsav commented on July 26, 2024

Yep. Everything was green.

from laravel-translatable.

vmartins avatar vmartins commented on July 26, 2024

Ok, I will continue to investigating my code. Thanks.

from laravel-translatable.

nWidart avatar nWidart commented on July 26, 2024

I'm having the same issue, the translatable data doesn't get saved with the following structure:
screen shot 2014-11-08 at 10 24 41 am

The models have the exact same structure as the Country and CountryTranslation models.

Even with some static data:

$data = [
            'name' => 'testStatic',
            'en'  => ['title' => 'english'],
            'fr'  => ['title' => 'french'],
        ];
        Menu::create($data);

No MenuTranslations get created.

from laravel-translatable.

dimsav avatar dimsav commented on July 26, 2024

@nWidart do you use homestead for dev?

from laravel-translatable.

nWidart avatar nWidart commented on July 26, 2024

No, was using a Vagrant box (Vaprobash) for a while but back to Mamp now.

from laravel-translatable.

dimsav avatar dimsav commented on July 26, 2024

This seems like an environment issue. Are the tests running green?

from laravel-translatable.

nWidart avatar nWidart commented on July 26, 2024

Hm, I would have to install it separately. Running phpunit in the current environment causes a Cannot open file "/Users/nicolaswidart/Sites/Module-Development/vendor/dimsav/laravel-translatable/vendor/autoload.php"..

Will try tonight, I don't remember seeing anything not passing though.

from laravel-translatable.

nWidart avatar nWidart commented on July 26, 2024

Of course on clean/independent install it needs database access...
So... wouldn't know how to run your test suite.

from laravel-translatable.

dimsav avatar dimsav commented on July 26, 2024

Just create an empty database. Here is the config: https://github.com/dimsav/laravel-translatable/blob/master/tests/TestsBase.php#L30-L38

from laravel-translatable.

nWidart avatar nWidart commented on July 26, 2024

Alright, had to change to user/password too, to make it work on a non homestead environment.

Everything green.

OK (31 tests, 58 assertions)

from laravel-translatable.

dimsav avatar dimsav commented on July 26, 2024

Ok now please write a test that reproduces the error and do a pull request.

from laravel-translatable.

jonathanpmartins avatar jonathanpmartins commented on July 26, 2024

I'm using Ubuntu, Nginx, Php 5.5.12, Laravel 5 Dev, and translatable last dev branch! And all is working how it should be.

from laravel-translatable.

dimsav avatar dimsav commented on July 26, 2024

@nWidart common, give me some feedback. We have to close this before version 5 release.

from laravel-translatable.

nWidart avatar nWidart commented on July 26, 2024

I just copied on a random route to contents of the it_creates_translations_using_mass_assignment_and_locales test, and it only added the English translation.

$data = [
        'en' => ['name' => 'English Category'],
        'fr' => ['name' => 'French Category']
    ];
    \Modules\Blog\Entities\Category::create($data);

My Category model has the same setup as the Country model for the test. So I wouldn't know why the test returns green, but it isn't actually working.

from laravel-translatable.

dimsav avatar dimsav commented on July 26, 2024

@nWidart it sounds like an environment issue.

Did you run the tests under the same environment as your app? If yes, then copy your Category class in the translatable repo and try to reproduce the error by writing a test.

from laravel-translatable.

nWidart avatar nWidart commented on July 26, 2024

I tried to copy over the category & categoryTranslation model with their migrations.
But as soon as I add the migrations, all tests fail.

Added this to the up() method

Schema::create('categories', function (Blueprint $table) {
            $table->increments('id');
            $table->timestamps();
        });

        Schema::create('category_translations', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name');
            $table->string('slug');
            $table->integer('category_id')->unsigned();
            $table->string('locale')->index();
            $table->unique(['category_id','locale']);
            $table->foreign('category_id')->references('id')->on('categories')->onDelete('cascade');
        });

And down:

 Schema::dropIfExists('categories');
Schema::dropIfExists('category_translations');

Since apparently I'm the only one with the issue I don't want to make you waste time on this. I'm saving the properties the manual way for now. It isn't as pretty, but it works.

from laravel-translatable.

dimsav avatar dimsav commented on July 26, 2024

Change the order of the down drops. First delete the translations table, after the categories.
If it still throws error, manually drop all the tables and try again the tests.

from laravel-translatable.

dimsav avatar dimsav commented on July 26, 2024

Thanks to @nWidart for the help!

from laravel-translatable.

nWidart avatar nWidart commented on July 26, 2024

Thank you for the support and making me feel like a fool!! 👍
Looks like that optional forth step is important after all. 😄

from laravel-translatable.

wisepotato avatar wisepotato commented on July 26, 2024

OH lordy @dimsav Gonna have to refactor my code now.

Thanks!

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.