-
-
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
Allow custom ts functions in extensions; defer custom ts calls until booted #15411
Conversation
Can one of the admins verify this patch? |
(Standard links)
|
Jenkins add to whitelist |
The build failure is relevant - i.e. indicating that |
Jenkins re test this please |
Changes make sense to me and the fact the build site runs is a good sign this PR is working. |
(CiviCRM Review Template WORD-1.2)
|
Allow custom ts functions in extensions; defer custom ts calls until booted
Overview -------- This fixes a regression in which seed data is not translated. Before ------ The `civicrm_data.*.mysql` files are not translated. After ----- The `civicrm_data.*.mysql` files are translated. There's a unit-test to check this. Comments -------- This regression stems from civicrm#15411, which aimed to allow extensions to define custom variants of `ts()`. The crux of the issue is "What happens if you try to translate a string before the system is bootstrapped - before the extension is loaded? What's your fallback behavior?" In civicrm#15411, it used a fallback behavior of "do no translation". In theory, you shouldn't really get into this scenario since UIs are pretty much always generated post-boot. However, it turns out that there is a situation where you have an un-booted system and need to translate strings -- i.e. when generating the localized `civicrm_data.*.mysql` data. Hence the bug. This patch preserves most of the changes from civicrm#15411, but it changes the fallback behavior from "do no translation" to "use the built-in/default translator".
Overview -------- This fixes a regression in which seed data is not translated. Before ------ The `civicrm_data.*.mysql` files are not translated. After ----- The `civicrm_data.*.mysql` files are translated. There's a unit-test to check this. Comments -------- This regression stems from civicrm#15411, which aimed to allow extensions to define custom variants of `ts()`. The crux of the issue is "What happens if you try to translate a string before the system is bootstrapped - before the extension is loaded? What's your fallback behavior?" In civicrm#15411, it used a fallback behavior of "do no translation". In theory, you shouldn't really get into this scenario since UIs are pretty much always generated post-boot. However, it turns out that there is a situation where you have an un-booted system and need to translate strings -- i.e. when generating the localized `civicrm_data.*.mysql` data. Hence the bug. This patch preserves most of the changes from civicrm#15411, but it changes the fallback behavior from "do no translation" to "use the built-in/default translator".
Overview
Custom ts functions didn't work when they are defined by extensions. The reason is that the
I18n
class starts looking for it when the extension files aren'trequire
d yet, and then gives up before they become available.Before
If you set a custom ts function (
CRM_Core_Config::singleton()->customTranslateFunction
) that is defined in themodule.php
file in an extension, it wouldn't work.After
It does work.
Technical Details
Changes discussed with @totten:
\Civi\Core\Container::isContainerBooted()
instead of\Civi\Core\Container::getBootService('settings_manager')
$areSettingsAvailable
to$bootstrapReady
for clarity.skip_translation
flag tots()
parametersavoid spinning up gettext during bootstrap (in case there is a custom ts function)Comments
Anything else you would like the reviewer to note