Forum Archive - how to retrieve the language variable

how to retrieve the language variable
Aug 19, 2016 6:25 pm by yule
I try to recover the language variables used by the visitor to adapt my images I use this on my htacces # gtranslate config RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] RewriteRule ^(af|sq|am|ar|hy|az|eu|be|bn|bs|bg|ca|ceb|ny|zh-CN|zh-TW|co|hr|cs|da|nl|en|eo|et|tl|fi|fr|fy|gl|ka|de|el|gu|ht|ha|haw|iw|hi|hmn|hu|is|ig|id|ga|it|ja|jw|kn|kk|km|ko|ku|ky|lo|la|lv|lt|lb|mk|mg|ms|ml|mt|mi|mr|mn|my|ne|no|ps|fa|pl|pt|pa|ro|ru|sm|gd|sr|st|sn|sd|si|sk|sl|so|es|su|sw|sv|tg|ta|te|th|tr|uk|ur|uz|vi|cy|xh|yi|yo|zu)/(af|sq|am|ar|hy|az|eu|be|bn|bs|bg|ca|ceb|ny|zh-CN|zh-TW|co|hr|cs|da|nl|en|eo|et|tl|fi|fr|fy|gl|ka|de|el|gu|ht|ha|haw|iw|hi|hmn|hu|is|ig|id|ga|it|ja|jw|kn|kk|km|ko|ku|ky|lo|la|lv|lt|lb|mk|mg|ms|ml|mt|mi|mr|mn|my|ne|no|ps|fa|pl|pt|pa|ro|ru|sm|gd|sr|st|sn|sd|si|sk|sl|so|es|su|sw|sv|tg|ta|te|th|tr|uk|ur|uz|vi|cy|xh|yi|yo|zu)/(.*)$ /$1/$3 [R=301,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(af|sq|am|ar|hy|az|eu|be|bn|bs|bg|ca|ceb|ny|zh-CN|zh-TW|co|hr|cs|da|nl|en|eo|et|tl|fi|fr|fy|gl|ka|de|el|gu|ht|ha|haw|iw|hi|hmn|hu|is|ig|id|ga|it|ja|jw|kn|kk|km|ko|ku|ky|lo|la|lv|lt|lb|mk|mg|ms|ml|mt|mi|mr|mn|my|ne|no|ps|fa|pl|pt|pa|ro|ru|sm|gd|sr|st|sn|sd|si|sk|sl|so|es|su|sw|sv|tg|ta|te|th|tr|uk|ur|uz|vi|cy|xh|yi|yo|zu)/(.*)$ /gtranslate/gtranslate.php?glang=$1&gurl=$2&glangy=$1 [L,QSA] RewriteRule ^(af|sq|am|ar|hy|az|eu|be|bn|bs|bg|ca|ceb|ny|zh-CN|zh-TW|co|hr|cs|da|nl|en|eo|et|tl|fi|fr|fy|gl|ka|de|el|gu|ht|ha|haw|iw|hi|hmn|hu|is|ig|id|ga|it|ja|jw|kn|kk|km|ko|ku|ky|lo|la|lv|lt|lb|mk|mg|ms|ml|mt|mi|mr|mn|my|ne|no|ps|fa|pl|pt|pa|ro|ru|sm|gd|sr|st|sn|sd|si|sk|sl|so|es|su|sw|sv|tg|ta|te|th|tr|uk|ur|uz|vi|cy|xh|yi|yo|zu)$ /$1/ [R=301,L] I added this variable glangy (&glangy=$1) and then I do this to test if ($_GET['glangy']!=''){ $langue2 ="1"; } else { $langue2 ="0"; } echo $langue2; I wish only the difference between the primary language (fr) and other languages It works only on my finger and not on the other pages of my site. I must do something wrong but I do not know what .. Thank you for your help Steve
Re: how to retrieve the language variable
Aug 19, 2016 6:49 pm by Edvard
You can use $_SERVER['HTTP_X_GT_LANG'] variable. https://gtranslate.io/docs/58-gtranslat ... umentation Detecting selected language If you want to code something special for individual language you can detect the current selected language and write your code based on that. You can find the current selected language code from X-GT-Lang request header. If your site is written in PHP you can find it in _SERVER['HTTP_X_GT_LANG'] variable. Thanks!
Re: how to retrieve the language variable
Aug 19, 2016 7:02 pm by yule
Hello Thank you for your reply but I'm afraid not know how to use ..... We need to _SERVER [ 'HTTP_X_GT_LANG'] in the header as well? <?php _SERVER [ 'HTTP_X_GT_LANG'] ?> And how do I do with an "if" to know? just like that ? if ($_SERVER['HTTP_X_GT_LANG']!=''){ $langue2 ="1"; } else { $langue2 ="0"; } echo $langue2; Sorry.....
Re: how to retrieve the language variable
Aug 19, 2016 7:06 pm by Edvard
I'm not sure I understand you. $_SERVER['HTTP_X_GT_LANG'] variable will contain the language code if you are not on your default language. For example: if($_SERVER['HTTP_X_GT_LANG'] == 'fr') echo 'test'; Thanks!

SIMILAR TOPICS

Large numbers of crawl errors with double language codeJan 24, 2019 1:43 amReplies: 1Post by: natastna2
Translate website to any specific language, on page loadJan 19, 2019 6:49 amReplies: 1Post by: Leaon7756
Graphic translation for every language is missingDec 19, 2018 7:54 amReplies: 1Post by: Daryl Dixon
How to remove mobile Language Select Button transparencyDec 5, 2018 10:06 pmReplies: 10Post by: JeffTR
Change language automaticallyNov 26, 2018 9:29 pmReplies: 3Post by: Antilb

Try GTranslate with a free 15 day trial