-
-
Notifications
You must be signed in to change notification settings - Fork 825
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
APIv4 - Add generic setLanguage
, to all APIs
#24116
APIv4 - Add generic setLanguage
, to all APIs
#24116
Conversation
(Standard links)
|
e5f0a9a
to
8ba78f3
Compare
* If set then listeners such as the Translation subsystem may alter | ||
* the output. | ||
* | ||
* @var string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you grep for @option
, then there are a couple examples like:
Civi/Api4/Generic/AbstractSaveAction.php: * @optionsCallback getMatchFields
Civi/Api4/Generic/ExportAction.php: * @options never,always,unmodified
Civi/Api4/Generic/ExportAction.php: * @options never,always,unused
Civi/Api4/Action/WorkflowMessage/GetTemplateFields.php: * @options metadata,example
Civi/Api4/Action/WorkflowMessage/Render.php: * @options error,warning,info
So this could probably use an @optionsCallback
?
a92d8a5
to
d14d0ae
Compare
For reference, I had some notes from before about different notations that could be used for requesting translation on API calls (eg Every item in the gist has trade-offs. The trade-offs here are:
|
47a65a5
to
d618640
Compare
setPreferredLanguage
, to all APIssetLanguage
, to all APIs
d618640
to
8692378
Compare
Closing in the expectation we proceed with #24174 |
Overview
This updates the api contract to support
setLanguage
eg.At a generic level this provides a way for an api consumer to specify where there is a language preference. A language preference does not mean that something usable by that language will be available - but it allows listeners, including the core
Translation
BAO to provide them.If the language preference alters the api behaviour then the record should have
actual_language
set on it.The language preferrence can be implemented by any hook - however, core core will implement the translation model for any entity/field combos which have been marked as
translatedFields
. For these fields (only MessageTemplate fields in core) theTranslation
BAO will add in the message template fields formsg_subject, msg_html and msg_text
if translations exist.This results in a return like the image below, where the first template has no translation and the second has one
Split off from #23844
Before
No way to invoke the
Translation
retrieval from coreAfter
setPreferredLanguage
can be set on any api action This indicates that where possible that language should be used, allowing for both custom hooks and for core code to retrieve any existing translations.In the core
BAO_Translation
code any translated fields will be swapped out with one in the preferred language, or a variant (eg. French will returned if French Canadian is preferred but only a French translation is available). If a substitution is retrieved then theactual_language
property will be added to the return resultTechnical Details
Note that the
BAO_Translation
code only kicks in when a field is defined as translatable using thetranslateFields
hook - per#24063 - this hook will be defined in core for ONLY the message template fields (as core will render these for sending languages) - any other fields would need to be defined in an extension, or a new discussion started
Comments
Coleman's input was
However - I used
actual_language
rather than justlanguage
which is already used in at least one table (erm the translation table)