Archive for 2007-01-15

KDE4 使用標準的 gettext 了

2007-01-15

在 KDE 早期,連 gettext 也未有複數格式的支援時,KDE 使用自創的 _n: 格式來表示複數:

msgid ""
"_n: Open %n file\n"
"Open %n files"
msgstr "開啟 %n 個檔案"

這個方案其實有很大問題。用甚麼來決定複數格式?是在 kdelibs 中某一個翻譯條目決定的:

msgid ""
"_: Dear translator, please do not translate this string in any form, but pick "
"the _right_ value out of NoPlural/TwoForms/French... If not sure what to do "
"mail thd@kde.org and coolo@kde.org, they will tell you. Better leave that out "
"if unsure, the programs will crash!!\n"
"Definition of PluralForm - to be set by the translator of kdelibs.po"
msgstr "NoPlural"

總括來說,一句定生死。可是麻煩的地方在於,中文是否永遠都沒有複數?不是!有時中文也會有複數形式的。說中文沒有複數,那只是指數字加量詞的情況,例如 1 horse, 2 horses 等等都變成「n 隻馬」而已。「你」的複數是「你們」,「她」的複數是「她們」,那些情形還是要分辨複數的,但就因為在 kdelibs 裏面的一句,就判定了中文絕對不能有複數。

但現在情況不同了。KDE4 使用 gettext 的標準方式表示複數,即是說在檔案的 header 加一句複數表示形式,不再由 kdelibs 判刑了。對於翻譯者來說,這真是喜訊一樁:

  1. 情況可以由每個檔案自行決定;
  2. 翻譯者不需要根據每種軟件分辨複數方式,減少了混亂

至於新的 gettext 的另一個格式 — msgctxt,則暫時仍沒有甚麼軟件用它。現在 gtk+ 和 qt 各用自己的格式為條目加上 context,但期望 gettext 0.15 較多人採用時,情況會改善。

Learning gnuplot

2007-01-15

As a test to see how much my maths sense has deteriorated, I’ve fetched 2006 Putnam exam and had a look at the questions.

The first question is supposed to be easiest, but what a shame, I don’t even know the formula to calculate volume of a convoluted shape without calculus, nor can I remember the way to do it in calculus as well. Here is the question:

Find the volume of the region of points LaTeX fragment such that

LaTeX fragment

Somebody has provided unofficial answer, which mentions Pappus’s Centroid Theorem, and conveniently states the answer without any calculus. Another shame that I didn’t manage to learn it during secondary school days.

In order to “save my face” a little bit, I picked up gnuplot and briefly learned how to plot 3D graph with it. Here is the answer to the question:

Solution to Putnam 2006 question A1

Some points to note however:

  1. Don’t use default x11 output if one wants to get anti-aliased graph. Use Postscript or SVG if possible.
  2. Always turn on hidden3d option, otherwise the graph becomes a flat entangled wool ball.

Here comes the script used to plot this doughnut graph:

set terminal svg size 500 350
set ticslevel 1
set ztics 0.5
set parametric
set urange [0:2*pi]
set vrange [0:2*pi]
set isosamples 100,50
set hidden3d
a=3
splot (a+cos(v))*cos(u),(a+cos(v))*sin(u),sin(v)

Save it somewhere (say answer.txt or whatever filename you like), and run this command to generate SVG graph:

gnuplot answer.txt > answer.svg

Use your favourite SVG viewer to open it. I recommend rsvg-view from librsvg, since it is a bare-bone viewer, and starts pretty quickly. Applications like inkscape is an overkill unless you want to add some retouch.