Part of Nobumi Iyanaga's website. n-iyanag@ppp.bekkoame.or.jp. 11/29/98.

logo picture

Multilingual web page in Unicode

This page is in Unicode (UTF-8). To read its content, you need to use Netscape Communicator 4.0x or higher, or Microsoft Internet Explorer 4.0x or higher. Thank you.

Second release
november 29, 1998

Go to English ReadMe


日本語 ReadMe

Netscape Communicator 4.0x と Microsoft Internet Explorer 4.0x が Unicode に対応したので、多言語の web page が簡単に見られるようになりました(Netscape は UTF-8 と UTF-7 に対応していますが、IE は UTF-8 だけのようです)。また、これで、多言語の web page を作ることもできるようになりました。ただ問題は、それぞれの言語を正しく Unicode (UTF-8) に変換することです。

Mac には、Text Encoding Converter というプログラムがシステムにバンドルされていて、ほとんどあらゆる文字コードがあらゆる文字コードに変換することができます(Netscape, IE などのブラウザも、これを使って Unicode のソースを各 language kit の文字コードに変換し、表示しているものと思います)。ただ、Text Encoding Converter にはユーザー・インターフェースがまったくないので、普通、エンド・ユーザーはこれを使うことができません。ありがたいことに、飯森英明さん(iimori@libri.bekkoame.ne.jp )作の TEC OSAX が、これに非常に使いやすいインターフェースをつけているので、AppleScript や UserLand Frontier などから使えば、Text Encoding Converter を操作することができます。
とくに最新のヴァージョン 1.2b1 では、
StyledText2Unicode
TextClipping2Unicode
および
Unicode2TextClipping
Unicode2StyledText
という四つのコマンドが加わり、Styled Text(SimpleText や Tex-Edit Plus などのテキストがこれに当たります。'styl' リソースに font/size/face/color などの情報を含んでいます)を直接 Unicode に変換したり、Unicode から Styled Text に変換できるようになりました。
しかし、Styled Text 以外の「ピュア」な文字列では、現在処理中の文字列がどの文字コードに当たるかを自動的に判定することはできないので(ただし、一部の2バイトコードについては、ある程度可能ですが)、正しい変換をするには、文字列のコードを explicit に与えてやる必要があります。そのための1つの方法として、language tag というものを考えました。

Language tag でマーク・アップしたテキストの一例を挙げると:

This is a test page. <language="japanese">あいうえお</language> <language="roman"> Ce fut un bel été! </language>

<language="traditional chinese">依般若波羅蜜多故。心無罣礙。無罣礙故。無有恐怖。遠離一切顛倒夢想。</language> Quelle bonne surprise!

これを、スクリプトでパースし、language tag で切り分けて、正しい「元言語」のパラメータを TECConvertText に与えてやるわけです。たとえば、「<language="japanese">あいうえお</language>」なら

TEC.convertText ( "あいうえお", "X-MAC-JAPANESE", "UTF-8")

というふうになります。

今のところ、サポートしているのは
<language="japanese">xxxxxx</language>
<language="traditional chinese">xxxxxxxxx</language>
の二つ、および
<language="roman">xxxxxxxx</language>
だけですが、ほかのコードも簡単に付け加えられます。

Language tag は1行以上にまたがることはできません(前の行が日本語、次の行も日本語、という場合でも、各行の始めと終わりに <language="japanese"> と </language> を置く必要があります)。また language tag を入れ子にすることもできません。

<language="roman"> は特殊なタグで、いわゆる higher ASCII の文字を html entity (&eacute; などの形)に置き換えるためのものです(普通の英語だけなら、必要ありません)。

HTML 文書の <title>xxxx</title> のなかに language tag が入る場合は、変換後に手動で削除する必要があります。それ以外は、language tag はブラウザに「認識されない」ので、そのまま残しておいてかまいません(好みによって <!-- language="japanese" -->xxxx<!-- /language --> のように、コメントの形にしてもいいでしょう)。Language tag を残しておけば、あとで Unicode から、各言語の文字コードに再変換しやすいので、むしろ残しておいた方がいいと思います。

なお、UTF-8 の html 文書は、

