GithubHelp home page GithubHelp logo

Localization about nova-page HOT 14 CLOSED

whitecube avatar whitecube commented on May 28, 2024
Localization

from nova-page.

Comments (14)

krizzdev avatar krizzdev commented on May 28, 2024 2

Thank you for your quick answer. Thats exactly what I was searching for.
Btw thanks for this great package!

from nova-page.

toonvandenbos avatar toonvandenbos commented on May 28, 2024 1

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.

voidgraphics avatar voidgraphics commented on May 28, 2024 1

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.

gldrenthe89 avatar gldrenthe89 commented on May 28, 2024 1

thanks that worked like a charm

from nova-page.

f-liva avatar f-liva commented on May 28, 2024

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.

voidgraphics avatar voidgraphics commented on May 28, 2024

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.

f-liva avatar f-liva commented on May 28, 2024

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.

voidgraphics avatar voidgraphics commented on May 28, 2024
<?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.

f-liva avatar f-liva commented on May 28, 2024

No man

HasTranslations seguire an eloquent model instance

from nova-page.

voidgraphics avatar voidgraphics commented on May 28, 2024

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.

f-liva avatar f-liva commented on May 28, 2024

Please provide a full example with fields and db. If I use HasTranslations don't work

from nova-page.

f-liva avatar f-liva commented on May 28, 2024

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.

gldrenthe89 avatar gldrenthe89 commented on May 28, 2024

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.

f-liva avatar f-liva commented on May 28, 2024

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)

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.