MozLCDB Manual

出自 MozTW Wiki

於 2005年2月7日 (一) 13:08 由 Kourge對話 | 貢獻 所做的修訂 File Format and Default Filenames 檔案格式和預設檔案名稱

由於有人在討論區上提議要把 piaip 的 MozLCDB 文件翻成中文,所以把大家翻的放到這邊。
該文件原文位於 http://moztw.org/tools/mozlcdb/
另外,請大家翻譯時,使用全形的標點符號(如 "," 和 "。" 而非 "," 或 ".")

MozLCDB: What is it? 什麼是 MozLCDB 呢?

MozLCDB is a tool made for localization of various Mozilla (Gecko) based products. It is designed to resolve issues introduced since Mozilla Firefox 1.0 branch, and a replacement for MozillaTranslator.

MozLCDB 是為了眾多基於 Mozilla (Gecko) 產品的本地化而設計的工具。它是為了解決由 Mozilla Firefox 1.0 產生的問題,也是 MozillaTranslator 的替代品。
by Milo

The author and "Why a new tool?" 關於作者以及「為何要用新工具」?

This is Hung-Te Lin, maintainer of Traditional Chinese Mozilla Localization and the famous "mozip" (a tool to make Win32 localized builds).

我是林弘德。Mozilla 正體中文本地化以及知名的 mozip (一個編譯 Win32 本地化版本的工具)的維護者。

I have been using MozillaTranslator for years (whether the official builds or my own tweaked versions) since Mozilla M14 (Milestone 14, not 1.4. The M series are older than Mozilla 0.6). During these years MT works O.K although more and more extra works have to be done because Mozilla locale structure changes all the time.

我從 Mozilla M14 (Milestone 14,不是 Mozilla 1.,M 系列比 Mozilla 0.6 還要早) 開始使用 MozillaTranslator(MT) 已經許多年了(不論是正式版本或是我修改過的)。這些年來 MT 都可正常運作,雖然由於 Mozilla 的 locale 架構經常改變,需要下更多額外的功夫。

Since the landing of Mozilla Firefox 1.0PR, localizers of Mozilla* suffered from the huge changes in Mozilla locale structure and new CVS requirements. Unfortunately, MozillaTranslator does not work anymore. Although MT has released new versions to solve issues, after trying MT5.04 I think it's time to develop a new tool which is more robust or I have to manually do many extra work for all versions. With my experience in localization, I proposed what I need and made a new tool, named MozLCDB. This name is a little weird because the better name 'MLDB' is already taken by others. Hmmm. Maybe MLD?

I'm not an perl guru so this script is not perfect nor elegant now, but it helped me to generate a working Firefox 1.0PR locale without too much effort (in comparision to fight with MozillaTranslator).

自從 Mozilla Firefox 1.0PR 推出後,Mozilla* 的許多本地化作者因為 Mozilla 的 locale 架構和新的 CVS 需求巨大的變化而遭遇許多麻煩。不幸地,MozillaTranslator 沒有用了。雖然 MT 發布新版本解決了很多問題,在用過 MT5.04 之後我認為是發展更加強大的新工具的時候了,否則我得爲新版本手動處理很多東西。我在本方化方面的經驗中,我檢討了我的訴求並且做了一套新工具,名為 MozLCDB。這個名稱是有點古怪,因為更好的名稱 「MLDB」已經有其他人使用了。嗯...可能可以叫 MLD?

我並不是 perl 高手因此這個 script 並不完美也不好看,但它讓我不須花太大功夫就能建立 Firefox 1.0PR 的 locale(與其與 MozillaTranslator 奮鬥)。 by tszkin, modded by Kourge

Features of MozLCDB MozLCDB 的功能

MozLCDB is focused to Mozilla Localization. In comparsion to MozillaTranslator, you'll notice that:

  • MozLCDB is just a perl script with command line only, no GUI.

You can (and you have to) edit all stuff with your favorite editor.

  • Targeted for Multiple Product maintaince.

That is, you can really localize Mozilla, Firefox, Thunderbird, Netscape, and keep only one instance for same chrome node.

  • Works for both CVS and downloaded ZIP language packs
  • The stored database is more human readable/editable
  • Single locale per database file. Does not support multiple locale (MT does).

