88 lines
4.5 KiB
Markdown
88 lines
4.5 KiB
Markdown
|
# Bilingual Computing
|
||
|
|
||
|
For the last few years, I have been learning French, with the goal to go 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 languages, I have a healthy interest in computing, online communities, and free and open source software.
|
||
|
I am adamant about independence in computing, and minimising my dependencies on services provided as products.
|
||
|
|
||
|
In this post I would like to talk a little bit about a couple of additions and customisations I have 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: open a terminal, hammer in a command and a query, and get a result back right then and there.
|
||
|
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 easier and quicker than picking up my phone, it's good enough.
|
||
|
|
||
|
I found [argos-translate](https://github.com/argosopentech/argos-translate), an open-source offline translation library.
|
||
|
The user downloads translation dictionaries as packages, which can then be used to translate strings of text, either individual words or entire phrases.
|
||
|
|
||
|
Here is my script for translating a phrase in French to English, which I have saved as `en`:
|
||
|
|
||
|
```bash
|
||
|
#!/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 have 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 or AZERTY, or any other standard European layout that would throw off my existing muscle memory.
|
||
|
Thankfully [QWERTY-fr](https://github.com/qwerty-fr/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 layouts, 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](https://github.com/polybar/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, for which exists the `sdvc` command-line dictionary in the AUR, and I installed a French dictionary (Dictionnaire de l'Académie Française, 8ème edition (1935)).
|
||
|
Since this is the only dictionary I have installed, usage is quite simple - I wrapped it in a `mot` script:
|
||
|
|
||
|
```
|
||
|
#!/usr/bin/env bash
|
||
|
|
||
|
# trouve la signification d'un mot français
|
||
|
|
||
|
mot=$1
|
||
|
|
||
|
sdcv -c -n $mot
|
||
|
```
|
||
|
|
||
|
This is something I'm not quite happy with yet, but it will do for now.
|
||
|
The dictionary should 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.
|