The original idea is from Alexander Buzmakov, with his version for Oxygen.
Here is now a version for Breakdance. This snippet will add a new condition, called Locale:
And then you will be able to choose one of the language you have previously added with Polylang:
Paste the following code in your favorite Snippet Manager (or in the functions.php file if you use Breakdance Zero Theme
add_action("breakdance_register_template_types_and_conditions", function () {
if (function_exists("pll_languages_list")) {
$lang_list = pll_languages_list();
\Breakdance\ConditionsAPI\register([
"supports" => ["element_display", "templating"],
"slug" => "polylang-condition", // MUST BE UNIQUE
"label" => "Locale",
"category" => "Polylang",
"operands" => ["equals", "not equals"],
"values" => function () use ($lang_list) {
return [
[
"label" => "Language",
"items" => array_map(function ($lang_list) {
return [
"text" => $lang_list,
"value" => $lang_list,
];
}, $lang_list),
],
];
},
"allowMultiselect" => false,
"callback" => function (string $operand, $value) {
$myVal = pll_current_language();
if ($operand === "equals") {
return $myVal === $value;
}
if ($operand === "not equals") {
return $myVal !== $value;
}
return false;
},
]);
}
});
if (function_exists("pll_languages_list")) {
$lang_list = pll_languages_list();
\Breakdance\ConditionsAPI\register([
"supports" => ["element_display", "templating"],
"slug" => "polylang-condition", // MUST BE UNIQUE
"label" => "Locale",
"category" => "Polylang",
"operands" => ["equals", "not equals"],
"values" => function () use ($lang_list) {
return [
[
"label" => "Language",
"items" => array_map(function ($lang_list) {
return [
"text" => $lang_list,
"value" => $lang_list,
];
}, $lang_list),
],
];
},
"allowMultiselect" => false,
"callback" => function (string $operand, $value) {
$myVal = pll_current_language();
if ($operand === "equals") {
return $myVal === $value;
}
if ($operand === "not equals") {
return $myVal !== $value;
}
return false;
},
]);
}
});