Reputation: 4289
Currently I am writing some text to pdf. based on the user locale, the language must be changed(ex: spanish, chineese, german).
Is there any API for this conversion? and Better approach?
Upvotes: 2
Views: 4539
Reputation: 15145
You can use ResourceBundles. You can find many tutorials via Google, for instance this one.
Upvotes: 0
Reputation: 279990
You would have a default key for each String you need translated:
title=The StackOverflow
content=The StackOverflow is an interesting site.
This would be stored in text_EN.properties for the EN locale.
For each other language, you would have text_.properties. Example text_FR.properties:
title=Le StackOverflow
content=Le StackOverflow est un site interessant.
(title, content, and other keys should are your keys and should be the same in all your properties files, since that is how you access them.)
When you are about to write the text to the pdf, you would acquire each value from the relevant properties file, based on the locale/language you need.
There are different templating languages you can use for this if you don't want to do it yourself. Thymeleaf
comes to mind, but I think there is also Velocity
.
Upvotes: 1