init
This commit is contained in:
parent
d435e1775f
commit
4a52c88273
2
LICENSE
2
LICENSE
@ -75,7 +75,7 @@ If you develop a new program, and you want it to be of the greatest possible use
|
||||
|
||||
To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
translit Copyright (C) 19yy Datenlabor
|
||||
translit Copyright (C) 19yy Tank
|
||||
|
||||
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version.
|
||||
|
||||
|
||||
41
README.md
41
README.md
@ -1,3 +1,40 @@
|
||||
# translit
|
||||
# Транслитерация с кириллицы на английский и обратно (Cyrillic-to-English and English-to-Cyrillic transliterator)
|
||||
|
||||
Cyrillic-to-English and English-to-Cyrillic transliterator
|
||||
## Установка (Install)
|
||||
|
||||
```
|
||||
luarocks install translit
|
||||
|
||||
```
|
||||
|
||||
## Использование (Usage)
|
||||
|
||||
### Транслитерация с киррилицы на английский (Cyrillic-to-English)
|
||||
|
||||
```
|
||||
local translit = require('translit')
|
||||
|
||||
local en_str = translit.en('Русский текст')
|
||||
|
||||
```
|
||||
|
||||
### Транслитерация с киррилицы на русский (English-to-Cyrillic)
|
||||
|
||||
```
|
||||
local translit = require('translit')
|
||||
|
||||
local cy_str = translit.cy('English text')
|
||||
|
||||
```
|
||||
|
||||
### Использование для URL (slug)
|
||||
|
||||
```
|
||||
local function sluger(title)
|
||||
local slug = translit.en(title)
|
||||
slug = string.gsub(slug,'%s','-')
|
||||
slug = string.gsub(slug,'[^%w-]','')
|
||||
return string.lower(slug)
|
||||
end
|
||||
|
||||
```
|
||||
|
||||
11
test.lua
Normal file
11
test.lua
Normal file
@ -0,0 +1,11 @@
|
||||
local translit = require('translit')
|
||||
|
||||
local str = 'Русский текст'
|
||||
|
||||
local en_str = translit.en(str)
|
||||
|
||||
print(en_str)
|
||||
|
||||
local ru_str = translit.ru(en_str)
|
||||
|
||||
print(ru_str)
|
||||
27
translit-1.0-0.rockspec
Normal file
27
translit-1.0-0.rockspec
Normal file
@ -0,0 +1,27 @@
|
||||
package = "translit"
|
||||
version = "1.0-0"
|
||||
source = {
|
||||
url = "git+https://gitlabor.ru/Tank/translit",
|
||||
tag = "1.0-0"
|
||||
}
|
||||
description = {
|
||||
summary = "Cyrillic-to-English and English-to-Cyrillic transliterator",
|
||||
detailed = [[
|
||||
Cyrillic-to-English and English-to-Cyrillic transliterator. Транслитерация с киррилицы на английский и обратно.
|
||||
]],
|
||||
homepage = "https://gitlabor.ru/Datenlabor/translit",
|
||||
license = "MIT/X11"
|
||||
}
|
||||
dependencies = {
|
||||
"lua >= 5.1",
|
||||
"utf8 >= 1.2"
|
||||
}
|
||||
external_dependencies = {
|
||||
|
||||
}
|
||||
build = {
|
||||
type = "builtin",
|
||||
modules = {
|
||||
["translit"] = "translit.lua",
|
||||
}
|
||||
}
|
||||
74
translit.lua
Normal file
74
translit.lua
Normal file
@ -0,0 +1,74 @@
|
||||
--[[
|
||||
Copyright 2025 datenlabor <admin@datenlabor.ru>
|
||||
|
||||
Readme: https://gitlabor.ru/Datenlabor/translit
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA.
|
||||
|
||||
|
||||
--]]
|
||||
|
||||
local utf8 = require('lua-utf8')
|
||||
|
||||
local _M = {}
|
||||
|
||||
local function replace(str,data)
|
||||
for k,v in pairs(data) do
|
||||
str = utf8.gsub(str,k,v)
|
||||
end
|
||||
return str
|
||||
end
|
||||
|
||||
function _M.en(input)
|
||||
local gost = {
|
||||
['а']='a',['б']='b',['в']='v',['г']='g',['д']='d',['е']='e',
|
||||
['ё']='yo',['ж']='j',['з']='z',['и']='i',['й']='i',['к']='k',
|
||||
['л']='l',['м']='m',['н']='n',['о']='o',['п']='p',['р']='r',
|
||||
['с']='s',['т']='t',['у']='y',['ф']='f',['х']='h',['ц']='c',
|
||||
['ч']='ch',['ш']='sh',['щ']='sh',['ы']='i',['э']='e',['ю']='u',
|
||||
['я']='ya',['А']='A',['Б']='B',['В']='V',['Г']='G',['Д']='D',
|
||||
['Е']='E',['Ё']='Yo',['Ж']='J',['З']='Z',['И']='I',['Й']='I',
|
||||
['К']='K',['Л']='L',['М']='M',['Н']='N',['О']='O',['П']='P',
|
||||
['Р']='R',['С']='S',['Т']='T',['У']='Y',['Ф']='F',['Х']='H',
|
||||
['Ц']='C',['Ч']='Ch',['Ш']='Sh',['Щ']='Sh',['Ы']='I',['Э']='E',
|
||||
['Ю']='U',['Я']='Ya',['ь']='',['Ь']='',['ъ']='',['Ъ']='',['ї']='j',
|
||||
['і']='i',['ґ']='g',['є']='ye',['Ї']='J',['І']='I',['Ґ']='G',['Є']='YE'
|
||||
}
|
||||
return replace(input, gost)
|
||||
end
|
||||
|
||||
|
||||
function _M.cy(input)
|
||||
local gost = {
|
||||
['ch']='ч',['sh']='ш',['sh']='щ',['YS']='ЫС',['Yo']='Ё',['yo']='ё',
|
||||
['YE']='Е',['SH']='Щ',['YA']='Я',['CH']='Ч',['SH']='Ш',
|
||||
['Ch']='Ч',['Sh']='Ш',['Sh']='Щ',['Ya']='Я',['JA']='Я',
|
||||
['JS']='ЙС',['ZH']='Ж',['ya']='я',['ye']='э',['a']='а',
|
||||
['b']='б',['v']='в',['g']='г',['d']='д',['e']='е',['j']='ж',
|
||||
['z']='з',['i']='и',['i']='й',['k']='к',['l']='л',['m']='м',
|
||||
['n']='н',['o']='о',['p']='п',['r']='р',['s']='с',['t']='т',
|
||||
['y']='у',['f']='ф',['h']='х',['c']='ц',['i']='ы',['e']='е',
|
||||
['u']='у',['A']='А',['B']='Б',['V']='В',['G']='Г',['D']='Д',
|
||||
['E']='Е',['J']='Ж',['Z']='З',['I']='И',['K']='К',['L']='Л',
|
||||
['M']='М',['N']='Н',['O']='О',['P']='П',['R']='Р',['S']='С',
|
||||
['T']='Т',['Y']='Ы',['F']='Ф',['H']='Х',['C']='Ц',['E']='Е',
|
||||
['U']='У',["'"]='ь',["'"]='Ь',["''"]='ъ',["''"]='Ъ',['j']='ї',
|
||||
['i']='и',['g']='ґ',['G']='Г'
|
||||
}
|
||||
return replace(input, gost)
|
||||
end
|
||||
|
||||
return _M
|
||||
Loading…
x
Reference in New Issue
Block a user