MDX/MDD一键转Android版GoldenDict可用格式

整理了一个词典转换脚本,用于把 MDict/MDX 词典转换成适合 Android GoldenDict 使用的 StarDict + DSL 资源词典。

项目已上传GITHUB

本地下载:mdxtogd_v20260913.zip (26.6 KB)

建议:首先自定义 GoldenDict 的全局CSS(sdcard/GoldenDict/.config/article-style.css 和
article-style-night.css)

转化后,显示上的问题一般仅需要调整一下CSS。

脚本名称:

mdxtogd.py

配置文件:

config.txt

目前支持的输入格式包括:

MDX
Tabfile
MDict Textfile

其中 MDict Textfile 指类似下面这种格式:

词条1
内容第一行
内容第二行
</>
词条2
内容
</>

程序会先统一转成 Tabfile。正文中的实际换行会转换为字面量 \n,因此每个词条在 Tabfile 中始终只占一行,之后再继续进行资源路径替换和 StarDict 转换。

一、主要功能

1. 支持 MDX + 多个 MDD

如果输入:

词典.mdx

程序会自动寻找同目录下的:

词典.mdd
词典.1.mdd
词典.2.mdd
……

无需在配置文件中逐个填写。

MDD 中的图片、CSS、JS、字体、音频等资源会解包并重新整理,然后生成 Android GoldenDict 使用的:

词典.dsl
词典.dsl.files.zip

DSL 使用 UTF-8 with BOM。


2. 支持本地资源

有些 MDX 中引用的 CSS、图片或字体并不在 MDD 里,而是直接放在词典文件旁边,例如:

词典.mdx
mecd.css
images/
fonts/

程序也会尝试解析这些实际被引用到的本地资源,并纳入相同的资源重写流程。

CSS 内部继续引用的图片、字体等资源,也会进一步解析。


3. 资源包支持两种目录方式

配置:

resource_layout = root

表示把资源全部放到 .dsl.files.zip 根目录。

如果存在同名文件,会自动重命名,并同步修改正文/CSS/JS 中的引用。

也可以:

resource_layout = original

保留 MDD 原来的目录结构,例如:

images/a.png
css/style.css
fonts/font.woff2

对于资源特别多的词典,我个人更推荐 original,管理和排查都比较方便。


4. CSS 可以放 ZIP,也可以独立放文件夹

css_storage = zip

CSS 放入:

词典.dsl.files.zip

或者:

css_storage = folder

CSS 作为独立文件,与正式词典文件放在同一目录。


二、自动处理 Android GoldenDict 资源路径

程序会根据 DSL 在 Android GoldenDict 中的实际安装路径,计算 DSL resource ID,并把类似:

images/a.png
../fonts/font.woff2
mecd.css

改写成 Android GoldenDict 能访问的资源地址。

例如:

content://mobi.goldendict.android/resource/<DSL_ID>/images/a.png

DSL resource ID 使用 DSL 相对于 GoldenDict 根目录的路径计算。

例如:

/storage/emulated/0/GoldenDict/ENG/ENG-ZHO/词典名/词典名.dsl

实际参与计算的是:

ENG/ENG-ZHO/词典名/词典名.dsl

三、自动识别词典语言

配置文件中强烈建议填写:

INDEX_LANGUAGE =
CONTENTS_LANGUAGE =

不过写法比较宽松。

例如英语可以写:

eng
en
English
english
英语
英文
英

中文可以写:

zho
zh
chi
Chinese
中文
汉语
漢語
汉
漢
中

程序内部会统一转换成标准代码。

例如:

INDEX_LANGUAGE = 英
CONTENTS_LANGUAGE = 汉

会统一识别成:

eng → zho

DSL 中则自动生成:

#INDEX_LANGUAGE "English"
#CONTENTS_LANGUAGE "Chinese"

如果没有填写,程序还会尝试从词典文件名判断,例如:

xx英汉词典
→ eng / zho

xx汉英词典
→ zho / eng

英英词典
→ eng / eng

POR-ZH
→ por / zho

