Module:xdq-translit

Hello, you have come here looking for the meaning of the word Module:xdq-translit. In DICTIOUS you will not only get to know all the dictionary meanings for the word Module:xdq-translit, but we will also tell you about its etymology, its characteristics and you will know how to say Module:xdq-translit in singular and plural. Everything you need to know about the word Module:xdq-translit you have here. The definition of the word Module:xdq-translit will help you to be more precise and correct when speaking or writing your texts. Knowing the definition ofModule:xdq-translit, as well as those of other words, enriches your vocabulary and provides you with more and better linguistic resources.

This module will transliterate Kaitag language text per WT:XDQ TR. 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:xdq-translit/testcases.

Functions

tr(text, lang, sc)
Transliterates a given piece of text written in the script specified by the code sc, and language specified by the code lang.
When the transliteration fails, returns nil.

local export = {}
local m_str_utils = require("Module:string utilities")
local gsub = m_str_utils.gsub
local sub = m_str_utils.sub
local upper = m_str_utils.upper
local lower = m_str_utils.lower
local len = m_str_utils.len

local letters = {
   = "m",  = "n",  = "b",  = "d",  = "g",
   = "p",  = "t",  = "k",  = "q",  = "ʼ",
   = "c",  = "č",
   = "v",  = "z",  = "ž",  = "ɣ",
   = "s",  = "š",  = "x",  = "χ",  = "h",
   = "r",  = "l",  = "y",
   = "i",  = "u",  = "e",  = "a",  = "o",  = "æ",

  -- Ejectives
   = "ṗ",  = "ṭ",  = "ḳ",  = "q̇",
   = "c̣",  = "č̣",
  
  -- Dialectal letters
   = "ʡ",  = "ħ",
}

-- Generate upper-case and title-case variants
local mappings = {}
for k, v in pairs(letters) do
  mappings = v
  mappings = upper(v)
  if len(k) == 2 then
    mappings = gsub(v, "^.", upper)
  end
end

function export.tr(text, lang, sc)
  local result = {}
  local i = 1

  while i <= len(text) do
    local one = sub(text, i, i)
    local two = one .. sub(text, i + 1, i + 1)
      
    local mapped = one
    if two ~= one and mappings then
      mapped = mappings
      i = i + 1 -- Skip next character if digraph matched
    elseif mappings then
      mapped = mappings
    end
    
    table.insert(result, mapped)
    i = i + 1
  end

  return table.concat(result)
end

return export