Translate & Adapt - Change Language Flag Icon

Translate & Adapt - Change Language Flag Icon

Glow_Up_Fits
Excursionist
35 5 3

Using Translate & Adapt, how can I change the flag icon for each of language available in the header dropdown on my site? I'm using the Ella 6.1.2 template. Thanks.

Reply 1 (1)

DaisyVo
Shopify Partner
2769 331 383

Hi @Glow_Up_Fits 

Okay, you're looking to customize the language flag icons in your Shopify store's header, specifically when using the Translate & Adapt app with the Ella 6.1.2 theme. I’ve dealt with similar customization requests before, and here’s how I’d approach it:

Understanding the Challenge

The Translate & Adapt app usually relies on your theme's built-in language selector. This means the flag icons are controlled by your theme's code, not the app itself. Therefore, you'll need to edit your theme's code to change the icons.

1-Locating the Language Selector Code

First, you need to find where the language selector is coded within your theme. I've found that in most Shopify themes, this is usually within the header.liquid file (located in the Sections folder). However, in some themes, it could be in a different file or even a snippet.

  • Accessing the Code: In your Shopify admin, go to Online Store > Themes. Click the three dots next to your current theme (Ella 6.1.2 in your case) and select Edit Code.
  • Finding the Right File: Look for header.liquid in the Sections folder. If it's not there, check for a file that seems related to the header or navigation in either the Sections or Snippets folder. Sometimes, the language selector is in a snippet that’s included in the header.

2-Identifying the Flag Icons

Once you've found the correct file, search for the code that displays the flag icons. This is usually done with <img> tags. You'll likely see something like this:

 

<img src="{{ 'flag-en.png' | asset_url }}" alt="English">

 

Or, it might use a more dynamic approach using language codes:

 

<img src="{{ 'flag-' | append: locale.iso_code | append: '.png' | asset_url }}" alt="{{ locale.name }}">

 

This code snippet uses the locale.iso_code to dynamically generate the flag image filename (e.g., flag-en.png, flag-fr.png).

3-Replacing the Flag Icons

Now for the main part: replacing the icons. Here are a couple of ways to do this:

  • Replacing the Image Files (Simplest but less flexible): The easiest method is to replace the actual image files used by your theme. If your theme uses files named like flag-en.png, flag-fr.png, etc., you can upload your own flag images with the same names to your theme's Assets folder. This will directly change the icons displayed. However, this method can become tedious if you have many languages.

  • Using CSS and Background Images (More flexible): A more flexible approach is to use CSS and background images. This way, you can keep your own image filenames and control the icons with CSS classes.

    • Upload Your Icons: First, upload your custom flag icons to your theme's Assets folder.
    • Add CSS: Then, add some CSS to your theme.scss.liquid file (in the Assets folder). This CSS will target the language selector elements and set background images for each language. For example:


.language-selector .en {

  background-image: url("YOUR_ENGLISH_FLAG_URL");

}

.language-selector .fr {

  background-image: url("YOUR_FRENCH_FLAG_URL");

}

/* Add more styles for other languages */

  •  Remember to replace YOUR_ENGLISH_FLAG_URL and YOUR_FRENCH_FLAG_URL with the actual URLs of your uploaded flag icons. You'll also need to add appropriate classes (like .en, .fr) to the corresponding elements in your header.liquid file.

A Word of Caution: Since you're using a specific theme (Ella 6.1.2), the exact code might be structured slightly differently. You might need to inspect the HTML of your store's header using your browser's developer tools to pinpoint the correct elements to target with CSS.

I've found that using CSS gives you the most control and keeps things organized, especially when dealing with multiple languages. It also prevents you from having to rename files, which can be a hassle.

If you need any other assistance, I am willing to help.

Best regards,

Daisy.



Please let us know if our reply is helpful by giving it a Like or marking it as a Solution!

Avada SEO & Image Optimizer - The #1 SEO solution