无法可靠判断时使用:

Unk / Unk

建议还是手工填写,自动判断主要作为兜底。


四、StarDict 的语言也会自动处理

这是专门针对 GoldenDict 做的一项处理。

StarDict 本身没有 DSL 那样的:

#INDEX_LANGUAGE
#CONTENTS_LANGUAGE

GoldenDict 可以根据 StarDict 文件名中的语言对判断语言。

因此,例如:

INDEX_LANGUAGE = eng
CONTENTS_LANGUAGE = zho

StarDict 自动生成:

词典名.en-zh.ifo
词典名.en-zh.idx
词典名.en-zh.dict
词典名.en-zh.dict.dz

这样 GoldenDict 可以识别为:

English → Chinese

但是 .ifo 内仍然保持:

bookname=词典名

因此词典在 GoldenDict 中显示的仍然是原来的词典名,不会显示成:

词典名.en-zh

类似地:

zho → eng
生成 .zh-en.*

eng → eng
生成 .en-en.*

fra → zho
生成 .fr-zh.*

如果某一端语言无法确定,则不会强行添加错误的语言后缀。


五、Android 目录自动生成

如果不填写:

install_dir =

程序会按照语言自动生成目录。

例如:

INDEX_LANGUAGE = eng
CONTENTS_LANGUAGE = zho

默认得到:

ENG/ENG-ZHO/词典名

最终 Android 位置类似:

/storage/emulated/0/GoldenDict/
└─ ENG/
   └─ ENG-ZHO/
      └─ 词典名/

这样词典多了以后,可以按照:

源语言
→ 语言方向
→ 具体词典

来分类。

转换完成后还会自动生成:

GoldenDict安装位置.txt

里面直接写明应该把正式词典文件复制到 Android 的哪个目录。


六、自动处理词典图标

如果 MDX/Textfile/Tabfile 同目录存在同名图片:

词典.png
词典.jpg
词典.jpeg
词典.bmp

程序会自动找到并转换为:

词典.bmp

尺寸:

48 × 64

用于 GoldenDict 词典图标。

图片会保持原始宽高比缩放,并居中到 48×64 画布,避免直接拉伸变形。

图像转换需要:

Pillow

可以安装:

python -m pip install Pillow

七、最终 Tabfile 会保留下来

程序完成各种:

entry://
图片路径
CSS路径
JS路径
字体路径
其它资源路径

替换以后,会保留:

词典名.android.txt

这是最终送入 StarDict 转换前的 Tabfile。

因此,如果转换完成后还想手工修改正文,可以直接编辑这个文件。

同时程序会生成:

makestardict.bat
_makestardict.py

修改完:

词典名.android.txt

以后直接双击:

makestardict.bat

即可重新生成 StarDict,不需要重新跑 MDX/MDD 解包和资源转换过程。

重新生成时同样会保持:

词典名.en-zh.*

这样的语言标记。


八、StarDict 的 .dict 与 .dict.dz

配置:

stardict_dictzip = true

会同时保留:

词典名.en-zh.dict
词典名.en-zh.dict.dz

如果:

stardict_dictzip = false

则只生成:

词典名.en-zh.dict

生成 .dict.dz 需要:

python -m pip install python-idzip

九、配置文件尽量简化

目前 config.txt 采用普通文本:

key = value

不使用 JSON,方便直接打开修改。

最基本可以只写:

source_file = ./词典.mdx

推荐再填写:

INDEX_LANGUAGE = eng
CONTENTS_LANGUAGE = zho

其它项目一般都有默认值。

一个常用示例:

source_file = ./外研社英汉多功能词典.mdx
input_type = auto

INDEX_LANGUAGE = 英
CONTENTS_LANGUAGE = 汉

dictionary_name =
output_dir =

device_goldendict_root = /storage/emulated/0/GoldenDict
install_dir =

css_storage = zip
resource_layout = original

local_resource_dirs = .
local_resource_recursive = true

rewrite_inside_resources = true

stardict_dictzip = true
stardict_html = true

keep_raw_tabfile = false

