Closed johnef closed 5 years ago
Could you please provide any more details? Code, Query, Settings and so on. Otherwise I can't help.
Yes of course Here is my model for product category
class ProductCategory extends Model {
use Translatable;
public $translatedAttributes = [ 'name' ];
protected $fillable = [ 'image', 'name', 'soft_delete' ];
public function categoryProduct() {
return $this->hasMany( Product::class, 'product_category_id' );
}
}
and here is the product category translations model
class ProductCategoryTranslation extends Model {
public $timestamps = false;
protected $fillable = [ 'name', 'product_category_id' ];
}
Now in controller
$productCategories = ProductCategory::all(); // local is English I get Arabic
Here is my translatable config
'locales' => [
'ar',
'en',
/*'es' => [
'MX', // mexican spanish
'CO', // colombian spanish
],*/
],
'locale_separator' => '-',
'locale' => null,
'use_fallback' => true,
'use_property_fallback' => true,
'fallback_locale' => false,
'translation_suffix' => 'Translation',
'locale_key' => 'locale',
'to_array_always_loads_translations' => true,
@Gummibeer please if you'd like me to provide anything else let me know
At all this seems all valid. Which part of the response is wrong/arabic? The attributes or do you have arabic listed in the translations
relation?
@Gummibeer when I change my local to English everything return English as static translations but the translations coming from the Database not getting the English translation.
Even I try something like this with
->whereHas( 'translations', function ( $query ) {
$query->where( 'locale', 'en' );
} )->first()
public function menu() {
$categories = ( new ProductCategory )
->where( 'soft_delete', 0 )
->whereHas( 'translations', function ( $query ) {
$query->where( 'locale', 'en' );
} )->first()
->with( 'categoryProduct' )
->whereHas( 'categoryProduct', function ( $query ) {
$query/*->where( 'quantity', '>', 0 )*/
->where( 'product_category_id', '!=', null )
->where( 'soft_delete', 0 );
} )
->withCount( 'categoryProduct' )
->orderBy( 'sort_categories', 'ASC' )
->orderBy( 'category_product_count', 'desc' )
->get();
return $categories;
}
This will return Arabic data
@Gummibeer My php version 7.1.9
As announced here, the project has been deprecated. Please use astrotomic/laravel-translatable.
I used this package with L5.4 and package version 7. everything was working fine. when I upgraded to Laravel 5.8 and package version 9. no I don't see the translation when I debug the local I get 'en' but the translation coming is 'ar'.