refactor: translations class usage

This commit is contained in:
Zack Spear
2023-11-09 16:49:47 -08:00
parent e409ab805d
commit 62900565fb
2 changed files with 13 additions and 1 deletions

View File

@@ -7,7 +7,7 @@ $serverState = new ServerState();
$wCTranslations = new WebComponentTranslations();
?>
<script>
window.LOCALE_DATA = '<?= rawurlencode(json_encode($wCTranslations->getTranslations(), JSON_UNESCAPED_SLASHES, JSON_UNESCAPED_UNICODE)) ?>';
window.LOCALE_DATA = '<?= $wCTranslations->getTranslationsJson(true) ?>';
/**
* So we're not needing to modify DefaultLayout with an additional include, we'll add the Modals web component to the bottom of the body.
*/

View File

@@ -374,4 +374,16 @@ class WebComponentTranslations
{
return $this->translations ?? [];
}
/**
* @param $urlEncode {bool}
* @return string
*/
public function getTranslationsJson($urlEncode = false)
{
if ($urlEncode) {
return rawurlencode(json_encode($this->getTranslations(), JSON_UNESCAPED_SLASHES, JSON_UNESCAPED_UNICODE));
}
return json_encode($this->getTranslations(), JSON_UNESCAPED_SLASHES, JSON_UNESCAPED_UNICODE);
}
}