[USER JS] Opera DictCN v0.7 (English/Chinese translation - 英汉汉英翻译)
Sunday, 5. July 2009, 14:42:06
With this extension, select a word or text on a webpage, and you will have short Chinese or English translation from Dict.cn and optionally from BabelFish and/or Google, with pronunciation sounds of selected word (English or Chinese pinyin) and example sentences. It can also give Google translation in your preferred language (Korean, French, Finnish or whatever Google can translate).Download / 下载 : Opera DictCN v0.7 (zip file) or directly : Opera DictCN v0.7 (script file, 135.0 KB)
Please note I consider this as a BETA version, even if it works fine on most webpages (see Limitations below for more details).
要是您看不太懂英文的话,您能去Opera 应用交流,在那里有用中文的说明(谢谢fengshi11/555 !
The my.opera.com forum topic is here. The chinese opera forum is here (Opera 应用交流).


NEW in v0.7 (from 0.6.4) :
- an input field is now available to directly enter text to translate. See also Customization below.
- when translating a single chinese character, it proposes (see example in first picture above):
- if exists, a traditional/simplified version of the character (please note that a simplified character can have several associated traditional characters, ODictCN will only show one alternative)
- two animation popups (click on small pencils/brushes icons) presenting the stroke order of the simplified (or sometime cursive, try 汉) version of the character, one using javascript, the other one using animated pictures, both from MDBG.net (please note that some characters do not have such animations/pictures, or only in simplified version)
- seems to work with Opera 10 beta.
Here are details about other features of ODictCN, introduced in previous versions:- There are two Google Translation possibilities :
- the normal one by default translates between English and Chinese, as dict.cn and BabelFish, depending on the selected text content (with or without chinese characters).
- the second one called "Extra Google" allows to translate with a fixed translation setting, for example to always have the French or Finnish translation of the selected text.
=> See "Hints and customisation" to know how to configure those Google Translations.
- Chinese localization : ODictnCN will try to detect the Opera program language, and if it's Chinese (zh, zh-TW, ...) it will show chinese labels and messages (in traditional chinese if it's "zh-TW"). The zip file also contains a chinese version of the buttons file ("buttonsODictCN_zh.htm") and the menu file "menuODictCN.ini" now also contains a chinese version. Thanks to fengshi555 and yuxichengyu at the Opera chinese forum). See also "Installation instructions" below.
- ODictnCN will try to detect the available sound player plugins depending on a list, and select the first one available to play the sound. See below after Installation instructions section for details for configuration and issues.
- presents the dict.cn examples (optional, can be disabled with buttons bar or with small 'D' options buttons in webpage).
- Pressing Ctrl key when selecting text (when releasing left mouse button) deactivates ODictCN for that selection.
Installation instructions :
If you have already installed the buttons and menu and they don't work anymore with a new ODictCN version, please remove all of them, and replace with the new ones, previous versions ones may not work with the latest ODictCN.js.
1/ Installation of the User Javascript :
- Copy the file ODictCN.js to a personal directory, dedicated to Opera User Javascript.
- Open menu "Tools" -> item "Preferences..." -> tab "Advanced" -> item "Content" -> button "Javascript Options"
- at the bottom of the dialog, choose the directory where the ODictCN.js is.
- click OK. Reload the currently opened pages.
2/ Installation of the toolbar buttons :

