-
-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom field name in validations (i18n) #136
Comments
@saracalihan, I would like to hear your opinions about this template. Does it look good enough? |
It sounds like a very useful feature, but I have some questions.
Apart from these questions, it is enough for me for custom localization. |
@saracalihan, thank you very much for your feedback. 🤗
In Axe API, we use validatorjs library. The reason we use
I think the YAML is very clear than JSON. But of course, we can use JSON. That's totally fine.
As a developer, you need more fields than one field if you want to support multiple languages at the same time, in reality. Also, developers are not able to manage the validating process. Let's look at the following example; class Users extends Model {
get validations(): Record<string, string> {
return {
email: "required|email",
name: "required|max:50",
surname: "required|max:50",
age: "max:100",
};
}
} This is the only thing a developer should do to validate data. As you can notice, there is no way to define fields name in different languages. Also, a developer might want to throw some special error messages to the users. For example; Does it make sense to you? |
@ozziest You are right about JSON, It becomes difficult to write when dealing with square brackets, quotes. i get to point, now this flex and usage is okay to me. |
I decided to use However, we have a problem with the validation library. It sets the language as a global value. Which doesn't allow to clients use different languages at the same time. Check this out We can't import this feature without replacing the validation library. |
This feature won't be implemented. Because the current validation library has several issues. (1, 2). Instead of that, robust-validator library support has been added. And it doesn't need fields names because it allows to handle field name in the frontend side. So I close this issue. |
Developers should be able to add custom field names to the validation messages.
Motivation
Currently, developers are able to add multiple languages to the API. It works like the following example in form validations;
As you can see, all validations messages are in German except the
field
name. Developers should be able to manage this field name for form validations.Definitions
All translations should be defined the under the
locales
folders by the language code.For example,
locales/en/fields.yaml
These values should be used by the form validation library like the following example;
Custom Translations
Developers should be able to use custom translations.
fields.yaml
file will be used by the Axe API. But the other files should be able to use the following example;The text was updated successfully, but these errors were encountered: