Handling right-to-left languages (Arabic, Hebrew, Persian, Urdu) with Lang Forge.
Detecting RTL Languages
php
/**
* Check if the current language is RTL.
*
* @return bool True if current language is RTL
*/
function theme_is_rtl_language() {
$rtl_languages = ['ar', 'he', 'fa', 'ur', 'yi', 'ku'];
return in_array(lf_get_current_language(), $rtl_languages);
}
// Set the text direction on the HTML element
add_filter('language_attributes', function ($output) {
if (theme_is_rtl_language()) {
$output .= ' dir="rtl"';
}
return $output;
});Loading RTL Stylesheets
php
add_action('wp_enqueue_scripts', function () {
wp_enqueue_style('theme-main', get_template_directory_uri() . '/css/style.css');
if (theme_is_rtl_language()) {
wp_enqueue_style('theme-rtl', get_template_directory_uri() . '/css/rtl.css', ['theme-main']);
}
});css
/* Use CSS logical properties for automatic RTL support */
.sidebar {
margin-inline-start: 0;
margin-inline-end: 20px;
padding-inline-start: 15px;
border-inline-start: 3px solid #2b6cb0;
}
.breadcrumbs .separator {
margin-inline: 8px;
}
/* RTL-specific overrides when logical properties are not sufficient */
[dir="rtl"] .icon-arrow {
transform: scaleX(-1);
}
[dir="rtl"] .text-align-left {
text-align: right;
}php
// Load RTL-specific template parts
$lang = lf_get_current_language();
$rtl = theme_is_rtl_language();
if ($rtl) {
get_template_part('partials/header', 'rtl');
} else {
get_template_part('partials/header', 'default');
}—