- please open that page (english) or this one (中文) to see all the available buttons (or open in Opera the file "buttonsODictCN_en.htm" (english) or "buttonsODictCN_zh.htm" (中文), included in the zip file).
- Chose the buttons you want, and drag-and-drop each one to the toolbar (for example before the URL). IMPORTANT : to drag-and-drop that kind of link, you need to click and hold the left mouse button, and then move the mouse UP or DOWN, never to the RIGHT or LEFT, then go to the target position in toolbar and release the mouse button.
- a dialog will ask if you want to add that button (with an unreadable text, don't take care) : answer OK/YES.
3/ Installation of the menu associated with the main button :- Copy the file menuODictCN.ini (in the zip file or from here) into :
for Windows : C:\Documents and Settings\your username\Application Data\Opera\Operathe good version\profile\menu\
for Ubuntu : ~/.opera/menu
- Note : if you already have a custom menu file in that directory, you need to copy/paste the menu definition inside menuODictCN.ini into your file.
- Open menu "Tools" -> item "Preferences..." -> tab "Advanced" -> item "Toolbars", and in the second list (menu configuration), click on item named "ODictCN Options" (or your personal custom menu file name).
- Close options.
- Click on the small arrow near the ODictCN main toolbar button, and then the menu must be available.
About the sound players detection :
ODictCN uses an ordered list of sound players which is inside ODictcn.js file, please see variable "this.soundPlayers". It is an array, the first element is tested first. The first element for which a plug-in is found is chosen (but ODictCN do not test if the plug-in really works...).
For example : this.soundPlayers = [ 'REALPLAYER', 'MPLAYER', 'VLC', 'QUICKTIME' ];
The available values in "this.soundPlayers" are detailed below :
- 'REALPLAYER' : for RealPlayer (or helix player)
- if you want to use real player plug-in on Windows, please use Real alternative, instead of the (very unstable) RealPlayer.
- a very few pinyin sounds may not play with Real Alternative.
- On Ubuntu : the Official RealPlayer 11 (*.bin installer) works, but there is a very annoying warning message each time a sound is played. For me, on Ubuntu the VLC player with mozilla-plugin-vlc is the best, but it may be different for you.
- 'MPLAYER' : Windows Media Player on Windows, or MPlayer on Linux.
- Windows : if it didn't work, please download and install the WMP for Firefox plugin. If Firefox is not installed on your computer, you will have to copy manually the files into Opera directory, from c:\PFiles\Plugins.
- Problem : on my computer (Windows), playing english sounds never ends, the page stay in the loading state.
- Ubuntu : Mplayer + GECKO MEDIA PLAYER (tested) or MPLAYERPLUG-IN (not tested).
For a good and very detailed procedure for sound and videos installing on Ubuntu, see http://ubuntuforums.org/showthread.php?t=766683 .
- Problem with Mplayer+Gecko Media Player Plugin on Ubuntu : the chinese sounds works fine, but the english sounds do not (silent).
- 'VLC' : for VLC media player.
- Please see at http://www.videolan.org/vlc/.
For me, on my computer, on Windows, it hangs Opera ! But on Ubuntu, it works very well.
- 'QUICKTIME' : Apple Quicktime player
- windows and Mac only : http://www.apple.com/quicktime/. Works fine on Windows for me.
Notes :
- the Sound Volume slider is only available with RealPlayer.
- If no plugin at all is detected, there's no sound icon inside popup, and the "Sound (声音)" item is absent from the options above the small 'D' button.
- some plugins may be slower to play the sounds than another.
Limitations :
- Google auto-detection feature ('auto|...') doesn't work very well with simple words, it often fails to detect the correct language, and then an error occurred.
- BabelFish (Yahoo!) may stop to answer to the queries if too much requests are send to it in a short time (the famous 999 error). If this happens, please disable the use of BabelFish for a while (several hours). See also Customization to know how to query babelfish only when there's no response with dict.cn.
- there's a problem with some websites using framesets. It may not work at all with those websites.
- the popup is hidden by Flash Player elements. Try to scroll down or up to see the popup.
- Please note that like all the User Javascript extensions, ODictCN is disabled by Opera on secured web sites (HTTPS).
Hints and customisation :
- (NEW)input field: the value "this.isTextInputAutoClose" in ODictCN.js determines if the input field hides (true) when you press Enter or the button, or if it stay visible until you click on the small "X" red button.
- Google sentences Translation : both are enabled/disabled separately, with 'D' button menu or toolbar menu or toolbar buttons.
- Google sentences Translation have a great feature : language autodetection. But for isolated words, it does not work properly. By default for "Google", ODictCN will force origin language to English or Chinese, as it does with BabelFish. If you want to benefit from Google autodetection, you can set the value "this.googleUseAuto" to true, in file "OdictCN.js". This may be useful if you want chinese translation of non-english text, and want to use "Extra Google" for another purpose (as translate in English).
- the "Extra Google" feature allows to translate with a fixed translation setting, for example 'auto|fr', which autodetects the source language and will always try to translate it in French. You can change that setting in file ODictCN.js, by changing the value "this.googleExtraLang". All available values are detailed in comments before that value.
Note : the "Extra Google" can also be useful if you want to have at the same time Simplified and Traditional chinese translation with Google : for example if ODictCN is in "Simplified" mode, set the value to "auto|zh-tw", you will have Traditional results with "Extra Google". The ODictCN general option "Traditional/Simplified" does not apply to "Extra Google" feature, for that purpose.
- as with BabelFish (see just below), Google Translation and Extra Google Translation have their options this.alwaysTryWhenGGEnabled and this.alwaysTryWhenGGExtraEnabled.
- BabelFish behaviour : when enabled (with 'D' button menu or toolbar menu) BabelFish is by default always queried when selecting text. In file ODictCN.js, the option this.alwaysTryWhenBFEnabled allow you to change that : if it is false, BabelFish is only queried when nothing was found at dict.cn.
- there are some others options available in ODictCN.js, please refer to the comments in that file.
- select for translation with Double-Click will work only if you disable the "Double click text to display context menu" setting in "Preferences... > Advanced > Toolbars"
- if you experience slow scrolling when the small 'D' button is visible, and don't want to hide that small button as it is possible with toolbar buttons (see Installation instructions), you can edit the file ODictCN.js and set the value "this.fixSlowSmoothScroll" to true. It will change the way the 'D' button position is updated, to reduce the scrolling slowdown. Because of a Opera 9.5 redraw issue (it's better but not resolved in 9.6), the button will then "jump" a little each time you toggle something, please don't take care.
- By default, ODictCN uses the website "http://dict.cn" ; sometimes it is down, so you can also tell ODictCN to use instead the website "cn.dict.cn" ; for that, change the value "this.dictcn_server" in file ODictCN.js.
- the style of some ODictCN visible elements (popup and 'D' button in page) can be changed, for example opacity or color. See and change at your convenience those styles at the beginning of file ODictCN.js.














Anonymous # 28. September 2009, 16:55
thank you!
galanga # 23. October 2009, 18:47
I discovered that with Opera 10 it is necessary to have cookies enabled on the current webpage, otherwise ODictCN continuously stays disabled, cliking on the small 'D' button does nothing. So, until I can find a workaround, you will have to enable cookies on all the websites you want to use ODictCN on...