其中:

dictionary_name =
output_dir =

留空时会自动根据输入文件名生成。


十、两种运行方式

方法 1:使用 config.txt

python mdxtogd.py

程序默认读取当前目录的:

config.txt

方法 2:直接指定输入和输出

python mdxtogd.py xx/词典.mdx yy/新词典名称.ifo

Tabfile/Textfile 也可以:

python mdxtogd.py dict.tab out/NewDict.ifo
python mdxtogd.py dict.txt out/NewDict.ifo

如果语言是:

eng → zho

最终 StarDict 会自动生成:

out/NewDict.en-zh.ifo
out/NewDict.en-zh.idx
out/NewDict.en-zh.dict
out/NewDict.en-zh.dict.dz
out/NewDict.en-zh.bmp

而 DSL 和图标仍然保持:

NewDict.dsl
NewDict.dsl.files.zip

十一、主要依赖

核心需要:

Python
PyGlossary
mdict-utils

建议同时安装:

Pillow
python-idzip

例如:

python -m pip install pyglossary mdict-utils Pillow python-idzip

部分 PyGlossary 插件可能还会提示缺少 lxml,如果希望一起安装:

python -m pip install lxml

十二、输出目录示例

例如:

外研社英汉多功能词典/

转换工作目录大致如下:

外研社英汉多功能词典/
├─ 外研社英汉多功能词典/
│  ├─ 外研社英汉多功能词典.dsl
│  ├─ 外研社英汉多功能词典.dsl.files.zip
│  ├─ 外研社英汉多功能词典.en-zh.ifo
│  ├─ 外研社英汉多功能词典.en-zh.idx
│  ├─ 外研社英汉多功能词典.en-zh.dict
│  ├─ 外研社英汉多功能词典.en-zh.dict.dz
│  └─ 外研社英汉多功能词典.bmp
│
├─ 外研社英汉多功能词典.android.txt
├─ makestardict.bat
├─ _makestardict.py
├─ GoldenDict安装位置.txt
└─ conversion_report.json

Android 端只需要复制内层正式词典目录中的文件。


十三、一些说明

这套脚本主要是按我自己在 Android GoldenDict 上实际使用词典的需求逐步整理出来的,因此重点不是做一个通用格式转换器,而是尽量把:

MDX/MDD
↓
资源整理
↓
Android GoldenDict DSL资源
↓
StarDict
↓
语言识别
↓
目录部署

这一整套过程自动化。

不同 MDX 的 HTML/CSS/JS 写法差异很大,因此不敢保证所有词典都能完全无修改直接转换。如果碰到特殊资源路径、特殊脚本、特殊 MDD 结构等问题,也欢迎反馈具体词典结构或报错信息,后续可以继续完善。

建议第一次转换新词典后,重点检查:

conversion_report.json
GoldenDict安装位置.txt
词典名.android.txt

如果有:

⚠️ 未解析本地资源

最好先确认对应资源到底是在 MDD、本地文件夹,还是原词典引用本身已经失效。

目前我自己主要用于 Android GoldenDict 的 MDX → StarDict + DSL resource 转换,欢迎大家测试、改进和反馈。

极速,支持词典格式多,支持Hunspell,词条索引可以自定义检索深度
对于意大利语/西班牙语/葡萄牙语以及其他有特殊符号的语言来说,使用它来检索是便捷的(一定要找到所需语言的合适的Hunspell文件)。
现在,专业版还可以免费获取key使用。

GOLDENDICT.MOBI (安卓版GoldenDict官网)
GoldenDict Mobile

About

GoldenDict Mobile is a multi-format dictionary program with reach formatting, colors, images and sounds. It fully supports a lot of popular dictionary formats. You can now carry all the dictionaries you want together with you on your Android device.

Supported formats

  • Lingoes .LD2 files
  • Babylon .BGL files
  • ABBYY Lingvo .LSD, .DSL, .LSA and .DAT files
  • StarDict files
  • Dictd files
  • Hunspell morphologies

