Boost Your SEO With Translated Image File Names

Boost Your SEO With Translated Image File Names

If you have a website with images, you know that it’s very important to give them descriptive and relevant file names. This helps search engines understand the content of the images and can give your website a boost in the search rankings.

But if you have a multilingual website, it's not enough to just use descriptive file names in one language. You also need to translate the file names into the other languages used on your site.

Why is this so important? When someone searches for an image online using a specific language, the search engine will look for images with file names in that language. If your image file names are only in one language, they may not show up in the search results for users searching in a different language. This means that you could be missing out on potential traffic and website visitors.

So, how can you make sure that your image file names are properly translated for SEO purposes?

One way is to use a program like Qabiria's Image File Translator. This program makes it super easy to translate and rename your image files. Just select the source and target languages, and Qabiria's Image File Translator does the rest. It's a huge time-saver and helps you get the most out of your multilingual website.

This program is one of my first attempts at programming, so be warned. :)

It's a very simple Python script that performs the following tasks:

  1. It imports several modules: shutil, os, pyinputplus, pathlib, and googletrans. shutil is used to copy files, os provides functions for interacting with the operating system, pyinputplus is a module for creating interactive prompts, pathlib is used for working with file paths, and googletrans is used for translation.

  2. It initializes a Translator object from the googletrans module. This object will be used to perform translations later in the script.

  3. It defines a list of language codes, langs, representing the languages that the user can choose from.

  4. It prompts the user to select the source language using a menu of the languages in langs.

  5. It removes the selected source language from the list of languages, so that the user cannot select it as the target language.

  6. It prompts the user to select the target language using a menu of the remaining languages in langs.

  7. It prompts the user to input the path of the main folder using pyinputplus.inputFilepath(). This function checks that the path exists before accepting it.

  8. It checks if the directory specified by the user is empty. If it is, it prints a message to that effect and the script ends.

  9. It changes the current working directory to the user-specified directory using os.chdir().

  10. It iterates over the files in the directory and its subdirectories using os.walk(). For each file, it checks whether it is an image file with a suffix indicating the source language. If it is, it extracts the name of the file (excluding the suffix and the language code) and translates it using the Translator object. It then assembles the translated name with the correct suffix and language code to create the target file name.

  11. It creates the full path of the target file by combining the current directory and the target file name.

  12. It checks if a file with the same name as the target file already exists in the current directory. If it does not, it copies the file using shutil.copy() and prints a message indicating that it has been copied. If the file does exist, it prints a message indicating that the file already exists.

  13. Finally, it keeps track of the number of files that have been translated and prints this number when the loop is finished.

Download this program from Github: https://github.com/marcocevoli/image-file-translator