Jump to content

Flag icons


Daffuzz

Recommended Posts

  • 1 month later...
  • 2 weeks later...
On 2017.10.31. at 2:36 PM, horiatb said:

In your theme:

themes/classic/modules/ps_languageselector replace the content of ps_languageselector.tpl with this:


{**
 * 2007-2017 PrestaShop
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License 3.0 (AFL-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:
 * https://opensource.org/licenses/AFL-3.0
 * 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 license@prestashop.com 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 <contact@prestashop.com>
 * @copyright 2007-2017 PrestaShop SA
 * @license   https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
 * International Registered Trademark & Property of PrestaShop SA
 *}
<div id="_desktop_language_selector">
  <div class="language-selector-wrapper">
    <span id="language-selector-label" class="hidden-md-up">{l s='Language:' d='Shop.Theme.Global'}</span>
    <div class="language-selector dropdown js-dropdown">
      <button data-toggle="dropdown" class="hidden-sm-down btn-unstyle" aria-haspopup="true" aria-expanded="false" aria-label="{l s='Language dropdown' d='Shop.Theme.Global'}">
        <span class="expand-more">{$current_language.name_simple}</span>
        <i class="material-icons expand-more"></i>
      </button>
      <ul class="dropdown-menu hidden-sm-down" aria-labelledby="language-selector-label">
        {foreach from=$languages item=language}
          <li {if $language.id_lang == $current_language.id_lang} class="current" {/if}>
            <a href="{url entity='language' id=$language.id_lang}" class="dropdown-item"><img class="lang-flag" src="{$urls.img_lang_url}{$language.id_lang}.jpg"/>{$language.name_simple}</a>
          </li>
        {/foreach}
      </ul>
      <select class="link hidden-md-up" aria-labelledby="language-selector-label">
        {foreach from=$languages item=language}
          <option value="{url entity='language' id=$language.id_lang}"{if $language.id_lang == $current_language.id_lang} selected="selected"{/if}>{$language.name_simple}</option>
        {/foreach}
      </select>
    </div>
  </div>
</div>

It should work, but you need to have the flag images for each language uploaded.

I dont now, but for me not working.

Link to comment
Share on other sites

  • 4 months later...
hace 20 minutos, ndiaga dijo:

You shoud use /img/l/  instead.

Here is how it works :  http://prestatuts.com/tutorials/prestashop-1-7-display-language-flags/ 

According to your instruction manual you place the route manually. Attachment Capture

omoa.thumb.jpg.98803c37034139027836388d9003de0a.jpg

 

I have a tutorial in Spanish of 2017 ((April 9, 2017) about the language flags in Prestashop 1.7 published on my blog and it is better to use the global variable, to refer to the directory

 

{$urls.img_lang_url}

 

Sorry for my English

Link to comment
Share on other sites

hace 3 minutos, ndiaga dijo:

Hi, thanks for the suggestion.

But that url can cause trouble in multilangual environment.

So I decided to put hard code the URL since   it will be the same in all  shops.

And  


{$urls.img_lang_url} = /img/l/ 

So what is the point?

 

I think In my personal opinion it is always better to use the global variables available to make use of the "established" routes, if it is a different (new) route than usual then if it makes sense, but if it is the same route, I think it is better to use the global variable, which already automatically references the /img/l/ directory, placing only {$urls.img_lang_url}

If it causes problems in multilanguage, then it is better to fix the problem in the origin.

Sorry for my English

Link to comment
Share on other sites

hace 1 hora, ndiaga dijo:

Why use a variable if you know that the variable is just  displaying this string :  '/img/l/'   ?

If you put in smarty  {$urls.img_lang_url} you will see the path '/img/l/'  .

The variable is just a convention to make life easy and avoid memorisations. But me I know where the flags are stored, so I just call that folder.

If it was shop url for example {$base_dir}  , yes I would use the variable because that varible displays  the shop's  URL not an existing folder that will never change.

In PrestaShop 1.6  you have this variable  {$img_lang_url}  and in PrestaShop 1.7 you have {$urls.img_lang_url}  so you see?  

They both call  '/img/l/' .  To avaoid confusion to the users,  I just call that folder.

Some   1.6 users  could read that tutorial  too. 

I understand you perfectly, but the code should be as clean as possible.

But I prefer to use the variables before placing the route manually.
Although it prints the same value, by organization and clean code it is better to use variables.


Neither are we going to fight. hehehe
5aa6b21239704_GifPeleadeInternet-memes3.gif.7aa2edf451f200e01c9648ee2fb880db.gif

Sorry for my english,

@ndiaga If you want I delete my messages (logically, I leave your answer without deleting).

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

16 hours ago, ndiaga said:

Ok, it's best practice to use a variable.

You win the game.

Thanks for your suggestion.

Don't delete any comment leave the user to decide what to do.

I will be even glad to see you comment in my blog :  http://prestatuts.com/tutorials/prestashop-1-7-display-language-flags/

I try your sugestions, but for me not working, when I change code, fronty page looks like this and language selector don't work:

TTT.jpg

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

  • 1 year later...
  • 4 weeks later...
On 11/11/2019 at 11:59 AM, Yankee Store said:

Hello

I am using Prestahop 1.7.6 
I am looking to sort the language  in the Languageselector drop down menu by the Language Name in asc order .
can someone help me how to code that ?

 



Thank You

я создал в таблице ps_lang колонку mysort
ALTER TABLE `ps_lang` ADD `mysort` INT NOT NULL AFTER `is_rtl`;

и проставил значения нужной мне сортировки

UPDATE `webpcstudio`.`ps_lang` SET `mysort` = '1200' WHERE `ps_lang`.`id_lang` = 15;

UPDATE `webpcstudio`.`ps_lang` SET `mysort` = '1300' WHERE `ps_lang`.`id_lang` = 13;

...

 

+ override:


/override/classes/Language.php 

<?php
class Language extends LanguageCore
{
    public static function loadLanguages()
    {
        self::$_LANGUAGES = array();

        $sql = 'SELECT l.*, ls.`id_shop`
                FROM `' . _DB_PREFIX_ . 'lang` l
                LEFT JOIN `' . _DB_PREFIX_ . 'lang_shop` ls ON (l.id_lang = ls.id_lang) order by l.`mysort`';

        $result = Db::getInstance()->executeS($sql);

        foreach ($result as $row) {
            $idLang = (int) $row['id_lang'];

            if (!isset(self::$_LANGUAGES[$idLang])) {
                self::$_LANGUAGES[$idLang] = $row;
            }
            self::$_LANGUAGES[$idLang]['shops'][(int) $row['id_shop']] = true;
        }
    }
}

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...