Jump to content

[Solved] Change flag position on language selector block


superskyman100

Recommended Posts

Hello,

I'm using prestashop 1.7.5.1

I already made lots of translations with my shop, but i finally had to add one language (australian). 

Problem is that i'd like to reorganize the flags order in the frontend (i'd like the australian language to be just below the english language), and there is no solution througout backend (except erasing all, and re-create in good order id., which would ruin all my previous  translations works).

Any simple idea ?

Thanks

 

 

 

Flagsproblem.jpg

id-langues.jpg

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

Hi there,

The language table doesn't support the position field. So, you cannot change the language position from your back office. In your case, you can override function getLanguages of class Language (Language.php) , sort (change) position of the language in this array.

Thanks,

Quang

Link to comment
Share on other sites

Sorry i understand absolutely nothing......

 

some guys told me to modify this section in ps_languageselector.php

 

 foreach ($languages as &$lang) {
            $lang['name_simple'] = $this->getNameSimple($lang['name']);
        } 

and ordering the languages here by id......

But NO IDEA how i should do that i know nothing about programming

 

 

 

Link to comment
Share on other sites

Hi,

Like in the prev message, you need to override function getLanguages in the class Language (Language.php) and put it in the folder: public_html/override/classes/Language.php. Please let me know your PS version. I will help you to create the file override.

Thanks,

Quang

Link to comment
Share on other sites

Thanks a lot Prestamonster for your help,

my PS is 1.7.5.1

in my point of view this sounds  really complicated... for instance i also have (the search is still on) 2 language.php files (at least) in my prestashop (inside the symphony folder)... 

Honestly i only need to change the language position in the language block on the front end, and nothing else... this is just for design / coherency purpose

Wouldn't it be simplier (and less risky) to make some little modifs in the ps_languageselector.php ??

 

 

 

Link to comment
Share on other sites

In case i just wanna the simple solution in ps_languageselector.php, should i code like that ?????.....

 

foreach ($languages as &$lang) {

$lang['name_simple'] = $this->getNameSimple($lang['name']);
$lang_en = array();
$lang_au = array();
$lang_other = array();

}

 

honestly i'm completey dumb about programming, i can just understand the general logics.....

 

 

 

Link to comment
Share on other sites

Hi there,

There are 2 ways:

1.  override function  getWidgetVariables() in the file ps_languageselector.php of module ps_languageselector

public function getWidgetVariables($hookName = null, array $configuration = [])
    {
        $languages = Language::getLanguages(true, $this->context->shop->id);
        $lang_en = array();
        $lang_au = array();
        $lang_other = array();
        foreach ($languages as &$lang) {
            $lang['name_simple'] = $this->getNameSimple($lang['name']);
            if ($language['iso_code'] == 'en') {
                $lang_en[] = $lang;
            } else if ($language['iso_code'] == 'gb') {
                 $lang_au[] = $lang;
            } else {
                $lang_other[] = $lang;
            }
        }
        $languages = array_merge($lang_en, $lang_au, $lang_other);

        return array(
            'languages' => $languages,
            'current_language' => array(
                'id_lang' => $this->context->language->id,
                'name' => $this->context->language->name,
                'name_simple' => $this->getNameSimple($this->context->language->name)
            )
        );
    }

2. Override function getLanguages of class getLanguage

unzip file attachment >> upload (via ftp, or cpanel) >> put it in public_html/override/classes/

For case 1: this code will be overriden if you upgrade module.

For case 2: It works fine in the case upgrade PS

Thanks,

Language.zip

  • Thanks 1
Link to comment
Share on other sites

  • 6 months 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...