Implement language dropdown with country flag
« on: February 26, 2024, 06:00:34 PM »
If you want to have a dropdown menu with a button, you can insert it into any theme.
It works very well in Sigma.

header.php

Code: [Select]
<div class="dropdown" style="float:right;">
  <img src='/ubersetzen.png'>
  <div class="dropdown-content">
     <?php if ( osc_count_web_enabled_locales() > 1) { ?>
        <div class="language" >
          <?php osc_goto_first_locale(); ?>
          <?php while ( osc_has_web_enabled_locales() ) { ?>
            <a class="lnk lang <?php if (osc_locale_code() == $current_locale['pk_c_code']) { ?>active<?php ?>" href="<?php echo osc_change_language_url(osc_locale_code()); ?>"><img class="img" align="middle" src="<?php echo osc_current_web_theme_url();?>languages/<?php echo strtolower(substr(osc_locale_code(), 3)); ?>.png" alt="<?php _e('Country flag''sigma');?>"/>&nbsp;<span><?php echo osc_locale_name(); ?>&#x200E;</span></a>
          <?php ?>
        </div>
      <?php ?>
    </div>
  </div> 


Code: [Select]
<style>
.dropbtn {
  background-color: steelblue;
  color: white;
  padding: 16px;
  font-size: 16px;
  border: none;
  cursor: pointer;
}

.dropdown {
  position: fixed;
  display: inline-block;
  right: 3px;
  top:   3;
  z-index: 99;
  bottom: 320px;
 
}

.dropdown-content {
  display: none;
  position: absolute;
  right: 0;
  background-color: orangered;
  min-width: 160px;
  box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
  z-index: 1;
  opacity: 0.9;
}

.dropdown-content a {
  color: black;
  padding: 12px 16px;
  text-decoration: none;
  display: block;
}

.dropdown-content a:hover {background-color: #f1f1f1;}
.dropdown:hover .dropdown-content {display: block;}
.dropdown:hover .dropbtn {background-color: #3e8e41;}
           
                       
</style>

<style>
      .img {
      width: 20px;
      height: 20px;
      display: inline;vertical-align: middle;
      justify-content: center;
      align-items: center;
      }
    </style>


Save flags as png in language in your theme







*

kriskoyk

  • *****
  • 285 posts
Re: Implement language dropdown with country flag
« Reply #1 on: February 27, 2024, 09:54:14 AM »
Has the code been tested on other topics? For me in beta it creates a problem in displaying object photos

Also, how can I make it appear in the menu bar before the "Log in" button?
« Last Edit: February 27, 2024, 09:59:21 AM by kriskoyk »

Re: Implement language dropdown with country flag
« Reply #2 on: February 27, 2024, 11:23:05 AM »

It has also been tested in OsclassWizards Theme and works great.



Place this image in your main Osclass folder.






in the menu bar it hasn't been tested yet.


Put the flags in your theme folder in languages. 

names of the flags

German de.png

Englisch us.png

And so forth.

*

kriskoyk

  • *****
  • 285 posts
Re: Implement language dropdown with country flag
« Reply #3 on: February 27, 2024, 11:28:12 AM »
OK thanks.

Re: Implement language dropdown with country flag
« Reply #4 on: February 27, 2024, 12:32:36 PM »
I hope it works for you now too.

*

kriskoyk

  • *****
  • 285 posts
Re: Implement language dropdown with country flag
« Reply #5 on: February 27, 2024, 12:45:17 PM »
It causes problem in displaying item image in beta theme

*

kriskoyk

  • *****
  • 285 posts
Re: Implement language dropdown with country flag
« Reply #6 on: February 27, 2024, 02:43:51 PM »
I want to try it in the menu bar. How to do it?

Re: Implement language dropdown with country flag
« Reply #7 on: February 27, 2024, 03:41:33 PM »
Try this as food for thought? Of course you have to adjust all of this.

Code: [Select]
<div class="navbar">
  <div class="dropdown">
    <button class="dropbtn">Dropdown
      <i class="fa fa-caret-down"></i>
    </button>
    <div class="dropdown-content">
      <?php if ( osc_count_web_enabled_locales() > 1) { ?>
        <div class="language" >
          <?php osc_goto_first_locale(); ?>
          <?php while ( osc_has_web_enabled_locales() ) { ?>
            <a class="lnk lang <?php if (osc_locale_code() == $current_locale['pk_c_code']) { ?>active<?php ?>" href="<?php echo osc_change_language_url(osc_locale_code()); ?>"><img class="img" align="middle" src="<?php echo osc_current_web_theme_url();?>languages/<?php echo strtolower(substr(osc_locale_code(), 3)); ?>.png" alt="<?php _e('Country flag''sigma');?>"/>&nbsp;<span><?php echo osc_locale_name(); ?>&#x200E;</span></a>
          <?php ?>
        </div>
      <?php ?>
    </div>
     
    </div>
  </div>
</div>



CSS

Code: [Select]
<style>
body {
  font-family: Arial, Helvetica, sans-serif;
}

.navbar {
  overflow: hidden;
  background-color: #333;
}

.navbar a {
  float: left;
  font-size: 16px;
  color: white;
  text-align: center;
  padding: 14px 16px;
  text-decoration: none;
}

.dropdown {
  float: left;
  overflow: hidden;
}

.dropdown .dropbtn {
  font-size: 16px; 
  border: none;
  outline: none;
  color: white;
  padding: 14px 16px;
  background-color: inherit;
  font-family: inherit;
  margin: 0;
}

.navbar a:hover, .dropdown:hover .dropbtn {
  background-color: red;
}

.dropdown-content {
  display: none;
  position: absolute;
  background-color: #f9f9f9;
  min-width: 160px;
  box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
  z-index: 1;
}

.dropdown-content a {
  float: none;
  color: black;
  padding: 12px 16px;
  text-decoration: none;
  display: block;
  text-align: left;
}

.dropdown-content a:hover {
  background-color: #ddd;
}

.dropdown:hover .dropdown-content {
  display: block;
}
</style>
« Last Edit: February 27, 2024, 03:54:08 PM by Roberto Klapper »

*

kriskoyk

  • *****
  • 285 posts
Re: Implement language dropdown with country flag
« Reply #8 on: February 27, 2024, 06:05:31 PM »
Thank you very much.
    This is the configuration I did and it works great!

Code: [Select]
<div class="navbar">
  <div class="dropdown">
    <button class="dropbtn"><?php _e('lang''beta');?>
      <i class="fa fa-caret-down"></i>
    </button></br></br>
    <div class="dropdown-content">
      <?php if ( osc_count_web_enabled_locales() > 1) { ?>
        <div class="language" >
          <?php osc_goto_first_locale(); ?>
          <?php while ( osc_has_web_enabled_locales() ) { ?>
            <a class="lnk lang <?php if (osc_locale_code() == $current_locale['pk_c_code']) { ?>active<?php ?>" href="<?php echo osc_change_language_url(osc_locale_code()); ?>"><img src="<?php echo osc_current_web_theme_url();?>images/country_flags/<?php echo strtolower(substr(osc_locale_code(), 3)); ?>.png" alt="<?php _e('Country flag''beta');?>" />&nbsp;<span><?php echo osc_locale_name(); ?></span></a>
          <?php ?>
        </div>
      <?php ?>
    </div>
     
    </div>
  </div>
</div>
<style>
body {
  font-family: Arial, Helvetica, sans-serif;
}

.navbar {
  overflow: hidden;
  background-color: #fff;
}

.navbar a {
  float: left;
  font-size: 16px;
  color: white;
  text-align: center;
  padding: 14px 16px;
  text-decoration: none;
}

.dropdown {
  float: left;
  overflow: hidden;
}

.dropdown .dropbtn {
  font-size: 16px;
  border: none;
  outline: none;
  color: black;
  padding: 14px 16px;
  background-color: inherit;
  font-family: inherit;
  margin: 0;
}

.navbar a:hover, .dropdown:hover .dropbtn {
  background-color: red;
}

.dropdown-content {
  display: none;
  position: absolute;
  background-color: #f9f9f9;
  min-width: 160px;
  box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
  z-index: 1;
}

.dropdown-content a {
  float: none;
  color: black;
  padding: 12px 16px;
  text-decoration: none;
  display: block;
  text-align: left;
}

.dropdown-content a:hover {
  background-color: #ddd;
}

.dropdown:hover .dropdown-content {
  display: block;
}
</style>

Re: Implement language dropdown with country flag
« Reply #9 on: March 05, 2024, 04:11:34 PM »

I am very pleased to hear this.

*

kriskoyk

  • *****
  • 285 posts
Re: Implement language dropdown with country flag
« Reply #10 on: March 05, 2024, 04:17:41 PM »
Now I have added the corresponding flag instead of "Lang". See here how it works:  https://www.test0.gr/

Re: Implement language dropdown with country flag
« Reply #11 on: March 05, 2024, 04:26:01 PM »
You did it very well.

*

kriskoyk

  • *****
  • 285 posts
Re: Implement language dropdown with country flag
« Reply #12 on: March 05, 2024, 04:32:08 PM »
What version of OSCLASS are you using?

Re: Implement language dropdown with country flag
« Reply #13 on: March 06, 2024, 11:30:10 AM »
Version 8.2.1