Features

  • All content is shown in full formatting, with images and sounds. We don’t compromise on quality.
  • It’s fast. It flies when you have a dozen of dictionaries, and can handle hundreds of dictionaries simultaneously fairly well, too.
  • The program will understand your typing no matter how you do it - forget about diacritics, case or punctuation!
  • In-program popup mode is supported. Configure your e-book reader to use “ColorDict3” as your dictionary interface, and GoldenDict will pop up.
  • Translating from clipboard is easy - just press and hold “Search” button on your device!
  • Supported devices: all Android versions starting from 1.5 and up to 4.4.

Getting it

GoldenDict Mobile is no longer being commercialized, and is probably going to be released as open source in the future.

Meanwhile you can continue using the latest released version, or any previously released one:

  • You can download the latest version here. Older versions are available here.
  • To get an offline license file, use the form here. You’d need to put a 10-digit device id into it, and it will let you download the file named ‘goldendict-key.txt’. Place it into /sdcard/GoldenDict or /sdcard/GoldenDict/.config dir. You can also simply try opening the downloaded file and choosing ‘Install GoldenDict License’ to install it automatically.

There’s also a completely free, open-source version of the program available for your desktop. Get it here.

GoldenDict Mobile mods for latest OS Android (by me is installed v2.6):

Open Source alternative for GoldenDict Mobile - supports AARD2 (.slob), Octopus (.mdx/.mdd), Babylon (.bgl), Stardict (.ifo), Abbyy Lingvo (.dsl) and ZIM (.zim) formats:

Releases:

Format converters:

…and below on this file:

哈喽楼主,总算见到本人了。

单纯分享一些工具;)

MOD版都能修改什么内容吖?

There is no need to change anything. According to the author, the program’s requirement regarding the operating system architecture under which the application runs has been modified, and the registration requirement has been removed.

wow,这个好强大啊,支持格式好多,马上下载win版试试。

是否可以对MOD版增加功能?其实我有一些想法。

I don’t think that’s possible. As far as I understand, the two authors of the modified versions simply changed the program’s requirements, not the options it offers. It still isn’t open-source, and likely never will be (an intention to make it so was announced over five years ago, yet the code was never actually opened). However, you can always reach out to the author of the other program -who is very responsive and accommodates user requests whenever possible - via the “Issues” section.

谢谢。有机会我把我的想法和可能的解决办法都一起写给GoldenDict的作者。
你的软件我也下载使用了,挺好的,就是界面风格我还不太习惯 ;)
希望你的多平台软件能够做得更好!

Thanks, but I am not the author of the software. The author is a Russian-speaking user (I don’t know if he is Russian, Belarusian, Ukrainian, or from one of the former republics - it doesn’t matter). He primarily posts on a Russian-language forum that I visit, and I am simply sharing what he has created because I think it is really good. You can also find him in this Telegram group; his nickname is Bio.

P. S. Homepage of the app: https://wudict.legbehindneck.com/

The author of GoldenDict stopped supporting the mobile version of the program long ago; the official desktop version has been updated only once in 15 years and is also being developed by others, such as xiaoyifang…

目前我的手机上仍能正常安装和使用GoldenDict Mobile,以前还是在Google Play上购买的。如果未来开发者既不更新也不公开代码,那真的很可惜,那到时候就可能只能用MOD版本了。

你的wudict是open的,多平台,多格式,也是很轻量,这些方面都很好,我再多用用,这样才能给出使用反馈;)

与你聊天挺开心的。

这个app目前是在浏览器中打开各种词库,无法做到GD那样做到在任何文档或浏览器网页文章中快捷取词查词,如果能做成单独的操作界面就好了

goldendict安卓版似乎还是不支持mdx格式?

Yes, GoldenDict does not support MDX.

所以用这个python代码就可以“曲线救国”实现
stardict的格式其实挺好的,还支持 主词头|副词头1|副词头2… 还有好多特点
毕竟stardict的开发者也是个人物!设计格式的时候就想得挺周全了的

我上上个月在隔壁论坛学到了这一招,遂“古法”转制了基本最常用的辞典到stardict+dsl.zip资源包,没想到楼主直接把这自动化了!

