Creating a New dictionary for my Kindle (Spanish-Traditional Chinese)

Victor Fernandez
6 min readMay 31, 2022

--

Photo by Tamara Menzi on Unsplash

The problem:

A Chinese speaker friend who speaks Spanish is reading a Spanish book on her kindle, and she whats to be able to hold over a word and access a Spanish-traditional Chinese dictionary. However, I couldn't find such a dictionary for her.

The Solution:

Create our dictionary and upload it to this particular kindle directly.

The Implementation:

I will use an existing dictionary as a source file. With a mixture of a project called pyGlosassary, some modification of the source code, and Kindle preview 3, I will create a compatible dictionary.

The goal will be to obtain a .mobi file representing the dictionary and is a compatible format.

The Steps:

  1. Get the dictionary source.
  2. Get the pyGlossary.
  3. Run and use pyGlosassary with the correct settings.
  4. Convert the dictionary.
  5. Modify source code.
  6. Kindle Preview 3
  7. Upload with Calibre.

1. Get the dictionary source.

There are not many options for a dictionary of Spanish-traditional Chinese, and the format of those dictionaries is not always compatible with the Kindle system.

I know the goal is to get a .mobi file, but I will need to start from a different extension.

I found some Spanish-traditional Chinese on a page called freemdict.com. These dictionaries are in .mdx and .mdd format.

Dictionary source code from freemdic.com

2. Get the pyGlossary.

I have the dictionary, but it is in a format that the Kindle won’t be able to read. So I need to convert this file to a supported extension. For this purpose, I will use pyGlossary .

pyGlossary is a tool for converting dictionary files a.k.a glossaries. Mainly to help use our offline glossaries in any Open Source dictionary we like on any modern operating system/device. — PyGlossary Github Description.

pyGlossary Github Repository

3. Run and use pyGlosassary with the correct settings.

pyGlossary will run in most of the Operative systems, Mac, Linux, and Windows, the only requirement is to have Python installed in version 3.8 or higher.

The authors of that repository provide a detailed description of how to install pyGlossary.

Here a summary

Installed on windows

First, let’s make sure I have python.

youtube has an incredible amount of tutorials on how to install python so I won't mentioned here

Check if Python is installed

I can get pyGlossary from GitHub or just use the pip package manager for python to obtain it.

I will check if pip is installed

Check if pip is installed

If python is installed and `pip` is in the system I can proceed to get pyGlossary, like this

pip install --upgrade pyglossary

It is important to run the terminal as an administrator to avoid any permission issues.

To launch by pyglossary, I can use

pyglossary

⚠️WAIT! I need to make use of some options first. According to the documentation pyglossary have two modes, direct and indirect if I want to generate a:

I need to run pyglossary in indirect mode, for that, I need to use the flag --indirect, so I need to modify the command as follows:

pyglossary --indirect

Indirect mode means the input glossary is completely read and loaded into RAM, then converted into the output format.

Launching pyglossary on cmd

pyglossary use different graphical components. In some cases, those components won’t be present in the OS. However, since pyglossary support several of them it won’t be a problem. This explains the error in the screenshot above.

Here is how pyglossaryto look in windows.

pyglossary UI using (Tkinter)

4. Convert the dictionary

Now I can proceed to convert the dictionary.

  1. select the dictionary file. PyGlossary in some cases will select the input format, most of the time this will be correct but is a good idea to double-check.
Select input file format

2. select the output format. in this case .mobi and select the location where to receive the new file.

Select .mobi format

Once the source is defined and the output file selected, I can proceed to use convert.

3. I’m running into some errors. However, the file I need was created.

What I’m looking for is to get content.opf file. In my case, it will be located on

C:\\Users\\Victo\\Desktop\\diccionario_espanol_chino\\OEBPS
Convert file generate the .opf file

5. Modify source code.

If I try to import this generated file to the kindle preview 3, I will have some message error related to the target language or the base language, which is due to the error in the previous step.

The error can be solved by modifying some parameters in the source code on thecontent.opffile.

Using sublime text ( or any enriched text editor) I can modify thecontent.opf files to add the required information.

Content. opf source code

The tag <dc:Language></dc:Language> holds the information for the direct or main language, in this case, is a dictionary Spanish to Chinese, so the language will be Spanish, so I use es to fill this tag

<dc:Language>es</dc:Language>

The following two tags represent:

  • In language: <DictionaryInLanguage></DictionaryInLanguage>
  • out language: <DictionaryOutLanguage></DictionaryOutLanguage>

The dictionary is Spanish to Chinese so the in language will be Spanish and the out language will be Chinese.

<DictionaryInLanguage>es</DictionaryInLanguage> <DictionaryOutLanguage>zh</DictionaryOutLanguage>
content.opf modified

6. Kindle Preview 3

This software will allow me to check if the dictionary was created correctly.

Kindle preview 3 can be downloaded here

Kindle Preview

On Kindle previewer 3 I can preview the dictionary by uploading thecontent.opf file.

Kindle preview 3 export function.

Once the Dictionary is loaded, I will use the export functions to get the .mobi file.

Export to .mobi

7. Upload with Calibre.

Here is a disclaimer, I m using open source free dictionaries therefore I doubt there is any legal consequence but it is better to check for any license, mention, or acknowledge required by the license which the source material is under.

Once the .mobi is created, caliber-ebook can be used to upload the dictionary to the kindle.

upload the dictionary

Here is how it looks on the kindle.

My old Kindle uses the dictionary.

Here is another example.

My Friend’s new kindle using the dictionary.

Final Thoughts

  1. There must be a better way to get a dictionary, but I wasn’t able to find a Spanish to traditional Chinese dictionary, all the dictionaries available are in Spanish to simplified Chinese.
  2. I tried to stay with the open-source and free-to-use resources, however, amazon rules are not clear on the usage of these customed made dictionaries.

Victor Fernandez

--

--

Victor Fernandez
Victor Fernandez

I’m Victor, I’m a Field Application Engineer for a CCTV manufacturer. I love Raspberry Pi, Python, and Microcontrollers and I write about my personal projects.

No responses yet