Open jakxnz opened 3 years ago
Not 100% sure what's causing this, but a good fix would be to ensure that all CMS preview links had the locale querystring hard-coded into the url. :P That could probably "force" the rendered locale to be correct.
I can see that working.
We overrode the logic at https://github.com/tractorcow-farm/silverstripe-fluent/blob/5.0/src/Middleware/InitStateMiddleware.php#L74, to make our project consider the CMSPrevew as "frontend"
i.e
/**
* Customised middleware for initialising fluent state
*/
class InitStateMiddleware extends \TractorCow\Fluent\Middleware\InitStateMiddleware
{
/**
* Overriding {@see \TractorCow\Fluent\Middleware\InitStateMiddleware::getIsFrontend()}
* to tweak a small aspect of the logic
*
* {@inheritDoc}
*/
public function getIsFrontend(HTTPRequest $request)
{
$bool = parent::getIsFrontend($request);
if ($request->getVar('CMSPreview')) {
$bool = true;
}
return $bool;
}
}
I think there's an argument that maybe CMSPreview SHOULD have been treated as frontend.
Maybe we should make that change up into core?
Good debugging by the way. :)
The reason for this may have been the "you can see un-localised pages in the CMS only" problem. It shouldn't be an issue if we have saved the page, and it's visible in the current locale.
That does raise an interesting point. It also makes me wonder: If page content is being inherited from a default locale, should the i18n translations match the currently selected locale in the CMS? Or should they also defer to the default locale?
If we want alignment, we have the inverse issue at the frontend. I believe (using the current version), if you're viewing content inherited from a fallback locale, it will still display the i18n references for the current locale.
Versions
Issue
Content that I configure in an i81n language file (e.g
app/_config/lang/mi.yml
) is not displayed when I view the website via the CMS Preview in that same localeSteps to reproduce:
mi.yml
https://docs.silverstripe.org/en/4/developer_guides/i18n/, add a translate reference in the locale's namespacemi_NZ
_t
reference (either with the PHP function or a template) somewhere that appears on the front-end (e.g inPage.ss
or the like)_t
referenceResult:
The i18n content is not translated to the current Fluent locale, selected in the CMS.
Expected result:
I'm not really sure. It would be nice if the correct language file reference was used, but I don't know if this causes any conflicts. Any thoughts?