<meta http-equiv="content-type" content="text/html; charset=unicode-2-0-utf-8">.

という形で、meta tag に charset を定義しておく必要があるようです。

現状で、多言語の web page を作る最善の方法は、Nisus Writer のような多言語ワープロ、またはエディタを用いて(html tag や language tag を入れた)ページを書き、最後にここに公開するツールのどれかを使って UTF-8 に変換することだろうと思います。


ここで最初に公開するのは、MacPerl (または MacJPerl )の droplet です( ここから (8K to download) ダウンロードして下さい)。これは非常に単純なスクリプトで、TEC OSAX と Tanaka's OSAX がインストールされていることを前提としています(しかし、なんのエラー・チェックもしていないので、どうぞ注意して使って下さい)。これはまだ充分テストしていませんし、あるいはクラッシュすることもあるかもしれません。使用するときは充分注意して下さい。

現状では、一度に一つだけのファイルしか処理できません。ファイルをドラッグ&ドロップでアイコン上にのせると、標準ファイル・ダイアローグが出て、変換後のテキストの保存場所を聞いてきます(デフォルトは、元のファイルと同じフォルダー内の同じファイル名+ ".uni" という拡張子です)。できたファイルは、Jedit 2.0x の形式になっています(Jedit 2.0x は Unicode に対応しています)。

現在サポートしている言語の表記は、上記のように:
japanese
traditional chinese
roman

の三つだけですが、これは簡単に増やすことができます(getFromCode というサブルーチンを参照して下さい)。

このスクリプトは非常に遅いです。その最大の理由は MacPerl の中から AppleScript を呼んでいるためですが、TEC の変換自体もあまり速くはありません。AppleScript の代わりに、直接 AppleEvent を使えればだいぶ速くなるはずですが、やり方がよくわかりません。どなたか、やり方を御存知の方がありましたら、ぜひお教え下さい。

なお、スクリプトには最低限の説明しかありません。このページをダウンロードして、あとで参照できるようにして下さい。


もう一つ、Frontier で同じことをするスクリプト(v. 1.0a2)を公開しました( ここから (10K to download) ダウンロードして下さい)。こちらは、UTF-8 のテキストを「伝統的」な文字コードに復元するスクリプトも入っています。


また先に述べた TEC OSAX 1.2b1 の Styled Text と Unicode 間の変換を行なう新コマンドを使った AppleScript の droplet (13K to download) と Frontier の droplet (52K to download) を作りましたので、それらも御利用下さい。AppleScript の droplet を使うには、TEC OSAX 最新ヴァージョンのほかに Tanaka's OSAX が必要です(AppleScript の droplet は、ほとんどエラー・チェッをしていないので、注意して使って下さい)。また Frontier の droplet は、上に述べた Frontier の unicodeConversion suite がインストールされていることを前提としています。

1998 年 11 月 25 日
1998 年 11 月 29 日
弥永信美


English ReadMe

Now that Netscape Communicator 4.0x and Microsoft Internet Explorer 4.0x support Unicode (it seems that Netscape supports UTF-8 and UTF-7, while IE supports only UTF-8...), we can read easily multilingual web pages. And It is also possible to create multilingual web pages. The only problem is the right conversion of multilingual text to Unicode.

Fortunately, on the Mac, there is Text Encoding Converter, which can convert almost from any encoding to any encoding. This has no user interface at all; but Hideaki Iimori (iimori@libri.bekkoame.ne.jp) created an excellent OSAX, named TEC OSAX, which provides a very convenient interface to Text Encoding Converter.
The latest version of TEC OSAX (1.2b1) has the following new commands:
StyledText2Unicode
TextClipping2Unicode
and
Unicode2TextClipping
Unicode2StyledText
With these additions, we can now convert automatically multilingual styled text files or text clippings to Unicode, and convert Unicode string to styled text files or text clippings (applications such as SimpleText or Tex-Edit plus create file of styled text. These files contain styl resource, in which are stored informations about font/size/face/color, etc.).
But when dealing with "pure" text, TEC OSAX cannot recognize automatically which is the encoding of a given string (although it can do it for some double-byte encodings: X-MAC-JAPANESE, X-MAC-CHINESETRAD, X-MAC-KOREAN, X-MAC-CHINESESIMP, JIS_C6226-1983, GB_2312-80, KS_C_5601-1987, ISO-2022-JP, ISO-2022-CN, ISO-2022-KR, EUC-JP, GB2312, X-EUC-TW, EUC-KR, Shift_JIS, Big5, HZ-GB-2312). To make it work properly, we must markup explicitly our text. Here is a very simple implementation that I propose.