You have to use multiple database files if you need multiple locale.

  • Easily modified if you understand Perl.

MozLCDB 主要用於 Mozilla 本地化。相比 MozillaTranslator 來說,你會注意到:

  • MozLCDB 是只有命令列模式(Command Line)的 perl script,沒有 GUI(圖形介面)。


  • 可以針對多個產品維護。

也就是說,你可以本地化 Mozilla、Firefox、Thunderbird、Netscape 而只需使用一個相同 Chrome 節點的實體。

  • 能與一起 CVS 協同工作及下載 ZIP 語言套件
  • 儲存的資料庫格式更可讓人讀寫。
  • 每個資料庫檔只支援一個 locale。不支援多 locale (MT 可以)。

假如你需要製作多個 locale,你要使用多個資料庫檔案。

  • 假如你了解 perl 語言,這支程式可是相當容易修改。

by a guest on the forums

Requirements 系統需求

You need these stuff:

  • Perl 5.8 or later versions
  • Your favorite editor (with the ability to open/save UTF-8, like VIM which is my own choice)
  • (optional) Any ZIP archiver if you want to use ZIP/JAR languagepack or if you want to import MozillaTralsator glossary
  • (optional) Python 2.0+ if you want to import MozillaTranslator glossary
  • (optional) Knowledge of Perl if you got problems or want to modify it


  • Perl 5.8 或以上版本
  • 你所偏好的編輯器 (要有能力開啟及儲存 UTF-8,比如我選擇的是 VIM)
  • (選用) 如果你要使用 ZIP 或是 JAR 語言套件或是你想匯入 MozillaTralsator 的詞庫,需要一個 ZIP 壓縮程式
  • (選用) 如果你想要匯入 MozillaTranslator 的詞庫,你需要 Python 2.0+
  • (選用) Perl 的相關知識,這樣你遇到問題才可以自行解決或是修改它

by Jose Sun

Download 下載

Get these files:

  • Latest version: Saturday, 02-Oct-2004 11:00:43 CST (hack on your own!)
  • Releases:
    • Version 0.2 (Stable, approved with FF1.0/TB0.8)
    • Version 0.1 (a little buggy)


  • 最新版本: 2004 年 8 月 2 日,星期六 11:00:43 CST (hack on your own!)
  • 釋出版本:
    • 版本 0.2 (穩定版本,FF1.0/TB0.8 測試通過)
    • 版本 0.1 (有些小臭蟲)

by Jose Sun

Background Knowledge 背景知識

This section explains the basic idea about MozLCDB. It helps you to understand it more although you may use it without knowing anything explained here. Yes, you can go to "Usage:" sections if you are in a hurry. However it is highly recommended to get things clear before you start.

這一節會解釋 MozLCDB 的基本概念。雖然你使用它的時候不需要任何底下說的知識,但是可以幫助你更了解它。是的,如果你趕時間的話可以直接到 "用法:" 這一節。但是無論如何我都強烈建議你在開始之前先把這些知識弄清楚。

Workflow 工作流程

I'm trying to explain the workflow of MozLCDB here. Don't worry about the terms quoted, they will be explained in following subsections.

Basically, MozLCDB works in this manner: MozLCDB tries to 'import' from a 'prepared directory' (pulled from CVS or ZIP language pack), then save and merge into a '(glossary) database'. If any new locale string or updated ones are found, these entries will be written to an 'input (editing) table'. You can then edit the input table to do localization. After everything is done, you have to 'update' the '(glossary) database' with your 'input (editing) table'. Then you can 'export' the locales to another 'prepared directory'. Finally, the 'prepared directory' will contain all the localized stuff.

我試著在這裡解釋 MozLCDB 的工作流程。不用擔心那些標記起來的術語,接下來的小節都會一一解釋。

