Giter Club home page Giter Club logo

Comments (2)

ivanvermeyen avatar ivanvermeyen commented on May 29, 2024 1

Hello,

I had to refresh my memory for a second, but there is a problem when using nested attribute syntax like post.slug.
You can also use this syntax to submit multiple translations, like slug.en.
So in your case that would becomepost.slug.en, etc.

I have to detect the locale in the validation rule. The way I do this by getting any string after a dot.
Because a locale can be anything, there is no way to distinguish it from a field name.
If you just submit a slug attribute, then there is no dot in the attribute name and the app's locale is used.

protected function getAttributeLocale($attribute, $delimiter)
{
$pos = strrpos($attribute, $delimiter);
return $pos > 0 ? substr($attribute, $pos + 1) : null;
}

I don't know if there is any other way to handle this that supports nested arrays...

Edit:

One workaround that should work is be to add the locale to the form field: name="post[slug][en]"
Then validate post.slug.*

from laravel-unique-translation.

benjaminhaeberli avatar benjaminhaeberli commented on May 29, 2024 1

Hello @ivanvermeyen,

Your explanation is very clear, I understood the problem and if I use post.slug.* it works fine! It's an architecture issue on my side: currently, my requests validate the slug for the current language of the user with app()->getLocale(). However, there will be only one form per resource in the back-office, so I actually have to support the validation of several slugs at the same time (the entities are shared between the different languages, only some fields like the title and the slug are translatable).

Thanks for your help, I'll do the corrections on my side 👍 By the way I'll also implement your laravel-localized-routes package for the front-office, it looks great 😎

from laravel-unique-translation.

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.