Comments (8)
👎 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.
@xificurk control labels, select values and even validation rules are beeing passed to translator. It's just done inconsistently.
from forms.
@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.
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.
@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.
👎 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.
@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.
Not relevant anymore.
from forms.
Related Issues (20)
- SubmitButton without caption throws depracated error on render on PHP 8.1
- UploadControl MaxLenght message %i HOT 1
- private const Array (request to change to public)
- Validation problem with rule MIME_TYPE
- Unable to add class to input programatically when rendered using n:name
- netteForms.js doesn't toggle properly when form is reset
- Cannot call method startTag() / endTag() on string
- addDate(), addTime(), addDateTime() - how to get nullable values?
- netteForms: min/max wrong validation of numbers HOT 1
- setValue() as well as setDefaultValue() don't set the value and the field shows error states instead HOT 2
- ChoiceControl::getRawValue(): Return value must be of type string|int, null returned HOT 1
- Validation of MimeType rule fails when FileControl->getContentType returns null HOT 1
- src/assets/netteForms.js broken in 3.2-dev HOT 1
- `Nette\Forms\Blueprint::dataClass($form)`: Undefined variable `$bp` HOT 1
- Number inputs format shouldn't be always validated HOT 7
- Number input with maxlength validation always fails HOT 2
- Compound condition does not toggle element
- Error in JS validation for rule Form::Image
- Implementation of setOmitted() to Nette\Forms\Rules
- errors cummulate when instances of Nette\HtmlStringable
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 forms.