Wordpress Multilanguage with variable and get request

174 Views Asked by At

i tried almost all plugins and not giving me what im looking for

im looking to click on a _GET link and convert site / content to another dir / lang and have 2 variable for each Lang as example :

  $is_lang = htmlspecialchars($_SESSION['WPLANG'], ENT_QUOTES);
  $is_en = htmlspecialchars('en_US', ENT_QUOTES);
  $is_ar = htmlspecialchars('ar', ENT_QUOTES);
    
    if(isset($is_lang) = $is_en):
--    
-- show something
--
    elseif(isset($is_lang) = $is_ar):
--    
-- show something
--
    endif;

so i end up with this wp-config :

$language = isset( $_GET['lang'] ) ? htmlspecialchars($_GET['lang'], ENT_QUOTES) : 'en';
switch ( $language ) {
    case 'ar':
        define( 'WPLANG', 'ar' );
        $_SESSION['WPLANG'] = 'ar';
    break;

    case 'en':
    default:
    define( 'WPLANG', 'en_US' );
    $_SESSION['WPLANG'] = 'en_US';
}
1

There are 1 best solutions below

0
On

i came out with sloution:

Fist use this code in wp-config :

    $language = isset( $_GET['lang'] ) ? htmlspecialchars($_GET['lang'], ENT_QUOTES) : 'en';
switch ( $language ) {
    case 'ar':
        define( 'WPLANG', 'ar' );
        $_SESSION['WPLANG'] = 'ar';
    break;

    case 'en':
    default:
    define( 'WPLANG', 'en_US' );
    $_SESSION['WPLANG'] = 'en_US';
}

than you will get 2 lang ready but most your theme has rtl.css so in rtl.css put :

body{
direction: rtl;
unicode-bidi: embed;
}

and now you can do if / else anywhere to show or hide or do your own trick with :

<?php if(get_locale() == 'ar'): ?>
<!-- if Arabic: something goes here. -->
<?php elseif(get_locale() == 'en_US'): ?>
<!-- if English: something goes here. -->
<?php endif; ?>