GithubHelp home page GithubHelp logo

Errors are not translated about forms HOT 8 CLOSED

nette avatar nette commented on July 23, 2024
Errors are not translated

from forms.

Comments (8)

xificurk avatar xificurk commented on July 23, 2024

👎 Well, YOU are adding the error, it's your resposibility to translate it. Same way as is your responsibility to translate e.g. flash messages.

from forms.

fprochazka avatar fprochazka commented on July 23, 2024

@xificurk control labels, select values and even validation rules are beeing passed to translator. It's just done inconsistently.

from forms.

xificurk avatar xificurk commented on July 23, 2024

@fprochazka Let's stay with errors... The problem is that you need to translate the error message before you replace placeholders in the message for their values. This must be obviously done when you're adding the error to the control. But when it's you who is "constructing" the error message, then it's your responsibility to translate it. Translating the error messages in getErrors() is simply too late.

from forms.

fprochazka avatar fprochazka commented on July 23, 2024

You're absolutely right, that's why the current translation interface is not sufficient and should accept parameters argument, just like Kdyby does.

  • translation interface must be fixed (ideally in backwards compatible way)
  • Nette translators must adopt the new interface, ideall would the one from Kdyby, because it's backwards compatible and knows all the required functionality
  • dummy translator that replaces placeholders can be added to nette
  • then the parameters can be added to messages and passed to translator when the message is beeing translated

from forms.

TomasVotruba avatar TomasVotruba commented on July 23, 2024

@xificurk My only intent is to make it consistent with labels, items values and rule messages, as @fprochazka said.

As for "replace placeholders" issue, the same would apply for placeholders in rule messages.
How do you solve them now?

The same approach can be used, couldn't be?
How would this change break your approach?

I don't want to refactor translating in Nette. For now, I wan't to only make this consistent.

from forms.

dg avatar dg commented on July 23, 2024

👎 for ITranslator with parameters. Expanding placeholders is not translator's job. And ITranslator has nothing to do with this issue.

I am not sure if it is good idea to have API, where setAbc($x) sets $x and getAbc() returns translated $x…

from forms.

fprochazka avatar fprochazka commented on July 23, 2024

@dg there are two types of parameters in the form (errors) context. The ones' from the rule and control, that is %label, %value, %arg, ... And the second group is parameters for the message from the application perspective...

Case 1

$control->addError("front.registration.email")

where the it translates to

front:
    registration:
        email: "Your email %value is not valid"

the translator returns "Your email %value is not valid" and forms replaces the %value to what the user provided

Case 2

I've done some operations with some values in form so I wanna show the relevant value.

front:
    addressForm:
       invalidAddress: "Na zadanou adresu %address% bohužel nerozvážíme"
$control->addError($translator->translate('"front.addressForm.invalidAddress"', NULL, ['address' => $address]));
// or ? 
$control->addError("front.addressForm.address", ['address' => $address]);

I would understand if you won't accept this for ->addError(), but something like this makes a lot of sense for ->addRule()


I'm partially solving it by using Phrase objects, but there are parts, that strictly expect strings only and it doesn't work in all the parts of Form. Would you be willing to accept pullrequest that solves this example?

from forms.

TomasVotruba avatar TomasVotruba commented on July 23, 2024

Not relevant anymore.

from forms.

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.