Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

How does languages work programmatically?


g_p_java

Recommended Posts

Hello,

 

i haven't understood how the change language in customer pages works.

For example, i'm the customer and i have chosen to view a product in english.

i change my mind and i choose french/german language in order to view

the same product.then the page automatically directs me to

the translated page.

In the code how does this work, i notice in the bar address that

language=en changes to another language when i click another flag.

I have not understood which is the way of doing and how does this work in the code??

 

thanks, in advance.

Link to comment
Share on other sites

The current language is stored in the PHP session as $_SESSION['language']. This is done in application_top.php.

 

The global variable $language is used as part of the directory/file name to include the appropriate language files. For example, if $language is "english" and we're viewing index.php, then the following two files would be included:

 

  • catalog/includes/languages/english.php
  • catalog/includes/languages/english/index.php

But if $language was "german", then these files would get loaded instead:

 

  • catalog/includes/languages/german.php
  • catalog/includes/languages/german/index.php

 

If the current language is changed, via the language=XX GET variable, then application_top.php saves the new language in the session and modifies $language to be the corresponding value.

 

Note that the XX in language=XX is the language ID. A database lookup is then performed to translate this into the string used in $language. For instance, "en" would become "english".

 

 

.

Check out Chad's News.

Link to comment
Share on other sites

This is the code in application_top.php which first set teh value for Language.

 

// set the language

if (!tep_session_is_registered('language') || isset($HTTP_GET_VARS['language'])) {

if (!tep_session_is_registered('language')) {

tep_session_register('language');

tep_session_register('languages_id');

}

 

include(DIR_WS_CLASSES . 'language.php');

$lng = new language();

 

if (isset($HTTP_GET_VARS['language']) && tep_not_null($HTTP_GET_VARS['language'])) {

$lng->set_language($HTTP_GET_VARS['language']);

} else {

$lng->get_browser_language();

}

 

$language = $lng->language['directory'];

$languages_id = $lng->language['id'];

}

 

// include the language translations

require(DIR_WS_LANGUAGES . $language . '.php');

 

Later on all sql queries will use this language id, language directory to get data from language files or from data base.

 

From data base through admin you can define contents for specific language throguh product page.

 

Satish

Ask/Skype for Free osCommerce value addon/SEO suggestion tips for your site.

 

Check My About US For who am I and what My company does.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...