HOWTO Let Nemo Indicate Your Current Language on the Desktop

  8 years ago

The idea behind

If you’re already seeking help on the Linux Mint community website, including the forums, you’re likely to use (at least) two languages: English and your mother tongue, unless both are the same wink. You might also have noticed that the advices there can be re-enacted easier, if the interface of Linux Mint is set to English for this purpose. The interface language can be switched either at login, or within a running session with System Settings› Preferences› Languages (Settings)› (Interface) Language. In the latter case though, you’ll have to quit your session and login again anyway.

OK, it isn’t as smooth as on a smartphone this way, but it’s smart enough to switch your applications, the spell checker(s), dictionaries, and — by means of some additional scripting — any user interface which is foreign to your desktop environment like a KDE program in Cinnamon and MATE, and vice versa, or even your email signatures… If you happen to work in different language environments like I do, you’ll surely appreciate being able to switch all these things at once smiley.

In contrast, a change in the keyboard layout — which is needed when a given language uses a different scripting system — becomes effective instantaneously, and as it depends on user preferences too, there is no need to automate it. The more so as the keyboard applet can indicate the active layout by a flag in Cinnamon’s panel (if configured properly). Then, the ice on the cake of internationalization would be if the session’s current language could be caught at a glance, in the same manner — with a visually appealing flag on the desktop, or more precisely with the correct flag representing your home folder. For instance, the five most widely spoken foreign languages in Europe could be associated with the following flags:

5 most spoken foreign languages


Show your colors

Step 1: Choose your preferred language

This one is as easy as to right click on the Home folder of the desktop, and to set (Home) Properties› Select Custom Icon (by clicking)› to the corresponding flag from a folder named /usr/share/cinnamon/applets/ (at this point, we don’t need to bother about the fact that the flag actually represents the country where your language’s name comes from, rather than that language itself).

Let’s do this with Esperanto as an example, because it’s the only true language flag in the list which, in addition, looks a bit minty cheeky. So judge by yourself:

Esperanto home folder

Step 2: Set up a little script

In order to let your Linux Mint choose the flag auto-magically, you’ll need a script that can be created with the following sequence of terminal commands (copy’n paste is your friend):

…$ mkdir -p ~/bin
…$ touch ~/bin/myhome
…$ chmod +x ~/bin/myhome
…$ gedit ~/bin/myhome

As soon as the last command is entered, the Text Editor will show up, and you’ll simply have to put in the following contents and to save the file:

# ~/bin/myhome (MagicMint) O0711, +O0808
# Change Nemo’s home icon to a country flag
# (ɔ) GPL-2, see /usr/share/common-licenses/GPL-2

COUNTRY_CODE=${1:-`echo $LANG | head -c2`}

help_msg() {
  cat <<-EOF
  `awk  'FNR==3 {print gensub("# ", "", 1)}' "$0"`
  Usage: `basename "$0"` [option]
    ctry:2   to override the system language
    --default   to set the default language
    --special lang:2 ctry:2   to set a special flag for a language
      e.g.: `basename "$0"` --special zh cn   for Chinese
      (Such a command can be used only ONCE!)
    --help | -h   to display this message  

  -h | --help )
    help_msg ;;

  # Set the default in this command file from the metafile
  --default )
    COUNTRY_CODE=$(basename `awk -F= '/flags/{print $2}' $METAFILE` | cut -d. -f1)
    sed --in-place "s:DEF=\"$DEF\":DEF=\"$COUNTRY_CODE\":" "$0" 

  # There is no such country flag as “English”
  "en" )
    exec "$0" gb

  # When there is no appropriate country flag
  "zz" )
    exec "$0" aa
    # Set a given flag for the language above ONCE AND FOR ALL
    --special )
      if [ -z "$1" ] || [ -z "$2" ]; then
        exec "$0" --help
      elif ! locale -a | cut -d. -f1 | cut -d_ -f1 | grep -q $1; then
        echo $1: There is no such a locale installed!
      elif ! ls "$FLAGDIR" | cut -d. -f1 | grep -q $2; then
        echo $2: There is no flag for such a country!
        sed --in-place "s/zz/$1/" "$0" 
        sed --in-place "s/aa/$2/" "$0" 

  # Otherwise set the appropriate flag
  # ----------------------------------
  # The following choice is based upon the 5 most widely spoken foreign languages in Europe.
  # The flags to pick always refer to the country which the language originally comes from:
  #   English ← Great Britain (38%) = gb
  #   French  ← France        (12%) = fr
  #   German  ← Deutschland   (11%) = de
  #   Spanish ← España        ( 7%) = es
  #   Russian ← Russia        ( 5%) = ru
  *) sed --in-place "/flags/s,$DEF.png\|gb.png\|fr.png\|de.png\|es.png\|ru.png\|aa.png,$COUNTRY_CODE.png," $METAFILE

