Java Programming for the Hawaiian Language - Amit Margalit

This document was contributed by Amit Margalit to the Hale Kuamo‘o, with the request that it be made available via Kualono. While we are grateful that he has researched this topic so thoroughly and makes them available to the public, the technology staff at Hale Kuamo‘o has not tested any of this work, and any questions or problems should be reported directly to Amit.

Foreword

This file was written for the benefit of anyone who wishes to program for the Hawaiian language. I tried to, in an effort to write myself little tools to help me practice my (still not so good) Hawaiian. If you use the tips in here and find them useful - I've done my share. If you drop me a line about it, I'd appreciate it.

Amit Margalit, amit@hawaii.timehelix.com

Introduction

At first, everything seemed OK. Until I created a TextField (actually a JTextField) and tried to type Hawaiian characters - ‘okina and vowels with kahakō. They don't come out right. In fact, they come out messed up completely.

There are in fact 3 issues to consider:

  1. Typing ‘okina and kahakō vowels with the Hawaiian Keyman.
  2. Typing ‘okina and kahakō vowels without the Hawaiian Keyman.
  3. Sorting order.

All of these have led me to create a fairly simple Java package for Hawaiian. It is explained below.

Typing ‘Okina and Kahakō Vowels with the Hawaiian Keyman

The attempt I made was to put a JTextField in an applet, and type the phrase 'E ola mau ka ‘ōlelo Hawaiʻi'. Everything went just fine until the ‘okina. It typed two strange characters. I added a keyListener for the keyTyped event, and examined the character that the KeyMan was generating. It was not an 8-bit entity. Looks more like a Unicode character. Unfortunately, the JTextField is not properly suited to dealing with mixed ANSI/Unicode strings.

The solution was to subclass the JTextField and create an HTextField that translates the Unicode characters into their ANSI equivalents. The core translation switch() statement is shown below. The entire source code is protected under the GPL, and will be provided by me upon request, free of charge, of course.

public static char hkeyToChar(char ch)
{
  switch(ch)
  {
    case 'u05d4': // ā
      ch = '344';
      break;
    case 'u05DB': // ē
      ch = '353';
      break;
    case 'u05DF': // ī
      ch = '357';
      break;
    case 'u05E6': // ō
      ch = '366';
      break;
    case 'uF895': // ū
      ch = '374';
      break;
    case 'u05B4': // ā
      ch = '304';
      break;
    case 'u05BB': // Ē
      ch = '313';
      break;
    case 'u05BF': // Ī
      ch = '317';
      break;
    case 'u05F2': // Ō
      ch = '326';
      break;
    case 'uF890': // Ū
      ch = '334';
      break;
    case 'uF896': // ‘
      ch = '377';
      break;
  }
  return ch;
}

Without the Hawaiian Keyman

The Hawaiian Keyman is all just fine, but what if we don't have one? Say we're writing a Java program for the Web or for Unix and have no way to ensure that a Hawaiian Keyman is present or any other means of creating the necessary characters for that matter. The Hawaiian package allows one to prefix a vowel (or a plain apostrophe) with a colon to signify that it should be considered a vowel with kahakō. Once the text is typed, it is easy to convert the string from the colon-vowel convention to the form it would have if a Hawaiian Keyman were present. This same form allows a string to be printed using a proper font.

For example, typing ':o' instead of 'ō'. A sentence such as 'E ola mau ka ‘ōlelo Hawaiʻi' can then be typed like this:

'E ola mau ka:':olelo Hawai:'i'.

Notice the colons before the apostrophe, and the 'o' for '‘ōlelo'.

Sorting Order

In fact, there are several ways to sort text in a program, depending on the text and language.

Hawaiian natural Order

The natural order in Hawaiian, as in the Māmaka Kaiao, is this:

  1. A, Ā (i.e. A comes before Ā which comes before E, etc.)
  2. E, Ē
  3. I, Ī
  4. O,Ō
  5. U, Ū
  6. H, K, L, M, N, P, W
  7. ‘ (‘okina)
  8. Non-Hawaiian letters in roman-alphabet order.

Compare Hawaiian Like English

This method is very similar to the Hawaiian natural order in that it does not ignroe the kahakō or the ‘okina, but the order of the letters is similar to English. Thus 'A' comes before 'ā' but after 'ā' comes 'B' , not 'E'. In other words, this method can be looked at as if it is plain English comparison, with the kahakō version of the vowels inserted after each of the vowels, and the ‘okina last.

Compare By Ignoring Hawaiian

This method, considers the kahakō version of the vowel to be equal to the non-kahakō vowel, and the ‘okina is completely ignored. This is done by using two temporary strings, which are a stripped-down copy of the original strings being compared. The down side of this method is that if you compare two words differing only by kahakō, the comparison is not consistent. Because of the nature of comparison which must place one word before the other, the comparison condition is either >= or <=. If the comparison is done as 'if word_a <= word_b' produces one result, but if it is done as 'if word_b >= word_a' produces the opposite result.

Hawaiian Language Package for Java

The package provides the following classes:

  • Hawaiian - This is a static-only class for Hawaiian language operations.
  • HLabel - A simple label that uses a Hawaiian font by default.
  • HTextField - A JTextField that uses a Hawaiian font and converts Keyman characters.
    • HTextArea - A JTextAre that uses a Hawaiian font and converts Keyman characters.
    • HOptionPane - An option dialog that uses a Hawaiian font.

Contact Me

If you want the source, or want to share information, feel free to drop me a line.

Amit Margalit, amit@hawaii.timehelix.com