blog/blogs/2022/5/14/bilingual-computing.md

4.5 KiB

Bilingual Computing

For the last few years, I've been trying to learn French, so that I can live in France. I used to speak the language as a child when I lived in Paris, but that was nearly 20 years ago, so I've forgotten a lot of the it. As well as langauges, I have a healthy interest in computing, online communication and free and open source software. I'm adamant about independence in computing, and minimising my dependencies on services provided as products.

In this post I'd like to talk about a little bit about a few additions and customisations I've made to my Linux environment to support learning and using multiple written languages.

Translation Commands

The first and most obvious thing I wanted was a quick and dirty translator. For me, this means being able to open a terminal, hammer in a command and a query, and get a result back. I am not too concerned about the accuracy of the translator, or translating large amounts of text. So long as it helps me most of the time with a word or phrase, and so long as it's quicker and easier than picking up my phone, it's good enough.

I found argos-translate, which provides open-source offline translation. The user downloads translation dictionaries as packages and can then be used to translate strings of text, either individual words or entire phrases.

Here's my script for translating a phrase in French to English, which I have saved as en:

#!/usr/bin/env bash

# fully expand arguments
phrase=$@

argos-translate --from-lang fr --to-lang en "$phrase"

Note that arguments passed into the script are expanded before being passed as a single string to the translation command. That means that I am able to pass arguments without turning them into a literal string, which is nice. Without wrapping it in quotes, however, characters such as apostrophes must be explicitly escaped.

en j\'aime bien les pingouins, ils s\'y connaissent en informatique

Keyboard Layouts

Now that I had a way to do quick translations, the next obvious limitation was my keyboard layout. In casual conversation I've often copy-pasted, made do with using multiple characters ('e, e`) to resemble diacritics, or just omitted them entirely and trusted the other party to understand. This would be unacceptable for any longer-form writing, such as blog posts.

Being a life-long QWERTY user, I was not enthralled by QWERTZ, AZERTY or any other standard European layout that would throw off my existing muscle memory. Thankfully QWERTY-fr exists! I haven't used an accented keyboard before, but I like how it is designed spatially. It reminds me of vim's design, where the position of the key is more important than what is written upon it.

After installing the additional layout, I wrote a script kbfr to enable it with setxkbmap. I also included some other layout modifications which turn Caps Lock into Ctrl and Esc using xcape, and ensure they are run when I set the keyboard layout:

#!/usr/bin/env bash

# while caps lock is held down, it applies a ctrl modifier to other keys
setxkbmap -option caps:ctrl_modifier

# when caps lock is pressed or released, it acts as esc
xcape -e 'Caps_Lock=Escape'

# enable the QWERTY-fr layout
setxkbmap -v -layout us_qwerty-fr

I also enabled the xkeyboard module for polybar, so that I could see at a glance which layout I have enabled.

A Dictionary

Finally, I wanted a more complete dictionary than my simple translator scripts. This is mostly to help me learn the grammatical gender of words, which my translator scripts are only partially able to help with. It's also good practice to figure out the meanings of words when I have only other words of the same language available to help!

I found the open StarDict dictionary, which has a command-line version, sdvc.

I installed a French dictionary for it with the AUR package stardict-acadfr1935, and since this is the only dictionary I have installed, usage is quite simple - I wrapped it in a mot script:

#!/usr/bin/env bash

# get the meaning of a french word
sdcv -c -n $1

This is something I'm not quite happy with yet, but it will do for now. The dictionary could include more up-to-date definitions, and the output is often quite verbose. The ArchWiki page does describe some suggested usages, which maybe I will look at in the future.


Thanks to my Quebecois friend Vorty for helping me with my terrible language skills, both English and French.