Reputation: 5611
I have this select:
<select class="form-control" th:field="*{objId}" name="objId" >
<option th:each="obj : ${objList}"
th:value="${obj.getId()}"
th:selected="${objList.contains(obj)}"
th:text="${obj.getDescription()}">
</option>
</select>
The description for the default object obj is 'Object not valid'.
Is it possible to internationalize its value? So when the object appears on this list it reads for instance, in Portuguese, "Objeto"?
Upvotes: 0
Views: 412
Reputation: 3825
to use internationalization you should use separate message file for each language you support and display description as follows:
th:text="#{${obj.getDescription()}}">
but in this case obj.getDescription()
should return message key as its value (for example object.description.message
), and this key has to be present in messages_pt.properties
file like for example:
object.description.message="Objecto"
Maybe I didn't understand you correctly, and you want only display different value when description is null. In this case the code below should resolve problem:
th:text="${obj.getDescription()}?: 'Description is null...'"
or
th:text="${obj.getDescription()}?: #{message.property.key.here}"
HTH
Upvotes: 1