handling leanguage change on editor

This commit is contained in:
Antoine M 2023-11-23 16:47:08 +01:00
parent ca237ed837
commit c88d0ba37c
6 changed files with 43 additions and 8 deletions

View File

@ -1 +1 @@
<?php return array('dependencies' => array('react', 'wp-block-editor', 'wp-blocks', 'wp-core-data', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => 'ba8f00e47dc94991ab84');
<?php return array('dependencies' => array('react', 'wp-block-editor', 'wp-blocks', 'wp-core-data', 'wp-data', 'wp-element', 'wp-i18n'), 'version' => 'abacad7c685ec920b653');

View File

@ -161,6 +161,24 @@ function Edit({
const currentTaxonomies = (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_5__.useSelect)(select => select("core/editor").getCurrentPostAttribute("thematiques"));
let currentThematique = (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_5__.useSelect)(select => select("core").getEntityRecord("taxonomy", "thematiques", currentTaxonomies[0] // or currentPost.thematiques[0] works as well
), [currentTaxonomies]);
function getAdminLanguageFromCookie(c_name) {
var c_value = document.cookie,
c_start = c_value.indexOf(" " + c_name + "=");
if (c_start == -1) c_start = c_value.indexOf(c_name + "=");
if (c_start == -1) {
c_value = null;
} else {
c_start = c_value.indexOf("=", c_start) + 1;
var c_end = c_value.indexOf(";", c_start);
if (c_end == -1) {
c_end = c_value.length;
}
c_value = unescape(c_value.substring(c_start, c_end));
}
return c_value;
}
const currentLang = getAdminLanguageFromCookie("wp-wpml_current_language");
const localBlockName = currentLang === "fr" ? "Vocabulaire" : "Vocabulairen";
(0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.useEffect)(() => {
if (currentPost.content && currentBlocks) {
const newTooltipWords = buildTooltipWords();
@ -177,7 +195,7 @@ function Edit({
})
}, (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)("h2", {
className: "homegrade-blocks-vocabulaire-summary__title"
}, "Vocabulaire \u2014", " ", currentThematique && currentThematique.name ? currentThematique.name : "{...pas de thématique}"), tooltipWords && tooltipWords.map(elem => (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)("details", {
}, localBlockName + " — ", currentThematique && currentThematique.name ? currentThematique.name : "...pas de thématique"), tooltipWords && tooltipWords.map(elem => (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)("details", {
className: "question"
}, (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)("summary", null, elem.tooltipText, (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", {
className: "open-close-icon"

File diff suppressed because one or more lines are too long

View File

@ -6,7 +6,7 @@ $thematique = get_the_terms($post->ID, 'thematiques')[0];
<section id="vocabulaire-summary" class="homegrade-blocks-vocabulaire-summary">
<h2 className="homegrade-blocks-vocabulaire-summary__title">
Vocabulaire <?php echo $thematique->name ? "" . $thematique->name : ""; ?>
<?php echo __("Vocabulaire", "homegrade-blocks") ?><?php echo $thematique->name ? " — " . $thematique->name : ""; ?>
</h2>
<?php foreach ($tooltipWords as $word) : ?>

View File

@ -132,7 +132,24 @@ export default function Edit({ attributes, setAttributes }) {
),
[currentTaxonomies]
);
function getAdminLanguageFromCookie(c_name) {
var c_value = document.cookie,
c_start = c_value.indexOf(" " + c_name + "=");
if (c_start == -1) c_start = c_value.indexOf(c_name + "=");
if (c_start == -1) {
c_value = null;
} else {
c_start = c_value.indexOf("=", c_start) + 1;
var c_end = c_value.indexOf(";", c_start);
if (c_end == -1) {
c_end = c_value.length;
}
c_value = unescape(c_value.substring(c_start, c_end));
}
return c_value;
}
const currentLang = getAdminLanguageFromCookie("wp-wpml_current_language");
const localBlockName = currentLang === "fr" ? "Vocabulaire" : "Vocabulairen";
useEffect(() => {
if (currentPost.content && currentBlocks) {
const newTooltipWords = buildTooltipWords();
@ -150,10 +167,10 @@ export default function Edit({ attributes, setAttributes }) {
})}
>
<h2 className="homegrade-blocks-vocabulaire-summary__title">
Vocabulaire {" "}
{localBlockName + " — "}
{currentThematique && currentThematique.name
? currentThematique.name
: "{...pas de thématique}"}
: "...pas de thématique"}
</h2>
{tooltipWords &&
tooltipWords.map((elem) => (

View File

@ -6,7 +6,7 @@ $thematique = get_the_terms($post->ID, 'thematiques')[0];
<section id="vocabulaire-summary" class="homegrade-blocks-vocabulaire-summary">
<h2 className="homegrade-blocks-vocabulaire-summary__title">
Vocabulaire <?php echo $thematique->name ? "" . $thematique->name : ""; ?>
<?php echo __("Vocabulaire", "homegrade-blocks") ?><?php echo $thematique->name ? " — " . $thematique->name : ""; ?>
</h2>
<?php foreach ($tooltipWords as $word) : ?>