FreeBSD and Japanese text

In our last episode, I showed how to get FreeBSD 7.2 with Gnome working with SCIM-Anthy, thus allowing people to type Japanese. But despite getting this working I ran into some other internationalization issues:

  • Text-based browsers still didn’t work.
  • Text-editors still didn’t work.

Text-based browsers

Text-based web browsers have come a long ways from when I frequently used them in college on the local UNIX terminals. Lynx has been the de facto standard, but I’ve struggled these days to make it work with international characters, particularly Japanese, so I recently discovered w3m, which was written by a Japanese developer and boasts some nice features.

When I installed as a package, I found the Japanese text was still unreadable, so I realized that I had to compile from FreeBSD ports with extra options. I did it like so:

Compile w3m from ports:

  1. cd /usr/ports/www/w3m
  2. make -DJAPANESE -DM17N -DINLINE_IMAGE install clean

Also remember to set the default LANG variable to en_US.UTF-8 for your user account in .profile, .cshrc or .bashrc depending on which shell you use. More details of this are found here in the FreeBSD online manual.

Finally, w3m works best when the terminal screen is wide enough. If not, the format kind of runs together and looks awkward. This is true with a graphical web browser as well. ;) The author recommends a terminal window of at least size 110×45, which can be set for your terminal window easily enough.

Once done you can read Japanese through w3m nicely. Here’s what my blog looks like:

FreeBSD 7.2 with w3m and vim

I like w3m’s inline image feature particularly. That alone is pretty cool. The terminal on the right demonstrates using vim to view a text file with Japanese in it. See section below for details.

One other tip with w3m: I noticed that depending on the settings of your computer, w3m will render pages better if you set it to EUC charset by default using the ‘-e’ flag. Even the author recommends in the FreeBSD port build that setting a EUC-JP charset by default for your account is a recommended, but UTF8 seems to work fine for the most part. Forcing EUC-JP causes other rendering issues if it’s not needed.

Text-based editors

By default, FreeBSD uses nvi as a text-editor, the classic Berkeley vi-editor, but development of this application is pretty infrequent, and seems to not work well with Japanese. Others across the web recommend installing vim-lite instead. I found that installing as a package was sufficient as the default install worked right away.

Next, set up an alias so that alias vi=vim, whereby vim is used by default anytime you want to use vi. As with the $LANG variable mentioned in the previous section, this can go into .profile, .cshrc or .bashrc depending on which shell you use.

Now if you want to test this, use vim to edit a new file and copy/past this text into there:


This is the opening line of a famous Japanese Buddhist epic, the Tales of the Heike from the 13th century.1

Save the text file, and see if you can view it with something like less or view. You should see the text as-is, which means things are working well.

Good luck!

1 My translation, poor as it is, would be “The Bell of the Gion Monastery resounds with the sound of impermanence of all phenomena.”

Be the first to like this post.

Leave a Reply

Gravatar Logo
Twitter picture

You are commenting using your
Twitter account. (Log Out)

Facebook photo

You are commenting using your
Facebook account. (Log Out)

Connecting to %s