Hi guys, I'm new to JAVA and I want to build a service (classes) to translate error message before sending to Client. But unlike js, I can define an error file as JSON. Anyone know how to do it in JAVA or the way to save translation data (EX: EN, MALAY) and use it to find the correct error code to return the translated message? (I don't want to use I18n). Thanks in advance
#Build Error Translation Service (Classes)
13 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @oblique goblet! Please use
/closeor theClose Postbutton above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
what you have done so far?
i mean do know how to read and write to files?
I don't know what to do. For EX:
In JS I can have this JSON:
{
'INVALID_USER': {
'en': 'Invalid user',
'xx': ' xx xxx xx'
}
}
then when throwing new error like: throw new BadRequestionException("INVALID_USER")
In behind the scene, I will map the actual message from the json file and then send it to Client
but for JAVA, I don't know how can save data like JSON and get translation easily based on the INVALID_USER and (Accept-langague: xx)
use a Map object instead of json!
@oblique goblet if you don't need to use Json specifically, java has a feature called a ResourceBundle which supports this kind of translation which might be worth checking out: https://docs.oracle.com/javase/tutorial/i18n/resbundle/concept.html
This internationalization Java tutorial describes setting locale, isolating locale-specific data, formatting data, internationalized domain name and resource identifier
I will check this. Thanks a lot
That's ok. Close post when done