Skip to content
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

Is it possible to get "better" labels by default without using .properties files? #15

Open
skinkie opened this issue Jul 28, 2020 · 3 comments

Comments

@skinkie
Copy link

skinkie commented Jul 28, 2020

I have set up a properties file to map between:

quantity-unitCode=Unit Code

Is there any way that I could do for example programmatically instruct to render this in a better way than:

???quantity-unitCode???:
@beranradek
Copy link
Owner

Hi skinkie,

what is your solution/template engine to generate markup of your forms (or are you using FormRenderer class)?

In provided demo, you can see translation of form field names within:
https://github.com/beranradek/formio-demo/blob/master/src/main/resources/webapp/WEB-INF/jsp/simple.jsp#L5
https://github.com/beranradek/formio-demo/blob/master/src/main/resources/webapp/WEB-INF/tags/forms/input.tag#L74
https://github.com/beranradek/formio-demo/blob/master/src/main/resources/net/formio/demo/domain/Person.properties

But generally, you can make your custom solution for translations based on labelKey attribute of form fields.

As stated in http://www.formio.net/documentation/configuration/: Default message bundle name (also used by FormRenderer) is derived from the class of edited object. If com.example.Registration class is edited, com/example/Registration bundle (Registration.properties in package com.example) is searched. If translation in message bundle is not found, ??? is written to output. When using FormRenderer for automatic form rendering, FormRenderer.getMessageTranslator can be overriden to provide custom message translator that does not use properties files.

@skinkie
Copy link
Author

skinkie commented Aug 29, 2020

what is your solution/template engine to generate markup of your forms (or are you using FormRenderer class)?

I am using the FormRenderer class.

But generally, you can make your custom solution for translations based on labelKey attribute of form fields.

Maybe I don't understand something. What I would expect is that the attribute names would be extracted from the classes, at least to give a sane default. Maybe camelCases rewriten to "Camel Cases" label. As developer I don't want to do this manually for an XSD schema.

@beranradek
Copy link
Owner

You can see example of FormRenderer usage in https://github.com/beranradek/formio-demo/blob/master/src/main/java/net/formio/demo/forms/CarForm.java. Translation properties associated with Car object are: https://github.com/beranradek/formio-demo/blob/master/src/main/resources/net/formio/demo/domain/car/Car.properties (file corresponding to class name is taken by default, letter case is important, I assume).

As I stated above, method FormRenderer.getMessageTranslator (or probably FormRenderer.renderMarkupFieldLabel) can be overriden (see the implementation of renderMarkupFieldLabel) if default usage of .properties file does not suit for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants