vv1.14.0
Main
The project includes a lightweight internationalization system to handle multi-language responses. This is particularly useful for returning error messages or notifications in the user's preferred language.
The translation files and logic are located in src/infrastructure/languages/.
Currently, the system supports:
en.json)es.json)pt.json) - used as pt-br in the code.en.json) {
"ERR_UNAUTHORIZED": "You are not authorized to access this resource.",
"ERR_NOT_FOUND": "The requested resource was not found."
}You can import the translate function directly.
import translate from '@infrastructure/languages/translate';
// Default (English)
const msg = translate('ERR_UNAUTHORIZED');
// Specific language
const msgPt = translate('ERR_UNAUTHORIZED', 'pt-br');The container provided to actions usually has access to the user's language, allowing for seamless translations.
export default async function myAction(request: container) {
// ... logic
if (error) {
throw request.badRequest(request.language(), "MY_ERROR_KEY");
}
}