Comments (14)
Thank you for your quick answer. Thats exactly what I was searching for.
Btw thanks for this great package!
from nova-page.
Hi @chrissfr,
It depends on which package you use for translating the fields. If the package claims to store translations in a json column, then it will simply work as expected with our package, because translated field values are stored in the same json file.
We have several websites running with this package & using translated fields and have not encountered any issues yet.
Which translated fields package do you use?
from nova-page.
To add onto the previous answer, we felt it was a bad decision to force a particular way to handle translated data, so we removed it and if you need it, you can choose how to make it work yourself. We aim to be as little opinionated as possible.
If you're curious about how we do it, we use spatie/laravel-translatable on both our models and our Nova Page templates to define which fields contain translated data.
Then, we use mrmonat/nova-translatable to make that translatable data editable in Nova. Note that Spatie themselves have made a similar package, but we found mrmonat's UI was better for our needs.
Also I am closing this since it is not an issue and rather a question.
from nova-page.
thanks that worked like a charm
from nova-page.
To add onto the previous answer, we felt it was a bad decision to force a particular way to handle translated data, so we removed it and if you need it, you can choose how to make it work yourself. We aim to be as little opinionated as possible.
If you're curious about how we do it, we use spatie/laravel-translatable on both our models and our Nova Page templates to define which fields contain translated data.
Then, we use mrmonat/nova-translatable to make that translatable data editable in Nova. Note that Spatie themselves have made a similar package, but we found mrmonat's UI was better for our needs.
Also I am closing this since it is not an issue and rather a question.
spatie/nova-translatable required the HasTranslations trait to be added to the model behind the nova resource (in that case the Template), so at the saving of the template we got a Method App\Nova\Templates\Home::setTranslation does not exist. error.
How do you handled the spatie's package here on nova page?
from nova-page.
The setTranslation
method is a part of the HasTranslations
trait from the spatie/laravel-translatable which should indeed be applied on the template class. If it complains that the method does not exist, either you did not apply the trait on your template, or there is a problem with the trait itself.
from nova-page.
HasTranslations must be applied to the Model referenced by a Nova Resource so where is that Model? No way to place a fake setTranslations method, the request doesn't get the values submitted with the form
from nova-page.
<?php
namespace App\Nova\Templates;
class Home extends Template {
use HasTranslations;
// ...
}
No need for a fake setTranslations
method, it's part of the HasTranslations
trait.
from nova-page.
No man
HasTranslations seguire an eloquent model instance
from nova-page.
There is no eloquent model. There is a template class instead. I have used the HasTranslation trait exactly the way I showed you before and it works fine.
from nova-page.
Please provide a full example with fields and db. If I use HasTranslations don't work
from nova-page.
I don't know what magic you are doing, but I just updated spatie/nova-translatable to the latest version 4.2.1, and as soon as I open the page editing page I get this error:
Argument 2 passed to Spatie\NovaTranslatable\Translatable::Spatie\NovaTranslatable\{closure}() must be an instance of Illuminate\Database\Eloquent\Model, instance of App\Nova\Templates\Home given
This is my Template class, and don't work.
<?php
namespace App\Nova\Templates;
use Illuminate\Http\Request;
use Laravel\Nova\Fields\Text;
use Spatie\NovaTranslatable\Translatable;
use Spatie\Translatable\HasTranslations;
use Whitecube\NovaPage\Pages\Template;
class Home extends Template
{
use HasTranslations;
/**
* Get the fields displayed by the resource.
*
* @param Request $request
* @return array
*/
public function fields(Request $request)
{
return [
Translatable::make([
Text::make('Foobar'),
]),
];
}
/**
* Get the cards available for the request.
*
* @param Request $request
* @return array
*/
public function cards(Request $request)
{
return [];
}
}
from nova-page.
To add onto the previous answer, we felt it was a bad decision to force a particular way to handle translated data, so we removed it and if you need it, you can choose how to make it work yourself. We aim to be as little opinionated as possible.
If you're curious about how we do it, we use spatie/laravel-translatable on both our models and our Nova Page templates to define which fields contain translated data.
Then, we use mrmonat/nova-translatable to make that translatable data editable in Nova. Note that Spatie themselves have made a similar package, but we found mrmonat's UI was better for our needs.
Also I am closing this since it is not an issue and rather a question.
Do you stil get this to work? cause i am not. what are you doing different?
from nova-page.
That's what I did.
/**
* Get the fields displayed by the resource.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function fields(Request $request)
{
$locales = LaravelLocalization::getLocalesOrder();
$fields = [];
foreach ($locales as $localeCode => $properties) {
$fields[] = Text::make("Text", "text_{$localeCode}");
}
return $fields;
}
from nova-page.
Related Issues (20)
- Class "Route" not found
- Class "App" Not Found
- Method App\\Nova\\Templates\\Formations::forceFill does not exist HOT 4
- Title will not save in templates HOT 5
- Argument 1 passed to StaticResource HOT 3
- Deleting Images in Flexible Content Field HOT 1
- PHP 8 error "Required parameter $closure follows optional parameter $date" HOT 2
- Page Resource Search does not work
- FR: Hide options from sidebar HOT 2
- Ability to hide nova-option HOT 1
- Detail view broken HOT 7
- Cast Date Field HOT 3
- PHP 8 Compatibility? -- Required parameter follows optional parameter HOT 2
- Remove template declaration in routes HOT 3
- Arabic encoding
- Nova 4 Support HOT 6
- TypeError: Cannot read properties of undefined (reading 'resource') HOT 3
- Error deleting a file HOT 1
- Call to undefined method Whitecube\NovaPage\Pages\Query::exists() HOT 3
- Can this be used for multiple page layouts? HOT 3
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 nova-page.