The JavaScript REST API framework (rest.js) provides some methods to easily make requests, but it doesn't handle responses, and error messages in particular. If there's an error, the REST API returns all error messages already translated, in the messageTranslations key, for instance:
"messageTranslations": { "en": "A message in English" "fr": "Un message en Français" }
Right now the languages are always English and the content language, but I assume this should change at some point (T269492). This means that if some code wants to display a localized error message, they have to do something like:
msg = apiResponse.messageTranslations[ mw.config.get( 'wgContentLanguage' ) ]
which is subpar because :
- It depends on an implementation detail (the REST API using the content language) that could change in the future
- It seems unnecessarily long
- It wouldn't scale if the list of languages is changed (e.g., to use the Accept-Language header or some MW-specific header or parameter)
Instead, I would like rest.js to choose the appropriate language, based on whatever criteria the REST API framework uses. This could happen either transparently by changing the return value of ajax() before the caller sees it, or it could be a helper method. It could also either just return the most appropriate translation, or a sorted list of translations.