GoldenDict的最原始的作者Isakov可能已经淡出开发了,安卓版宣称开源也是遥遥无期。
但是大家可以呼吁其他辞典软件的作者添加Hunspell功能嘛,像《词悦》的最新测试版已经有了,而且还支持两轮查询:

I tried installing Wudict on Android, but its lemmatization by default accesses raw.githubusercontent.com, and that domain is inaccessible in China without a :ladder:.

Could not read the catalogue: Get “https://raw.githubusercontent.com/wuweidict/lemmas/main/manifest.json”: dial tcp [::]:443: connect: connection refused — languages already installed still work.

I manually ran git clone GitHub - wuweidict/lemmas: lemmatization files for wudict https://wudict.legbehindneck.com/ · GitHub and then put de.tsv.gz into
/storage/emulated/0/Android/data/com.legbehindneck.wudict/files/.wudict/lemmas
This time it really did load the German morphology file, but I tried searching for “abgekämpftes” and it couldn’t find “abgekämpft”, let alone “abkämpfen”. I unzipped its morphology file and took a look: it turned out to be entirely a hard-coded word list, different from the Hunspell used by GoldenDict.
But de.tsv does indeed contain these two lines:

abgekämpft	abgekämpfte	abgekämpftem	abgekämpften	abgekämpfter	abgekämpftere	abgekämpfterem	abgekämpfteren	abgekämpfterer	abgekämpfteres	abgekämpftes	abgekämpfteste	abgekämpftestem	abgekämpftesten	abgekämpftester	abgekämpftestes
abkämpfen	abgekämpft	abkämpfe	abkämpfend	abkämpfens	abkämpfest	abkämpfet	abkämpfst	abkämpft	abkämpfte	abkämpften	abkämpftest	abkämpftet	abzukämpfen

Why it can’t be found, I have no idea…
In addition, the lemmatization file that comes with Wudict has no Japanese, let alone the fact that Chinese traditional/simplified cross-search can also be implemented with Hunspell.

我试着在安卓上安装了wudict,但是它的还原词形默认就会访问 raw.githubusercontent.com,然而这个域名在中国不用:ladder:是访问不了的。

Could not read the catalogue: Get “https://raw.githubusercontent.com/wuweidict/lemmas/main/manifest.json”: dial tcp [::]:443: connect: connection refused — languages already installed still work.

手动git clone GitHub - wuweidict/lemmas: lemmatization files for wudict https://wudict.legbehindneck.com/ · GitHub 然后把de.tsv.gz放入
/storage/emulated/0/Android/data/com.legbehindneck.wudict/files/.wudict/lemmas
中,这下确实可以载入德文构词法文件了,但是我试了下搜索„abgekämpftes“,并不能找到„abgekämpft“,更别说„abkämpfen“了。解压它的构词法文件看了看,原来全部是写死的词表,跟GoldenDict采用的Hunspell不一样。
但de.tsv里面确实有这两行:

abgekämpft	abgekämpfte	abgekämpftem	abgekämpften	abgekämpfter	abgekämpftere	abgekämpfterem	abgekämpfteren	abgekämpfterer	abgekämpfteres	abgekämpftes	abgekämpfteste	abgekämpftestem	abgekämpftesten	abgekämpftester	abgekämpftestes
abkämpfen	abgekämpft	abkämpfe	abkämpfend	abkämpfens	abkämpfest	abkämpfet	abkämpfst	abkämpft	abkämpfte	abkämpften	abkämpftest	abkämpftet	abzukämpfen

为什么查不到我就不知道了……
另外,Wudict自带的词形还原文件是没有日文的,更别说中文繁简通查也可以用Hunspell实现了。

然而你去看那个索引文件.idx就会发现设计是一坨史,所有索引只能按顺序读取,想实现二分法查就只能全部加载进内存(也可以只存偏移量)。对于松鼠来说同时查询几百本几千本词典将是个灾难。或者像goldendict那样重新构建索引。总体评价是拉完了