You will markup your text with the "language tags". Here is an example:

This is a test page. <language="japanese">あいうえお</language> <language="roman"> Ce fut un bel été! </language>

<language="traditional chinese">依般若波羅蜜多故。心無罣礙。無罣礙故。無有恐怖。遠離一切顛倒夢想。</language> Quelle bonne surprise!

Our script will parse the text, splitting it by the language tags, and pass the right parameter to TEC.convertText (). For example, if a string is marked "japanese", it is sent to TEC.convertText () in this form:

TEC.convertText (my_string, "X-MAC-JAPANESE", "UTF-8")

In this implementation, the language tag must begin in a line, and end in the same line. This means that even if you have for example two consecutive lines of Japanese text, each of the lines must begin with <language="japanese"> and end with </language>.

The language tag "roman" is a special one: the string inside this tag will be "ISO 8859 encoded", with the html entities. So, if your string is in plain ASCII, without accented characters, you don't need to mark it up at all.

If your <title>xxx</title> tag contains language tag, it must be removed after the conversion. Otherwise, they may remain in html text, because language tags are not recognized, and are ignored by the browsers. I think it is better to leave them (perhaps in a html comment form, i.e. <!-- language="japanese" -->xxxxxxx<!--/language-->, etc.), because with them it will be easy to reconvert the text into the "traditional" encodings...

One more thing: html page in UTF-8 must contain this charset meta-tag:

<meta http-equiv="content-type" content="text/html; charset=unicode-2-0-utf-8">.

I think that the best way to create multilingual web pages is to use some multilingual editor or word-processor, such as Nisus Writer , to write and edit the original pages (with all the html tags and "language tags"), and convert them into UTF-8 with using of the tools that I release here...


The first implementation that I release is a very simple MacPerl (or MacJPerl) droplet (download here (8K to download)). It requires TEC OSAX and Tanaka's OSAX (the script does not check if they are installed. So please be careful...!). It is not tested extensively, and it may even cause crashes. Again, please be careful !

You can drag-and-drop only one file at once; a standard file dialog will ask you where you want to save the converted file (the defaul being in the same folder, with the same name appended by the extension ".uni"). The result file will be a text file of Jedit 2.0x, a Japanese editor which supports Unicode.

The language notations supported now are:
japanese
traditional chinese
roman

You can easily add other languages if you want... (see the sub-routine named "getFromCode").

This script is very slow, mainly because it calls AppleScript from inside MacPerl (and also, because the conversion process itself is slow). If you know how to use AppleEvent to call TEC OSAX and Tanaka's OSAX from MacPerl script, please let me know. The script will be much faster...

The script contains only a minimum explanation. Please download this page and keep it!


And here is a UserLand Frontier implementation of this conversion system (v. 10.a2. download here (10K to download)download here). This suite contains a script which does the reverse: it reconvert to "traditional encodings" multilingual UTF-8 text.


I add now some AppleScript droplets (13K to download) and Frontier droplets (52K to download) to this collection of conversion utilities. They use the newly added TEC OSAX commands mentioned above, which convert styled text files or text clippings to Unicode (UTF-8) and Unicode string to styled text files of text clippings. The AppleScript droplets use also Tanaka's OSAX (these scripts don't do almost any error checking. Please use them with caution!).
On the other hand the Frontier droplets suppose that my unicodeConversion suite is installed.

I hope these additions are useful for you!

november 25, 1998
november 29, 1998
Nobumi Iyanaga


Go to NI Frontier Page
Go to Home Page


Mail to Nobumi Iyanaga


frontierlogo picture

This page was last built with Frontier on a Macintosh on Sun, Nov 29, 1998 at 23:59:52. Thanks for checking it out! Nobumi Iyanaga