Jump to content

Remove language directory for default language


gpisw

Recommended Posts

So I've followed two posts which claim that they work, and I've got no luck.

https://www.prestashop.com/forums/topic/275956-how-to-remove-en-from-default-language/#comment-1465530 <- Later answers claim that work

https://presta.site/blog/en/how-to-remove-en-from-urls-in-prestashop/ <- Self claim that works (and it's an extension of the earlier post, and better executed with override).

 

I've done both and it doesn't delete default language directory. Anyone has done it successfully? The prestashop version I'm using is 1.6.1.16 if it helps.

Also deleted cache after adding files through the backoffice tool.

These are the files added to override/classes

<?php

class Link extends LinkCore
{
    protected function getLangLink($id_lang = null, Context $context = null, $id_shop = null)
    {
        $parent_result = parent::getLangLink($id_lang, $context, $id_shop);

        if ($parent_result) {
            if ($id_lang == Configuration::get('PS_LANG_DEFAULT')) {
                return '';
            } else {
                return $parent_result;
            }
        }
    }
}

 

<?php
/*
* 2007-2013 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
*  @author PrestaShop SA <[email protected]>
*  @copyright  2007-2013 PrestaShop SA
*  @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
*  International Registered Trademark & Property of PrestaShop SA
*/
class Tools extends ToolsCore
{ 
	/*
    * module: smartseoplus
    * date: 2017-10-20 20:04:19
    * version: 1.0.12
    */
    public static function link_rewrite($str, $utf8_decode = null)
	{
		$str=rewrireUnicodeString($str);
		if ($utf8_decode !== null)
			Tools::displayParameterAsDeprecated('utf8_decode');
		return Tools::str2url($str);
	}

	public static function setCookieLanguage($cookie = null)
	{
			parent::setCookieLanguage($cookie);

			if (!$cookie) {
					$cookie = Context::getContext()->cookie;
			}

			if(!Tools::getValue('isolang') && !Tools::getValue('id_lang') && !Tools::isSubmit('id_category_layered')) {
					$cookie->id_lang = Configuration::get('PS_LANG_DEFAULT');
					Context::getContext()->language = new Language($cookie->id_lang);
			}

			/* If language file not present, you must use default language file */
			if (!$cookie->id_lang || !Validate::isUnsignedId($cookie->id_lang)) {
					$cookie->id_lang = (int)Configuration::get('PS_LANG_DEFAULT');
					Context::getContext()->language = new Language($cookie->id_lang);
			}

			$iso = Language::getIsoById((int)$cookie->id_lang);
			@include_once(_PS_THEME_DIR_.'lang/'.$iso.'.php');

			return $iso;
	}

	    /**
     * Set cookie id_lang
     */
    public static function switchLanguage(Context $context = null)
    {
				parent::switchLanguage($context);
				
				if ( !( ($iso = Tools::getValue('isolang')) && Validate::isLanguageIsoCode($iso) && ($id_lang = (int)Language::getIdByIso($iso)) ) ){
					$_GET['id_lang'] = Configuration::get('PS_LANG_DEFAULT');
				}else{
					$_GET['id_lang'] = $id_lang;
				}
    }

}

 

Edited by gpisw (see edit history)
Link to comment
Share on other sites

Hi gpiswI have the same problem in my prestashop, and I need to remove the directory of the main language of the web to avoid an extra level of URL depth and improve SEO, someone knows something about how to do it? Any Help?

Link to comment
Share on other sites

  • 1 year later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...