In the context of Loading... we’d like to introduce a REST endpoint to resolve translation keys.
The main goal is to allow JavaScript code to use localized messages without having to rely on Velocity code. The JavaScript module that needs to use some translation keys would fetch them using an URL like this:
This is endpoint should be called with the GET method, and the following parameters:
locale: Optional, defined the locale of the request translation values, otherwise the local of the context will be used.
prefix: Optional, a common prefix used for all the provided keys
key: (one or many), once for each requested translation key
The response is an object, where the keys as the requested translation keys and the values the raw translation values (i.e., where the parameters are not resolved), for instance:
raw translation values (i.e., where the parameters are not resolved)
just for info, the idea is to improve this later to be able to pass parameters to the REST API, or to have them resolved on JS side, in which case, is there a plan for having a common API for that?
The two use cases are not exclusive and resolving the parameters server side could be useful.
Regarding a client side localization API, @cdesableau is working on the integration of vue-i18n and iirc @mflorea has some existing code in CKEditor which could be externalized too.
This (making a separate HTTP request for each translation to resolve its parameters) is not practical for the front-end so I don’t think we’ll need it.
Yes, we plan to have some JavaScript module to handle this, but it’s outside the scope of this proposal.