Comments (36)
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.
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.
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.
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.
Add DB::table('your_table_name')->get(); code in your class before model::create($data)
from laravel-translatable.
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.
vmartins is experiencing exactly what I'm experiencing
from laravel-translatable.
Here is a test that describes this behavior.
Please compare your classes with the classes Country and CountryTranslation
from laravel-translatable.
You can use Laravel translation function (trans()) in http://laravel.com/docs/helpers
from laravel-translatable.
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.
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.
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:
- TranslatableTests::it_creates_translations_using_mass_assignment_and_locales
Failed asserting that null matches expected 'Belgique'.
from laravel-translatable.
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.
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.
Indeed, the migration table is there. My mistake.
from laravel-translatable.
The way I described, your test return OK?
from laravel-translatable.
Yep. Everything was green.
from laravel-translatable.
Ok, I will continue to investigating my code. Thanks.
from laravel-translatable.
I'm having the same issue, the translatable data doesn't get saved with the following structure:
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.
@nWidart do you use homestead for dev?
from laravel-translatable.
No, was using a Vagrant box (Vaprobash) for a while but back to Mamp now.
from laravel-translatable.
This seems like an environment issue. Are the tests running green?
from laravel-translatable.
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.
Of course on clean/independent install it needs database access...
So... wouldn't know how to run your test suite.
from laravel-translatable.
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.
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.
Ok now please write a test that reproduces the error and do a pull request.
from laravel-translatable.
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.
@nWidart common, give me some feedback. We have to close this before version 5 release.
from laravel-translatable.
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.
@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.
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.
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.
Thanks to @nWidart for the help!
from laravel-translatable.
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.
OH lordy @dimsav Gonna have to refactor my code now.
Thanks!
from laravel-translatable.
Related Issues (20)
- Add Laravel 5.8 support HOT 1
- Saving in translated model instead of saving in original model HOT 4
- Fetching Model by translated field and determine locale HOT 3
- Extra Fields or Properties For Translated Text HOT 2
- Can't translate to Portuguese HOT 3
- Display translated attribute even if no translation for current locale and fallback locale? HOT 3
- Has this package a possibility to get translations of related models HOT 2
- Ability to save in both languages HOT 8
- ID coming back with different data HOT 4
- Query where locale not working properly HOT 2
- What would be the best way to handle admin panel with translations? HOT 4
- how i can custom $translatedAttributes from outside model HOT 2
- Multiple Databases HOT 2
- Fallback to default locale with numeric field is not working as expected HOT 3
- get all and Fallback if translation is missing #23 HOT 2
- Wrong column name HOT 2
- Problem with relations HOT 3
- Prefix for default language HOT 6
- When I change local I don't get the translation HOT 7
- how to change the category translation on the fly? HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from laravel-translatable.