https://github.com/bergmark/transliterate
A library for ransliterating Korean Hangeul to the latin alphabet and vice versa. Can be used from Haskell, Fay, and JavaScript
https://github.com/bergmark/transliterate
Last synced: about 2 months ago
JSON representation
A library for ransliterating Korean Hangeul to the latin alphabet and vice versa. Can be used from Haskell, Fay, and JavaScript
- Host: GitHub
- URL: https://github.com/bergmark/transliterate
- Owner: bergmark
- License: bsd-3-clause
- Created: 2013-11-07T06:20:11.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2016-04-12T21:05:49.000Z (about 10 years ago)
- Last Synced: 2025-03-23T18:35:22.765Z (over 1 year ago)
- Language: Haskell
- Size: 84 KB
- Stars: 4
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
[Changelog](CHANGELOG.md)
The Korean alphabet Hangeul (South Korea), or Chosongul (North Korea) is a surprisingly simple system consisting of 24 letters (called jamo). Once you know these 24 letters you can pretty much read it! Each syllable is combined into one hangeul block. "an nyeong" means hello, this is two syllables and is written as "안녕". 안 = an, 녕 = nyeong. You read each block from the top left, to the right/middle, and then bottom, written out as separate characters this becomes ㅇ(silent) ㅏ(a) ㄴ(n) ㄴ(n) ㅕ(yeo) ㅇ(ng).
Learning to read hangeul is easy but when learning it's useful to have a tool that can do the transliteration for you so you can check that you are reading it correctly. Additionally, if you want to write Hangul on your non-korean keyboard it's pretty tricky. You need to switch keyboard layout, figure out which character you're supposed to type, and figure out where it is on the keyboard. The goal of this library is to help out in this process so you can simply type "an nyeong" and get the result printed out. Or in reverse, if you find "하스켈" somewhere the library will transliterate it back as "ha seu kel" and you can then hopefully figure out what it means.
This library is written in Haskell, but also compiles to JavaScript using Fay. Fay can also generate a JS wrapper for the library so you can use it as a normal JS library!
## Try it out!
#### Fay
[Fay compiled to JS](http://www.atmat.net/transliterate/test/FayTest.html)
Type "an nyeong" into the top text field, or paste "하스켈" into the bottom field to see it doing its thing.
#### JavaScript
The version where the UI is written in normal JavaScript is [here](http://www.atmat.net/transliterate/test/JsTest.html).
#### GHCi
```
$ cabal repl
λ> :set -XOverloadedStrings
λ> putStrLn . unpack $ toHangeul "an nyeong"
안녕
λ> putStrLn . unpack $ fromHangeul "하스켈"
ha seu kel
```
## Implementation
The main module is [Translit.Hangeul](src/Translit/Hangeul.hs), it's shared between GHC and Fay. There are GHC and Fay specific modules for some low level functionality where Fay uses the FFI and GHC the text and pcre packages.
The UI for browsers has two implementations, one in [Fay](test/FayTest.hs) and one in [JavaScript](test/JsTest.js). There's also a command line test that runs in both [GHCI and nodejs](test/Test.hs). They are short so I'll put them here for comparison:
```javascript
$(document).ready(function () {
var H = Strict.Translit.Hangeul;
var inp = jQuery("#inp");
var out = jQuery("#out");
inp.keyup(function () {
out.val(H.toHangeul(inp.val()));
});
out.keyup(function () {
inp.val(H.fromHangeul(out.val()));
});
});
```
```haskell
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RebindableSyntax #-}
module FayTestWeb where
import Fay.Text
import JQuery
import Prelude
import Translit.Hangeul
main :: Fay ()
main = ready $ do
inp <- select "#inp"
out <- select "#out"
(`keyup` inp) $ \_ -> do
t <- getVal inp
setVal (toHangeul t) out
return ()
(`keyup` out) $ \_ -> do
b <- getVal out
setVal (fromHangeul b) inp
return ()
```
## Future Plans
I also want to add transliteration for the japanese featural alphabets hiragana and katakana, and maybe others. Japanese kanji is of course not possible to do like this, it needs a dictionary.