可以給Mac的Dictionary添加其他原裝詞典嗎?怎麼添加?

Mac的Dictionary很好用,英文系統自帶了Oxford的英英詞典。我猜想法文系統應該也會自帶個英法或者法英詞典什麼的,德文同理。

請問我可以給Dictionary添加這些詞典嗎?怎麼添加?有Apple買好的原裝詞典可以免費下載嗎?或者其他來源?

我想添加法英和徳英。


Step by Step guide on how to convert Mdic to Mac dictionary
轉換Mdic到Mac擴展詞典 教程

來自ilius/pyglossary · GitHub 項目

環境要求

Python 2.7

OSX10.8及以上自帶Python

若系統在OSX10.8以下請手動安裝:Welcome to Python.org

Command Line Tools for Xcode

https://developer.apple.com/downloads/可下載(注意版本號)

Dictionary Development Kit

https://developer.apple.com/downloads/下載 Auxiliary Tools for Xcode

把其中的Dictionary Development Kit複製到/Developer/Extras/Dictionary Development Kit(若沒有該路徑請新建文件夾

BeautifulSoup4

打開Terminal

輸入

sudo easy_install beautifulsoup4 html5lib

具體步驟

1. 把要轉換的Mdic文件放到一個單獨的文件夾(方便後面操作),記下存放Mdic文件的文件夾路徑,在Terminal輸入:

cd 文件夾路徑

例如:

cd ~/Downloads/oald8

敲回車

2. 至Releases · ilius/pyglossary · GitHub下載代碼包(一般選擇最新版,若後面有報錯請選其他版本嘗試。 20160203經@Lix.me 測試可行。),解壓,記下pyglossary.pyw這個文件的路徑,在Terminal輸入:

python pyglossary.pyw文件路徑 --read-options=resPath=OtherResources --write-format=AppleDict Mdic文件名.mdx Mdic文件名.xml

例如:

python ~/Software/pyglossary/pyglossary.pyw --read-options=resPath=OtherResources --write-format=AppleDict oald8.mdx oald8.xml

敲回車,等程序自動運行完畢。

3. 在原來Mdic的文件旁會出現新的文件夾,確認該文件夾下沒有音頻格式文件(wav, mp3),有的話請刪除。(因為過多音頻文件會導致製作失敗,而MAC詞典本身也不支持音頻。)

4. 在Terminal依次輸入以下幾句:

cd Mdic文件名

sed -i "" "s:src="/:src=":g" Mdic文件名.xml

make

make install

體積大的詞典轉換時間會比較長,請耐心等待命令運行完畢。
然後打開詞典的設置頁,勾選剛剛轉換完的詞典即可。

應求上傳
漢典:http://pan.baidu.com/s/1dDQPIQ9(原圖片文件在轉換後無法顯示,已從文件包中刪除。若要查詢字型請訪問:漢典 zdic.net)
日漢雙解:http://pan.baidu.com/s/1eRfHgHW
牛津、朗文、劍橋、柯林斯雙解四合一:http://pan.baidu.com/s/1hsxw1Xa
Macmillan English Dictionary: https://pan.baidu.com/s/1miEsQOK 密碼: ve73

Mdic分享網站
◆Edict詞庫,維基百科,Wiki資源 http://www.owndict.com

效果圖

Macmillan English Dictionary:

漢典:


mac的Dictionary可以添加很多詞庫, 很多不支持的詞庫都可以轉換成支持的詞庫, 例如StarDict的詞庫,GoldenDict的詞庫. 下面貼出的是前幾天找到的一個詞庫轉換方法. 幾乎可以將目前常見的詞庫轉成Mac的Dictionary

convet DSL or BGL format or starDict dictionarys to mac dictionary

someone makes a script to convert, it"s name is pyglossary. This project is located here: ilius/pyglossary · GitHub

In order to use it, you need to install Command Line Tools for Xcode and Dictionary Development Kit, the kit can be download fromSign in with your Apple ID

NB.Dictionay Development Kit is part of Auxiliary Tools for Xcode.

And finally here is a bash script that automates the entire process for the DSL format: Run the bash script without arguments to see usage notes.

NB. You will need to edit the script and set the correct value of PYGLOSSARY_HOME, by default it is ~/projects/pyglossary/pyglossary. It will auto convert and copy the finally dictionarys to Apple Dictionary location.

[ convert_dsl_to_appledict.sh](Convert dictionaries in Lingvo DSL format to AppleDict format. Depends on pyglossary, iconv, and OSX Command Line Tools for Xcode, and OSX Dictionary Development Kit)

[ convert_bgl_to_appledict.sh](convert_bgl_to_appledict.sh)

Note

If you want to convert dsl.dz format dictionary of goldendict.First you need install dictzip in order to extract it to .dsl format. The dictzip cmd has built in Ubuntu.

我將GoldenDict下朗文5和朗文5的1.5GB的含發音的擴展詞庫轉換成Mac的Dictionary詞庫了, 下載鏈接: Longman5_Extras.tar.gz等 (pan.baidu.com/s/1bpgLHL1). 由於Mac的詞典不支持發音,所以轉換之後丟失了朗文中的真人單詞發音和例句發音.

下面是2張朗文5的靚照:

-------------------------------------------------------------------------------------------------

update:2015.03.30

今天轉換了柯林斯英英詞典, 老規矩先上靚照

下載鏈接: CollinsCobuildEnen_utf8.tar.gz (pan.baidu.com/s/1hrW2kdA)


詞典資源下載地址見最後一部分。

9月6日更新:修復牛津、朗文、劍橋、柯林斯四合一雙解版中的CSS樣式問題,新增Concise Oxford English Dictionary and Thesaurus、Longman Language Activator、Oxford Collocation Dictionary of English、Shorter Oxford English Dictionary。

11月15日更新:新增語音版圖文版Merriam-Webster"s Collegiate Dictionary、Vocabulary.com Dictionary、WordNet 3.1, 1.51中文簡釋版、World Book Dictionary 2015。

感謝 @stein 與 @倚樓 提供轉換好的詞典。

不過使用了一段時間後發現詞典內鏈接跳轉不正常,不能發音、圖片不能顯示等種種小問題。研究了一會兒之後終於把各個問題都解決了。這樣詞典既有原生dictionary的良好體驗,又實現了GoldenDict、歐路詞典下拓展詞庫的完善功能。

下面簡要簡要記錄由Mdict詞典文件轉換成完美dictionary文件的過程如下。

開源項目

PYGLOSSARY:最新Releases見ilius/pyglossary/releases

python-lzo:

sudo pip3 install python-lzo

準備好以下環境:

  • Writing to AppleDict

sudo pip3 install lxml beautifulsoup4 html5lib

  • GNU make as part of Command Line Tools for Xcode.
  • Dictionary Development Kit as part of Auxillary Tools for Xcode. Extract to/Developer/Extras/Dictionary Development Kit

轉換過程

  • 用PYGLOSSARY進行轉換

假設詞典文件為~/Downloads/oald8/oald8.mdx, 圖片、語音文件oald8.mdd也在同一文件夾下。

先將詞典文件轉換成xml文件,並將其他圖片、音頻等文件提取出來放在OtherResources文件夾下。

cd ~/Downloads/oald8/
python3 ~/Software/pyglossary/pyglossary.pyw --read-options=resPath=OtherResources --write-format=AppleDict oald8.mdx oald8-apple
cd oald8-apple

在PYGLOSSARY的說明中接下來是將xml文件中的相對鏈接中的"/"去掉以及替換spx為wav。

sed -i "" "s:src="/:src=":g" oald8.xml
sed -i "" "s|sound://([/_a-zA-Z0-9]*).spx|1.wav|g" oald8.xml

其實這兩步可以在之後用正則統一替換。

  • 轉換語音文件

如果是spx文件,先轉換成wav(需安裝speex)。若是wav文件則可跳過這一步。

find OtherResources -name "*.spx" -execdir sh -c "spx={};speexdec $spx ${spx%.*}.wav" ;

然後用FFmpeg把wav文件轉換成mp3文件(macOS中默認的iTunes與QuickTime均不支持wav格式)。

新建sh腳本文件如下,並在當前目錄新建Sounds文件夾,然後執行sh腳本。

for x in ./OtherResources/*.wav; do ffmpeg -i "$x" "Sounds/`basename "$x" .wav`.mp3"; done

如果語音文件較多的話需等待較長時間。朗文當代第五版中近二十萬個音頻文件我頂配的15寸 MacbBook Pro也轉換了半天...

  • 編譯

make

有時生成的詞典包文件中並沒有圖片、音頻文件。這時將OtherResources文件夾中除音頻外的其他文件以及放置mp3文件的Sounds文件夾複製到xxx.dictionary/Contents目錄下(右鍵dictionary文件,選擇Show Package Contents)。

  • 安裝

將生成的dictinary文件複製到當前用戶文件下下的/Library/Dictionaries中(或者打開Dictionary App,選擇菜單欄中的文件-&>打開詞典文件夾,即可進入該文件夾),之後在Dictionary App的菜單欄中詞典-&>偏好設置中啟用一下就行。

修正詞典文件的各種問題

以上方法生成的詞典會有開頭說到的詞典內鏈接跳轉不正常,不能發音、圖片不能顯示等種種小問題。下面修復這些問題。

  • Dictionary的URI Scheme介紹

以下引自Dictionary Services Programming Guide。

x-dictionary: is an URI scheme that describes cross references between entries in dictionaries. It is used in tag such as &.

The x-dictionary:URI contains three elements separated by colons as the general form—target selector, target text, and dictionary bundle ID. The target selector must be either d (for definition) or r (for reference). Use d if you want to search definitions of the following key text. Use r if you want to refer to the entry specified by the reference ID which must be unique to each dictionary.

x-dictionary:d:key_text:dict_bundle_id
x-dictionary:r:reference_id:dict_bundle_id

The dictionary bundle ID can be omitted in both forms, as shown in the following lines. If it is omitted, Dictionary Services searches the target text in all active dictionaries.

x-dictionary:d:key_text
x-dictionary:r:reference_id

  • 修複詞典中的鏈接跳轉問題。

舉例來說,假設dict_bundle_id為Longman5。(dict_bundle_id可在生成的詞典文件中的Info.plist中修改。)

假設xml文件中為:

&hour&

可替換為:

&hour&

可用正則表達式匹配然後處理。

  • 修正詞典中頁面內的定位問題

例如點擊apple1會跳轉到同一個頁面中的apple2處。

&apple1&
&apple2&

將其替換為

&apple1&
&apple2&

可用正則表達式匹配然後處理。

  • 修複詞典的發音問題

假設xml文件中為:

&&&

可替換為

&&

onmousedown可替換成onmouseover,這樣滑鼠懸浮上發音圖標就開始發音,而不用單擊。

可用正則表達式匹配然後處理。

  • Java正則替換代碼示例

以Longman5_Activator為示例,假設只需要修復鏈接跳轉問題和頁面內的定位問題。寫得比較隨便,隨意看一下就好。

當然有些編輯器直接支持正則表達式查找和替換,這樣就不用寫程序了。

import java.io.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Replace {
static final String REGEX_1 = "x-dictionary:d:entry:\/\/#";
static final String REGEX_2 = "entry:\/\/([^#"][^"]*)"";
static final String Bundle_Id = "Longman5_Activator";
static final String inputName = "Longman5_Activator.xml";
static final String outputName = "Longman5_Activator_Output.xml";
static final String ENCODE = "UTF-8";
BufferedReader br = null;
BufferedWriter bw = null;

public static void main(String[] args) throws IOException {
new Replace().replaceFile();
}

public String replacefun1(String line) {
Pattern pattern = Pattern.compile(REGEX_1);
StringBuffer sbr = new StringBuffer();
Matcher matcher = pattern.matcher(line);
while (matcher.find()) {
matcher.appendReplacement(sbr, "#");
}
matcher.appendTail(sbr);
return sbr.toString();
}

public String replacefun2(String line) {
Pattern pattern = Pattern.compile(REGEX_2);
StringBuffer sbr = new StringBuffer();
Matcher matcher = pattern.matcher(line);
while (matcher.find()) {
matcher.appendReplacement(sbr, matcher.group(1) + ":" + Bundle_Id + """);
}
matcher.appendTail(sbr);
return sbr.toString();
}

public void replaceFile() throws IOException {
try {
br = new BufferedReader(new InputStreamReader(new FileInputStream(
inputName), ENCODE));
bw = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream(outputName)));
String line = null;
while ((line = br.readLine()) != null) {
bw.write(replacefun2(replacefun1(line)));
bw.newLine();
}
} catch (IOException e) {
} finally {
bw.close();
br.close();
}

}

}

其他注意事項

  • 文本匹配的正則表達式需一一調試

以上每個詞典文件中的具體模式均不太一樣,而且有時會有與一般模式不同的個例(如多加了幾個空格、標籤間加了個&
、中間換了一行、圖片大多是png個別是gif等等),需要一一調試。推薦調試網站Regexr。

  • 空格相關問題

連續兩個粗體單詞之間的空格會不顯示。例如

&apple& &pie&

會顯示為applepie。此時將其替換為

&apple &pie&

注意xml中不能用nbsp;。

另外有時xml中會有amp;nbsp;,原意應顯示為為空格,卻顯示為nbsp;。此時將其替換為#160;就好。

  • 取詞小窗口修改大小

若取詞小窗口中字體太小,可在詞典包內容中的DefaultStyle.css文件中加上以下內容:

.apple_client-panel body{margin: 0 0 15px;font-size: 16px;}

  • CSS樣式文件

若OtherResources文件夾中有其它CSS文件,或者原來CSS文件就獨立於MDict文件之外,將其內容複製到詞典文件包中的DefaultStyle.css文件中

  • 其它問題

將@@@LINK=abc替換成&abc&.

如果圖片無法正常顯示,將相對路徑名最前面的/去掉,例如將&替換成&.

由於macOS的Dictionary中滑鼠懸浮於某一內容之上時會將其視作一個span,如果CSS中原本就有應用於所有span的樣式,會把該樣式應用於滑鼠經過的區域。這樣滑鼠經過的區域會有很奇怪的樣式。解決辦法是在原有span中加一個class,並把原來span的樣式歸到新建的class中。

等等。

  • 其他功能

Dictinary還支持高亮搜索關鍵詞、家長控制功能等等,參考之前提到過的Dictionary Services Programming Guide。

與Alfred Workflow結合的一些功能

  • 快捷鍵取詞

雖然三指輕點取詞很方便,但是有些軟體並不支持三指取詞。結合Alfed Workflow即可實現選中待查內容後快捷鍵取詞。

open dict://{query}

  • 快捷鍵發音

下載韋氏142000單詞發音庫(密碼:cjk0)後,假設解壓至~/Voice文件夾下。同理即可實現選中待查內容後快捷鍵發音。

query={query}
word="${query//~}"
char=${word::1}
afplay ~/Voice/$char/$word.wav

當然系統中開啟Speech功能,結合快捷鍵也能實現類似功能。缺點是這是合成的發音而非真人發音,優點是單詞變形乃至句子段落都能發音。

效果圖示意

轉換了一些詞典,這裡放幾張示意圖。下載地址見最後部分,大家自取吧。

  • Longman Dictionary of Contemporary English, 5/e

  • 牛津、朗文、劍橋、柯林斯四合一雙解版

  • Oxford Collocation Dictionary of English, 2nd Edition

資源下載

  • Macmillan English Dictionary 2nd Edition 密碼:mwkz(這本詞典好處是詞條處把短語與搭配單列出來,並且有Thesaurus,有發音。)
  • Longman Dictionary of Contemporary English, 5/e 密碼:s7q8(包括Longman5與Longman5_Extras兩部分,因為有單詞和例句發音,文件比較大。Extras部分有collocation與corpus。)
  • 牛津、朗文、劍橋、柯林斯四合一雙解版 密碼:ymuo(9月6日已修復CSS樣式問題)(這本詞典需安裝Kingsoft Phonetic Plain字體,否則音標顯示不正常。字體下載地址 密碼:o3r4)
  • Oxford Advanced Learner"s Dictionary, 8th Edition 密碼:eg40(這本詞典由pdawiki網友製作,除發音沒有外其它均正常。需要發音的朋友可參考這裡自行提取添加。)
  • Concise Oxford English Dictionary and Thesaurus, 11th Edition 密碼:kpwq(這本簡明扼要)
  • Longman Language Activator 密碼:2h38(Thesaurus詞典)
  • Shorter Oxford English Dictionary, 6th Edition 密碼:yzqe(是Oxford English Dictionary的簡編版,義項排列按時間順序,比較適合高水平讀者。)
  • Oxford Collocation Dictionary of English, 2nd Edition 密碼:52e7(搭配詞典)
  • 語音版圖文版Merriam-Webster"s Collegiate Dictionary
  • Vocabulary.com Dictionary(這本會用一段文字解釋單詞,適合語境背單詞。同時有衍生詞、同反義詞。最後一部分釋義取自WordNet。)
  • WordNet 3.1, 1.51中文簡釋版(Thesaurus很不錯)
  • World Book Dictionary 2015

當然Dictionary中內置的Oxford Dictionary of English(或New Oxford American Dictionary)與牛津英漢漢英詞典也很好,基本上是我使用頻率最高的兩本詞典了。

Reference:

  1. MAC OSX詞典轉換筆記
  2. BGLDSLMDXCD ===&> OS X dictionary


Use the Mac OSX built-in Japanese Dictionary!這個鏈接裡面說了10.5以後自帶了日語詞典,其他的詞典我不知道是什麼時候加入的。不用網上去找各種詞典文件什麼的,自帶的已經很全了。


可以的。

把字典文件拷貝到/Library/Dictionaries就可以了。

參考網址:Mac技巧之蘋果電腦 Mac OS X 系統自帶的支持屏幕取詞的多語言翻譯軟體 「字典」 詳細介紹

下面這個網址提供世界各種語言的詞庫,親測荷蘭語-英語好用,雖然詞條不全。

http://mysite.mweb.co.za/residents/clasqm/mac-os-x-dictionaries/


今天才想起來把我的小教程發上來:D 希望有用。

原文:【原創】 為mac添加自製詞典 轉換mdx格式到mac詞典格式

【轉換mdx格式到mac詞典格式】

準備:

我們要用到一個開源項目PYGLOSSARY,ilius/pyglossary · GitHub。點開鏈接,下載zip文件就可以了。

根據頁面下方的指引,準備好:

?BeautifulSoup4(with html5lib as backend) required to sanitize html contents.

(在終端輸入:sudo easy_install beautifulsoup4 html5lib)

? - GNU make as part of Command Line Tools for Xcode.

- Dictionary Development Kit as part of Auxillary Tools forXcode. Extract to /Developer/Extras/Dictionary Development Kit

- (這兩個均在http://developer.apple.com/downloads下載,要仔細找一找,好像搜索不到。)

- 將Dictionary Development Kit解壓到/Developer/Extras/下。(如果沒有這個目錄,新建一個。)

準備好要轉換的詞典,在這裡以abc.mdx和abc.mdd為例,將他們存放在 /Users/(你的用戶名)/Downloads/1/ 文件夾里。記得詞典名字最好不要有空格中文之類。mdd文件包含了詞典的格式、多媒體等資料,不能遺漏。

將下載回來的PYGLOSSARY的zip文件解壓到 /Users/(你的用戶名)/Downloads/ 目錄下(為了方便,記得將文件夾改名為pyglossary)

好啦!準備工作就做好啦。

第一步:

打開終端,在終端輸入:

$ cd ~/Downloads/1/~/Downloads/pyglossary/pyglossary.pyw --read-options=resPath=OtherResources --write-format=AppleDict abc.mdx abc.xml

(進入 /Users/(你的用戶名)/Downloads/1/ 目錄;

開始轉換。)

第二步:

成功之後,你會在目錄里看到一些新文件。不要關閉終端,繼續在終端輸入:

$ make

(生成文件)

好了,現在應該能看到多出來的objects里有一個.dictionary文件(夾),就要勝利了。現在可以關掉終端。

如果在這時候將詞典文件拷貝到 /Library/Dictionaries 文件夾里,你可能會發現詞典的格式很難看,不是原來的樣子,而且名稱也很奇怪。這是因為一些設置參數還沒有調整。我們再回到生成的.dictionary文件。

第三步:

進入.dictionary文件:右鍵 - 顯示包內容

我們首先調整詞典的名字:

打開info.plist(可能需要xcode)

將Bundle identifier的abc改成一個你喜歡的唯一的字元串(保證和其他詞典不同就可以了);

將Bundle name改成詞典的名字,比如圖中改成「牛津英語習語詞典」。

保存並關閉。

再調整樣式:

將DefaultStyle.css刪掉;

將sf_cb.css複製一份並且改名成DefaultStyle.css,

第四步:

好了!現在詞典可以用了。將它複製到資源庫里的Dictionaries文件夾(/Library/Dictionaries),再在詞典的偏好設置中啟用吧!別忘了和大家分享。

問題:

每個轉換的詞典釋義里都會有一個標題,貌似是軟體自動加上的,不知道怎樣去掉?

20150710 #已解決:只要在第四步在兩個css樣式文件里添加

h1{
display:none;
}

就可以了。


給 @朱冰一 的答案專門擷了Yosemite系統的圖:


把格式好的字典直接放到/Users/UserName/Library/Ditionaries 這裡有一些詞典下載MAC OSX詞典轉換筆記


額,似乎還沒答案提到 DictUnifier:

打造全能Mac自帶Dictionary~~

不需要輸入命令,都在圖形界面下操作 ( ??。)

上文提到的 zh_CN 簡體中文詞典 里有 100 多種與簡體中文有關的詞典下載。StarDict Dictionaries -- 星際譯王詞庫 里也有其他語言的詞典庫。


後排提醒一下大家,在最新系統(macOS High Sierra 10.13)下添加第三方詞典會導致使用spotlight時閃退,癥狀為輸入兩個字母就閃退,但手速快(非常快)的話就不會,但如果只追求使用spotlight查找文件及其他可以在設置-spotlight-定義 前面勾掉,可以正常使用,代價是無法使用spotlight直接查單詞,但其實如果直接使用spotlight查單詞也並不會顯示第三方釋義

以上


打造全能Mac自帶Dictionary~~

我是搬運工

完美解決dictionary的問題!


關鍵dictionary development kit好像xcode8.0用不了呀。

make不了啊。。。


/bin/sh: /Developer/Extras/Dictionary Development Kit/bin/build_dict.sh: No such file or directory

make: *** [all] Error 127

我按照stein的方法做呢,所有正常,但是到sed -i "" "s:src="/:src=":g" oald8.xml這一個步驟的時候。出現以上錯誤。看起來像是Auxiliy解壓到系統developer文件夾的時候出錯,能幫我看看具體是哪裡出錯了嗎?這個問題如何解決呢?感謝了,就差這一步了


不用這麼複雜,看到一個帖子,下載zip文件,然後添加字典,就好了。

zip鏈接

https://app.box.com/s/tpewnps320yq442po46e


可以添加,有個湘雅醫學詞典,簡直好用到爆


Dictionaries for macOS,這個鏈接裡面下載程序,添加詞典。測試版,正式版需要花錢。我買了挪威語-英語詞典,7.99美刀。三指單擊就查詞,很棒。


剛剛做了一個字典,遇到一些坑,寫了一篇日記:

http://fangpeishi.com/abbreviations_dictionary.html


有沒有可能將mac的詞典轉換成mdict格式?到處搜尋都沒有方法。


上面的這些回答,各種腳本,各種命令行,真心是太複雜。。。。我來個簡單的:

---

mac詞典默認把詞典文件放在`/Library/Dictionaries`目錄,是.dictionary後綴的文件。所以,把你的詞典文件,粘貼到這個目錄。完了在`詞典-&>偏好設置`中啟用一下就行。

---

就這麼簡單。已驗證,即下圖中:朗道詞典5.0


發現了一個很簡單的方法,在Mac App Store下載dictionaries,然後找後綴為dictionary格式的字典,用dictionaries打開,授權,原生字典里的參考源裡面就有了


關鍵是dictionary development kit在蘋果得官方網站上下不到了


推薦閱讀:

為什麼人們有時雖然並不會外語,但是能夠分辨出聽見的是哪種語言?
你有哪些學習德語的經歷可以分享?
化妝品上的德語?
iOS 上有什麼好用的德語學習應用?
與母語不同的人用非雙方母語的第三門語言戀愛是什麼體驗?

TAG:Mac | 詞典 | 應用程序Application | 法語 | 德語 |