Custom Image URLs for different languages

Popular automatic website translation tool

Custom Image URLs for different languages

Postby jb11 » Fri Dec 09, 2011 9:51 pm

Hi Edvard

I have been using GTranslate with huge success and all is working well.

I am aware you are working an a feature whereby we can change the images/media on our website as well to show images based on the language being viewed by the visitor. At the moment, all my English static images/banners are showing-up for all the 23 languages I am using on my site via GTranslate.

Until the feature will be available in future, I need to now attempt to do something myself to, via php and jumi for joomla, change the image urls based on the language code in the mod_rewrite URL as per the address bar.

I want to use your Jumi (Joomla) product (I know how to use Jumi) to run a php script to:

(1) use the "$_SERVER['REQUEST_URI'];" php command to get the mod_rewrite URL in the browser; I know how to do this.

(2) and to use this string to search for the applicable language being seen by the website visitor. E.g.if "$_SERVER['REQUEST_URI'];" has the value "/es/blog" in it, I will be able to extract the "es" part with PHP; I know how to do this.

(3) use this extracted language code order to show the images I created for the various languages which I also know how to do especially with Jumi for Joomla. PHP will change the img src urls based on this language code. I have my own banners/images which we designed for each language. I just want to ensure the banners show-up for the correct website language.

My problem: $_SERVER['REQUEST_URI']; at the moment does not show me the /es/ (or /it/ or /de/ etc.) part but only the real path.

I have created a php file ("lang.php) with the following code:

Code: Select all

For example, If I visit "", $_SERVER['REQUEST_URI']; actually returns "/" and not "es/".

Should I change something in my htaccess file for this command ($_SERVER['REQUEST_URI'];) to show the language sub-directory generated by mod_rewrite? I need to see the "es/" through the PHP command in order to manipulate my images.

Will appreciate your input on why $_SERVER['REQUEST_URI']; is not showing the language sub-directories... I might be missing something. I am not familiar with .htaccess code although I can change it.

Or is there a more easier way to determine the language code to use Jumi with a GTranslate wesbite?

Thank you

My htaccess file:

Code: Select all
##  Can be commented out if causes errors, see notes above.
#Options +FollowSymLinks

#  mod_rewrite in use

RewriteEngine On

# gtranslate config
        RewriteRule ^([a-z]{2}|zh-CN|zh-TW)/([a-z]{2}|zh-CN|zh-TW)/(.*)$ /$1/$3 [R=301,L]
        RewriteRule ^([a-z]{2}|zh-CN|zh-TW)/([a-z]{2}|zh-CN|zh-TW)$ /$1/ [R=301,L]
        RewriteRule ^([a-z]{2}|zh-CN|zh-TW)/(.*)$ /gtranslate/translate.php?lang=$1&url=$2 [L,QSA]
        RewriteRule ^([a-z]{2}|zh-CN|zh-TW)$ /gtranslate/translate.php?lang=$1 [L,QSA]

# RewriteRule ^(da|nl|de|sv|pl|ro|no|ru|hu|lt|sl|sk|lv|uk|es|pt|it|fi|fr|et|bg|cs|el)/(da|nl|de|sv|pl|ro|no|ru|hu|lt|sl|sk|lv|uk|es|pt|it|fi|fr|et|bg|cs|el)/(.*)$ /$1/$3 [R=301,L]
# RewriteRule ^(da|nl|de|sv|pl|ro|no|ru|hu|lt|sl|sk|lv|uk|es|pt|it|fi|fr|et|bg|cs|el)/(da|nl|de|sv|pl|ro|no|ru|hu|lt|sl|sk|lv|uk|es|pt|it|fi|fr|et|bg|cs|el)$ /$1/ [R=301,L]
# RewriteRule ^(da|nl|de|sv|pl|ro|no|ru|hu|lt|sl|sk|lv|uk|es|pt|it|fi|fr|et|bg|cs|el)/(.*)$ /gtranslate/translate.php?lang=$1&url=$2 [L,QSA]
# RewriteRule ^(da|nl|de|sv|pl|ro|no|ru|hu|lt|sl|sk|lv|uk|es|pt|it|fi|fr|et|bg|cs|el)$ /gtranslate/translate.php?lang=$1 [L,QSA]
########## Begin - Rewrite rules to block out some common exploits
## If you experience problems on your site block out the operations listed below
## This attempts to block the most common type of exploit `attempts` to Joomla!
# Block out any script trying to set a mosConfig value through the URL
RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|\%3D) [OR]
# Block out any script trying to base64_encode crap to send via URL
RewriteCond %{QUERY_STRING} base64_encode.*\(.*\) [OR]
# Block out any script that includes a <script> tag in URL
RewriteCond %{QUERY_STRING} (\<|%3C).*script.*(\>|%3E) [NC,OR]
# Block out any script trying to set a PHP GLOBALS variable via URL
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
# Block out any script trying to modify a _REQUEST variable via URL
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
# Send all blocked request to homepage with 403 Forbidden error!
RewriteRule ^(.*)$ index.php [F,L]
########## End - Rewrite rules to block out some common exploits

#  Uncomment following line if your webserver's URL
#  is not directly related to physical file paths.
#  Update Your Joomla! Directory (just / for root)

RewriteBase /

# ErrorDocument 404 /index.php

########## Begin - Joomla! core SEF Section
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/index.php
RewriteCond %{REQUEST_URI} (/|\.php|\.html|\.htm|\.feed|\.pdf|\.raw|/[^.]*)$  [NC]
RewriteRule (.*) index.php
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
########## End - Joomla! core SEF Section

Posts: 16
Joined: Sat Jul 23, 2011 2:42 am

Re: Custom Image URLs for different languages

Postby Edvard » Tue Dec 13, 2011 12:57 am


Please read this, it should be helpful: url-language-code-t320.html?hilit=glang

Edvard Ananyan - GTranslate Team

Please leave your feedback on your CMS plugin directory. It is very important for us!
Google Translate Joomla
Google Translate WordPress
Google Translate Drupal
Site Admin
Posts: 4156
Joined: Mon Jun 28, 2010 1:54 pm
Location: Yerevan, Armenia

  • Related Topics
    Last post

Who is online

Users browsing this forum: No registered users and 2 guests