-
-
Notifications
You must be signed in to change notification settings - Fork 812
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
Resources: set language-specific cacheCode, fixes AngularJS translation with multilingual #22236
Conversation
(Standard links)
|
CRM/Core/Resources.php
Outdated
$this->cacheCode = Civi::settings()->get($cacheCodeKey); | ||
// AngularJS json partials are language-specific because they ship with the strings | ||
// for the current language. | ||
$this->cacheCode = Civi::settings()->get($cacheCodeKey) . CRM_Core_I18n::getLocale(); |
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.
Oh, I like the general idea of incorporating the locale into the browser-side cache-busting code. It seems like it could make several kinds of resources more amenable to multilingual.
Applying the trick in this spot means it applies once - at the start of the page-request. These values might rotate during the page-request (e.g. if the cache-code needs to be expired/reset, or if the locale changes).
Haven't tested, but I think this might be more responsive:
diff --git a/CRM/Core/Resources.php b/CRM/Core/Resources.php
index 0175befd74..4e93411b04 100644
--- a/CRM/Core/Resources.php
+++ b/CRM/Core/Resources.php
@@ -334,9 +334,11 @@ class CRM_Core_Resources implements CRM_Core_Resources_CollectionAdderInterface
/**
* @return string
+ * A random-looking string that may be appended to resource-URLs.
+ * This should be URL-safe (ie use alphanumerics and underscores).
*/
public function getCacheCode() {
- return $this->cacheCode;
+ return $this->cacheCode . CRM_Core_I18n::getLocale();
}
/**
@@ -563,7 +565,7 @@ class CRM_Core_Resources implements CRM_Core_Resources_CollectionAdderInterface
$hasQuery = strpos($url, '?') !== FALSE;
$operator = $hasQuery ? '&' : '?';
- return $url . $operator . 'r=' . $this->cacheCode;
+ return $url . $operator . 'r=' . $this->getCacheCode();
}
/**
fdeac61
to
98e2d42
Compare
Thanks Tim! I tested your suggestion and it works as well, and makes more sense. Updated my PR. |
@mlutfy test fails seem related |
2d4ff3b
to
6ccd2ae
Compare
… translation with multilingual
6ccd2ae
to
8b547c5
Compare
Yay tests pass, but I had to tweak them. Can someone double-check if it looks OK? |
@mlutfy Patch looks good. Update to the tests makes perfect sense. Did an |
Overview
To reproduce:
Result: the page will still be in English.
Example URL on dmaster, after adding French, and enabling asset-caching (dmaster does not enable it by default, because debugging is enabled):
(because the core language switcher does not support AngularJS, fortunately the language-switcher extension does.)
Before
Pages are randomly translated:
After
Pages are always in the correct language.
Technical Details
My fix feels duct-tape-y. I don't know if it will cause other problems. Testing it in production for now. Opening the PR for discussion.