diff options
author | Philipp Gesang <pgesang@ix.urz.uni-heidelberg.de> | 2011-05-10 11:30:45 +0200 |
---|---|---|
committer | Philipp Gesang <pgesang@ix.urz.uni-heidelberg.de> | 2011-05-10 11:30:45 +0200 |
commit | adc06ec6e6e32fafe4e0689bd8a5e9d31000012e (patch) | |
tree | 304b83f7e8f27ced1f324b0de209088cfb6b41d8 | |
parent | 66589735535d45b9d1875b102060de9a42fa7008 (diff) | |
download | transliterator-adc06ec6e6e32fafe4e0689bd8a5e9d31000012e.tar.gz |
serbian transliteration tables & functions
-rw-r--r-- | tex/context/third/transliterator/trans_tables_sr.lua | 116 | ||||
-rw-r--r-- | tex/context/third/transliterator/transliterator.lua | 11 |
2 files changed, 122 insertions, 5 deletions
diff --git a/tex/context/third/transliterator/trans_tables_sr.lua b/tex/context/third/transliterator/trans_tables_sr.lua new file mode 100644 index 0000000..9abe5b2 --- /dev/null +++ b/tex/context/third/transliterator/trans_tables_sr.lua @@ -0,0 +1,116 @@ + +--===========================================================================-- +-- Serbian -- +--===========================================================================-- + + +if not translit.done_serbian then + -------------------------------------------- + -- Lowercase Serbian (Cyrillic -> Latin) -- + -------------------------------------------- + translit.sr_tolt_lower = translit.make_add_dict{ + ["А"] = "A", + ["Б"] = "B", + ["В"] = "V", + ["Г"] = "G", + ["Д"] = "D", + ["Ђ"] = "Đ", + ["Е"] = "E", + ["Ж"] = "Ž", + ["З"] = "Z", + ["И"] = "I", + ["Ј"] = "J", + ["К"] = "K", + ["Л"] = "L", + ["Љ"] = "Lj", + ["М"] = "M", + ["Н"] = "N", + ["Њ"] = "Nj", + ["О"] = "O", + ["П"] = "P", + ["Р"] = "R", + ["С"] = "S", + ["Т"] = "T", + ["Ћ"] = "Ć", + ["У"] = "U", + ["Ф"] = "F", + ["Х"] = "H", + ["Ц"] = "C", + ["Ч"] = "Č", + ["Џ"] = "Dž", + ["Ш"] = "Š", + } + + translit.tables["Serbian Cyr->Lat Transliteration lowercase"] = translit.sr_tolt_lower + + -------------------------------------------- + -- Uppercase Serbian (Cyrillic -> Latin) -- + -------------------------------------------- + + translit.sr_tolt_upper = translit.make_add_dict{ + ["а"] = "a", + ["б"] = "b", + ["в"] = "v", + ["г"] = "g", + ["д"] = "d", + ["ђ"] = "đ", + ["е"] = "e", + ["ж"] = "ž", + ["з"] = "z", + ["и"] = "i", + ["ј"] = "j", + ["к"] = "k", + ["л"] = "l", + ["љ"] = "lj", + ["м"] = "m", + ["н"] = "n", + ["њ"] = "nj", + ["о"] = "o", + ["п"] = "p", + ["р"] = "r", + ["с"] = "s", + ["т"] = "t", + ["ћ"] = "ć", + ["у"] = "u", + ["ф"] = "f", + ["х"] = "h", + ["ц"] = "c", + ["ч"] = "č", + ["џ"] = "dž", + ["ш"] = "š", + } + + translit.tables["Serbian Cyr->Lat Transliteration uppercase"] = translit.sr_tolt_upper + + local function __inverse_tab (t) + local result = { } + for k,v in next,t do result[v] = k end + return result + end + + translit.sr_tocy_lower = translit.make_add_dict(__inverse_tab(translit.sr_tolt_lower)) + translit.sr_tocy_upper = translit.make_add_dict(__inverse_tab(translit.sr_tolt_upper)) + + translit.done_serbian = true +end + +--===========================================================================-- +-- End Of Tables -- +--===========================================================================-- + +local t = translit +local function sr (mode, text) + local P, R, S, V, Cs = lpeg.P, lpeg.R, lpeg.S, lpeg.V, lpeg.Cs + local utfchar = translit.utfchar + local trl_sr = translit.make_add_dict{} + + trl_sr = t[mode.."_upper"] + t[mode.."_lower"] + + local _p_sr = translit.addrules (trl_sr, _p_sr) + local p_sr = Cs((_p_sr / trl_sr + utfchar)^0) + + return p_sr:match(text) +end + +translit.methods ["sr_tolt"] = function (text) return sr( "sr_tolt", text ) end +translit.methods ["sr_tocy"] = function (text) return sr( "sr_tocy", text ) end diff --git a/tex/context/third/transliterator/transliterator.lua b/tex/context/third/transliterator/transliterator.lua index ddda144..d794c05 100644 --- a/tex/context/third/transliterator/transliterator.lua +++ b/tex/context/third/transliterator/transliterator.lua @@ -83,7 +83,8 @@ end -- Generate a rule pattern from hash table. do - local P = lpeg.P + local P, R, V = lpeg.P, lpeg.R, lpeg.V + function translit.addrules (dict, rules) for i, _ in pairs(dict) do if rules == nil then rules = P(i) @@ -92,12 +93,9 @@ do end return rules end -end -- Modified version of Hans’s utf pattern (l-lpeg.lua). -do - local P, R, V = lpeg.P, lpeg.R, lpeg.V translit.utfchar = P{ V"utf8one" + V"utf8two" + V"utf8three" + V"utf8four", @@ -194,6 +192,7 @@ function translit.show_all_tabs () environment.loadluafile ("trans_tables_iso9") environment.loadluafile ("trans_tables_trsc") environment.loadluafile ("trans_tables_scntfc") + environment.loadluafile ("trans_tables_sr") environment.loadluafile ("trans_tables_trsc") environment.loadluafile ("trans_tables_glag") environment.loadluafile ("trans_tables_gr") @@ -227,7 +226,7 @@ end -- corresponding function. -- Those supposedly are the most frequently used so it won’t hurt to preload --- them. +-- them. The rest will be loaded on request. environment.loadluafile ("trans_tables_iso9") function translit.transliterate (method, text) @@ -245,6 +244,8 @@ function translit.transliterate (method, text) method == "ocs" or method == "ocs_gla" then environment.loadluafile ("trans_tables_scntfc") + elseif method:match("^sr_") then + environment.loadluafile ("trans_tables_sr") elseif method == "gr" or method == "gr_n" then environment.loadluafile ("trans_tables_gr") |