#End of script

Step 3: Add your current flag to the list

This is the goal to achieve by the two previous steps which must have been completed. It can be attained by invoking the script above from a terminal [Ctrl+Alt+T] or the command line [Alt+F2]:

…$ ~/bin/myhome --default

Step 4: Automate the process

Normally, the effect of the “myhome” command won’t be seen until the next restart of nemo. But you don’t need to cause this to happen manually, as it is much easier to integrate the command into the startup procedure of the Cinnamon session. So click on Menu› Preferences› Startup Applications, and Add (a) Startup Program. A dialog will show up, where you have to input the following task description:

 Name:    Nemo Home Flag
 Command: ~/bin/myhome
 Comment: Change Nemo’s home icon to country flag

Leave the Startup Delay at 0 seconds, save the command — and you’re done cool. The next time you want to login, you’ll have to select another language in the login screen (maybe one of the most widely spoken languages in the world below), and you’ll see the matching flag on your desktop.

10 most spoken languages


What if not ?

In half of the cases above, the flag cannot be associated directly to a given language, because there simply is no matching country, i.e. one that is named the same way. If this is the case for your foreign language — which should be the one of your current session for this, by the way —, you’ll have to get its language code with the command (except for English which is automatically corrected by the script):

…$ echo -n $LANG | head -c2 && echo

Then, you must look for a flag in the folder mentioned at the beginning. The country code you need is the name of the chosen file without the ending “.png”. You can add such a special language flag just once to the list (afterwards, you’ll have to edit the script manually for this). For example, you could define Chinese as your special language by setting its language code (zh) and its flag (cn):

…$ ~/bin/myhome --special zh cn


The Home flag looks even more impressive on the desktop if you hide the Computer icon in (System Settings›) Preferences› Desktop› Show desktop icons. That’s a useless “legacy” from Windows anyway, because on the rare occasions you’ll really need it, it can be opened from the file manager as well.

As a final thought, chances are that you won’t care about this tutorial at all if you happen to be native of one of the following countries wink:

Least foreign language speakers

MagicMint 8 years ago

@Rebel450: I’m actually cheating when editing… The timeout imposed on the login here alone constrains me to use an external editor for the HTML text. But I’m used to do this for websites anyway, so it doesn’t matter to me. I’ve recourse to the ckeditor to control the final layout merely ;-)

Hammer459 8 years ago

@MagicMint I have several qualities... PC is not one of them :-)
And I am proud Canadian!

Rebel450 8 years ago

That is what I call a tutorial:

Well organized,
easy to understand (even the issue itself is very tricky)
and very good explained

- and a big plus for the visual appearance.

If you ever made a howto with the editor given -
you will know, this one can be really a handful ...

This tutorial should be an example for others,
highly appreciated.

MagicMint 8 years ago

@Hammer459: As far as I’m concerned, I’d prefer the Maple Leaf too ;-) But the Union Jack is there for sake of political correctness — representing the “mother country” of English.

Hammer459 8 years ago

Good tutorial.
I can now set a red-and-white Maple Leaf and a blue with a yellow cross as my language flags!