We help IT Professionals succeed at work.

Multi languages & HTML editor(s)

sh2gr
sh2gr asked
on
Medium Priority
311 Views
Last Modified: 2013-12-16
Hello

As I will set up a multi language shop (with ENG as default), I want to ask if there is a way -when adding a new product- to have the english description displayed for each other languages.
So far.....(for 5 languages) I have 5 HTML editors displayed on my "new product" entry page and have to add 5 times the same Description, but I need only the english.
When nothing is entered for non english languages....nothing will be dispalyed inside the shop when switching between languages.

The section for the HTML editor (product description) is this:
......
$oFCKeditor->Value = (isset($products_description[$languages[$i]['id']])) ? stripslashes($products_description[$languages[$i]['id']]) : get_products_description($pInfo->products_id, $languages[$i]['id']) ;
.......
echo draw_textarea_field('products_description[' . $languages[$i]['id'] . ']', 'soft', '100%', '20', (isset($products_description[$languages[$i]['id']])) ? stripslashes($products_description[$languages[$i]['id']]) : get_products_description($pInfo->products_id, $languages[$i]['id'])); //,'id="'.'products_description' . $languages[$i]['id'] . '"');

 

Dimi
Comment
Watch Question

Do you want to display the description in english, if the non-english description is not available?

If yes
If your function get_products_description() returns the description from the DB, on the base language id specified. You can change this function behaviour in such a way, it returns english description if the non-english is not available.

Author

Commented:
Hello

thats correct. I want the english description to be taken from the db if there is no other available (in the non english).
Some if function...right?

Well what would the code be?
post the code of get_products_description()

Author

Commented:
Ohh...right, sorry :-)  

function get_products_description($product_id, $language_id) {
    global $db;
    $product = $db->Execute("select products_description
                             from " . TABLE_PRODUCTS_DESCRIPTION . "
                             where products_id = '" . (int)$product_id . "'
                             and language_id = '" . (int)$language_id . "'");

    return $product->fields['products_description'];
  }
function get_products_description($product_id, $language_id) {
    global $db;
    $english_id = 1;//replace 1 with the id of english
    $product = $db->Execute("select products_description
                             from " . TABLE_PRODUCTS_DESCRIPTION . "
                             where products_id = '" . (int)$product_id . "'
                             and language_id = '" . (int)$language_id . "'");

   //this will check if the language is non-english and description is not defined, get the english description from the db
   if(trim($product->fields['products_description'])=="" && $language_id!=$english_id)
      $product = $db->Execute("select products_description
                             from " . TABLE_PRODUCTS_DESCRIPTION . "
                             where products_id = '" . (int)$product_id . "'
                             and language_id = '" . $english_id . "'");

   return $product->fields['products_description'];
}

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
Thank you...so far so good, the description shows up in the non english fields (editors).
But it don't writes into the database....i receive blank product descriptions when viewing in different than english language

>>>But it don't writes into the database....i receive blank product descriptions when viewing in different than english language

I didnt understand
Do you function other than get_products_description() to display description or using the same function everywhere?

Author

Commented:
Yes...my fault.  Before executing the "save new product", I can preview it at the new_product_preview page

This is the additional functions
Start document:

 if (not_null($_POST)) {
      $pInfo = new objectInfo($_POST);
      $products_name = $_POST['products_name'];
      $products_description = $_POST['products_description'];
      $products_url = $_POST['products_url'];
    } else {
      $products = $db->Execute("select p.products_id, pd.language_id, pd.products_name,
                                      pd.products_description, pd.products_url, p.products_quantity,
                                      p.products_model, p.products_image, p.products_price, p.products_virtual,
                                      p.products_weight, p.products_date_added, p.products_last_modified,
                                      p.products_date_available, p.products_status, p.manufacturers_id,
                                      p.products_quantity_order_min, p.products_quantity_order_units, p.products_priced_by_attribute,
                                      p.product_is_free, p.product_is_call, p.products_quantity_mixed,
                                      p.product_is_always_free_shipping, p.products_qty_box_status, p.products_quantity_order_max,
                    p.products_sort_order
                               from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd
                               where p.products_id = pd.products_id
                               and p.products_id = '" . (int)$_GET['pID'] . "'");

      $pInfo = new objectInfo($product->fields);
      $products_image_name = $pInfo->products_image;
    }

    $form_action = (isset($_GET['pID'])) ? 'update_product' : 'insert_product';

    echo draw_form($form_action, $type_admin_handler, 'cPath=' . $cPath . (isset($_GET['product_type']) ? '&product_type=' . $_GET['product_type'] : '') . (isset($_GET['pID']) ? '&pID=' . $_GET['pID'] : '') . '&action=' . $form_action . (isset($_GET['page']) ? '&page=' . $_GET['page'] : ''), 'post', 'enctype="multipart/form-data"');

    $languages = get_languages();
    for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
      if (isset($_GET['read']) && ($_GET['read'] == 'only')) {
        $pInfo->products_name = get_products_name($pInfo->products_id, $languages[$i]['id']);
        $pInfo->products_description = get_products_description($pInfo->products_id, $languages[$i]['id']);
        $pInfo->products_url = get_products_url($pInfo->products_id, $languages[$i]['id']);
      } else {
        $pInfo->products_name = db_prepare_input($products_name[$languages[$i]['id']]);
        $pInfo->products_description = db_prepare_input($products_description[$languages[$i]['id']]);
        $pInfo->products_url = db_prepare_input($products_url[$languages[$i]['id']]);
      }

      $specials_price = get_products_special_price($pID);
*********************************************
at the page end
*********************************************
 reset($_POST);
      while (list($key, $value) = each($_POST)) {
        if (!is_array($_POST[$key])) {
          echo draw_hidden_field($key, htmlspecialchars(stripslashes($value)));
        }
      }

      $languages = get_languages();
      for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
        echo draw_hidden_field('products_name[' . $languages[$i]['id'] . ']', htmlspecialchars(stripslashes($products_name[$languages[$i]['id']])));
        echo draw_hidden_field('products_description[' . $languages[$i]['id'] . ']', htmlspecialchars(stripslashes($products_description[$languages[$i]['id']])));
        echo draw_hidden_field('products_url[' . $languages[$i]['id'] . ']', htmlspecialchars(stripslashes($products_url[$languages[$i]['id']])));
      }
      echo draw_hidden_field('products_image', stripslashes($products_image_name));

      echo image_submit('button_back.gif', IMAGE_BACK, 'name="edit"') . '&nbsp;&nbsp;';

      if (isset($_GET['pID'])) {
        echo image_submit('button_update.gif', IMAGE_UPDATE);
      } else {
        echo image_submit('button_insert.gif', IMAGE_INSERT);
      }
      echo '&nbsp;&nbsp;<a href="' . href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . (isset($_GET['pID']) ? '&pID=' . $_GET['pID'] : '') . (isset($_GET['page']) ? '&page=' . $_GET['page'] : '')) . '">' . image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>';


Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.