基本上,MozLCDB 以這種方法運作:MozLCDB 會從 '已備妥目錄' (可以從 CVS 或 ZIP 語言套件取得)試著 '匯入' 資料,然後儲存並合併到 '(詞彙) 資料庫'。如果找到任何新的或更新過的 locale 字串,這些項目就會被寫入到 '輸入 (編輯) 表'。你可以編輯輸入表來進行本地化。一切都做完了以後,你必須用你的 '輸入 (編輯) 表' 來 '更新' 你的 '(詞彙) 資料庫'。接著你可以 '匯出' 那些 locale 到另一個 '已備妥目錄'。最後,'已備妥目錄' 會有所有本地化過的東西。

File Format and Default Filenames 檔案格式和預設檔案名稱

MozLCDB tries to record everything in a text file named 'mozlcdb.txt'. It is saved in perl Dump format, however it is still readble ( if you know a little perl) and also called as the 'glossary' (due to MT) or 'database'. And there's another format of input that MozLCDB can read: the input (editing) table. It is more human readble and looks like DOS/WIN INI or GNU PO format. The default file name of this kind file is 'current.txt'. When importing from and exporting to Mozilla locale directories, currently MozLCDB recognizes only DTD and ".properties" files.

MozLCDB 會試著在一個名為 'mozlcdb.txt' 的文件內紀錄所有東西。它是以 perl 的傾印(dump)格式儲存,不過還是可讀的 (如果你懂一點 perl),也被稱為 '詞彙' (照 MT 那樣) 或 '資料庫'。還有另外一種 MozLCDB 能讀取的格式:輸入 (編輯) 表。這種格式比較能給人看,而且看起來很像 DOS/WIN 的 INI 或 GNU 的 PO 格式。這種檔案的預設檔案名稱是 'current.txt'。當匯入自或匯出至 Mozilla locale 目錄時,MozLCDB 目前只辨認 DTD 和 ".properties" 檔案。

Import, Export, and Update 匯入、匯出、及更新

import means to read locales from Mozilla files into the database.
export means to write locales from database into real Mozilla files.
update means to read locales from an input (editing table) into the database.

Directory Structure 目錄結構

Mozilla locale is stored in a hierarchical directory structure, also refered as chrome node. So you will see a very long path like "locale/en-US/global/global.dtd" in the directory you pulled from CVS or extracted from a language pack. MozLCDB mostly runs with the level just after where 'en-US' sits, so whether you're working with CVS or language pack, you must move directories (or move mozlcdb program and files) and assign correct ROOT path to fit thie rule. Then it can be called as a 'prepared directory'. (P.S: Actually, you can run in any level of directories. But you may get problems if you work in that way.)


What's the ROOT? It's a PATH to help MozLCDB find corresponding locale path. For example, if my current directory is D:\Mozilla\LC (Win) or /home/moz/lc (UNIX) and my locale is in full path of D:\Mozilla\LC\locale\en-US\global\... or /home/moz/lc/locale/en-US/global/..., then you have to use ROOT as locale/en-US.

The procedure of 'Import'and Multiple Product '匯入'步驟和跨產品

What really happened when you 'import'? MozLCDB will scan and walk through all files inside the 'prepared directory' assigned by ROOT. Currently, only *.dtd and *.properties will be processed. All other files will be ignored.

When one DTD or properties file was found, MozLCDB first reads its content for the 'key's and original locales. If a key was not found (never seen), it will be inserted into database as a 'new' entry. If a key was found, MozLCDB will determine what to do depending on the original (en-US) locale message. If it is exactly same as some version recorded in database, it is considered a 'same' entry with no new entries introduced. If no entries with same original could be found, MozLCDB will append one entry with timestamp into database. This is the magic to make multiple product possible. We keep all versions of original messages.

The procedure of 'Export' '匯出'步驟

What really happened when you 'export'? MozLCDB will scan and walk through all files inside the 'prepared directory' assigned by ROOT. Currently, only *.dtd and *.properties will be processed. All other files will be ignored.

When one DTD or properties file was found, MozLCDB first reads its content for the 'key's and original locales, then try to lookup database to decide what localized string to put in. If you export with '-x', MozLCDB assume you are working with a clean original copy exactly just what you have imported, so it will check for existence of keys and original locale message. However, you may want to export to a working (trial) copy. In that usage, -x will warn and stop because original message is filled with your localized strings. In this case you may use '-X' which will not check for keys.