มอดูล:eo-translit
หน้าตา
- The following documentation is generated by Module:documentation/functions/translit. [edit]
- Useful links: subpage list • links • transclusions • testcases • sandbox
This module will transliterate ภาษาเอสเปรันโต text.
The module should preferably not be called directly from templates or other modules.
To use it from a template, use {{xlit}}.
Within a module, use Module:languages#Language:transliterate.
For testcases, see Module:eo-translit/testcases.
Functions
[แก้ไข]tr(text, lang, sc)- Transliterates a given piece of
textwritten in the script specified by the codesc, and language specified by the codelang. - When the transliteration fails, returns
nil.
local export = {}
local gsub = mw.ustring.gsub
local lower = mw.ustring.lower
local c1 = {
-- ฉ & ฎ are dummies
["b"]="บ", ["c"]="ฉ", ["ĉ"]="ช", ["d"]="ด", ["f"]="ฟ", ["g"]="กฺ", ["ĝ"]="จ",
["h"]="ฮ", ["ĥ"]="ฅ", ["j"]="ย", ["ĵ"]="ฌ", ["k"]="ค", ["l"]="ล", ["m"]="ม",
["n"]="น", ["p"]="พ", ["r"]="ร", ["s"]="ซ", ["ŝ"]="ชฺ", ["t"]="ท", ["ŭ"]="ว",
["v"]="วฺ", ["z"]="ซฺ", ["dz"]="ฎ",
}
local v1 = {
["a"]="ั", ["e"]="↶เ", ["i"]="ิ", ["o"]="↶โ", ["u"]="ุ",
}
function export.tr(text, lang, sc, debug_mode)
if type(text) == "table" then -- called directly from a template
text = text.args[1]
end
text = require("Module:eo-spel").convert(text) -- converts X & H systems to common
text = lower(text)
text = gsub(text, "dz", c1["dz"]) -- do digraph first
text = gsub(text, "([bcĉdfgĝhĥĵkpsŝtvz])([lr])", "%1๎%2") -- -l & -r clusters
text = gsub(text, "([aeiou])r([^aeiou])", "%1ร์%2")
text = gsub(text, "([aeiou])r$", "%1ร์")
text = gsub(text, "aj([bcĉdfgĝhĥjĵklmnprsŝtvzŭ%s%p])", "↶ไ%1")
text = gsub(text, "aŭ([bcĉdfgĝhĥjĵklmnprsŝtvzŭ%s%p])", "↶เา%1")
text = gsub(text, "ej([bcĉdfgĝhĥjĵklmnprsŝtvzŭ%s%p])", "↶เย์%1")
text = gsub(text, "aj$", "↶ไ")
text = gsub(text, "aŭ$", "↶เา")
text = gsub(text, "ej$", "↶เย์")
text = gsub(text, ".", c1)
text = gsub(text, "([aeiou])([aeiou])([aeiou])", "%1อ%2อ%3")
text = gsub(text, "([aeiou])([aeiou])", "%1อ%2")
text = gsub(text, ".", v1)
text = gsub(text, "^([ัิุ↶])", "อ%1")
text = gsub(text, "([%s%p%d])([ัิุ↶])", "%1อ%2") -- also includes rare cases like 1a, 2an, 3aj, 4ajn
text = gsub(text, "([ัิุ])([ัิุ↶])", "%1อ%2")
text = gsub(text, "([ก-ฮ]ฺ?๎)([ก-ฮ]ฺ?)↶([เแโไ])", "%3%1%2")
text = gsub(text, "([ก-ฮ]ฺ?)↶([เแโไ])", "%2%1")
text = gsub(text, "ั$", "า")
text = gsub(text, "ั([%s%p])", "า%1")
text = gsub(text, "ิ$", "ี")
text = gsub(text, "ิ([%s%p])", "ี%1")
text = gsub(text, "ุ$", "ู")
text = gsub(text, "ุ([%s%p])", "ู%1")
text = gsub(text, "ั([ก-ฮ]ฺ?)([ัาิีุู๎])", "า%1%2")
text = gsub(text, "ิ([ก-ฮ]ฺ?)([ัาิีุู๎])", "ี%1%2")
text = gsub(text, "ุ([ก-ฮ]ฺ?)([ัาิีุู๎])", "ู%1%2")
text = gsub(text, "ั([ก-ฮ]ฺ?)([ัาิีุู๎])", "า%1%2") --twice
text = gsub(text, "ิ([ก-ฮ]ฺ?)([ัาิีุู๎])", "ี%1%2")
text = gsub(text, "ุ([ก-ฮ]ฺ?)([ัาิีุู๎])", "ู%1%2")
text = gsub(text, "ั([เแโไ])", "า%1")
text = gsub(text, "ิ([เแโไ])", "ี%1")
text = gsub(text, "ุ([เแโไ])", "ู%1")
text = gsub(text, "ั(ร์)", "า%1")
text = gsub(text, "ิ(ร์)", "ี%1")
text = gsub(text, "ุ(ร์)", "ู%1")
-- replace ฉ & ฎ to right ones
text = gsub(text, "ฉ", "ท͜ซ")
text = gsub(text, "ฎ", "ด͜ซฺ")
return text
end
return export