' LangID = 0 - русский, 1 - украинский
Function Translit( sRusString As String, LangID As Integer ) As String
Translit = ""
Const sRuAlph$ = {а,б,в,г,д,е,ё,ж,з,и,й,к,л,м,н,о,п,р,с,т,у,ф,х,ц,ч,ш,щ,ъ,ы,ь,э,ю,я}
Const sRu2EnAlph$ = {a,b,v,g,d,e,jo,zh,z,i,j,k,l,m,n,o,p,r,s,t,u,f,h,c,ch,sh,shc,`,y, ,je,y,y}
Const sUaAlph$ = {а,б,в,г,д,е,є,ж,з,и,і,ї,й,к,л,м,н,о,п,р,с,т,у,ф,х,ц,ч,ш,щ,ю,я}
Const sUa2EnAlph$ = {a,b,v,g,d,je,e,zh,z,y,i,ji,j,k,l,m,n,o,p,r,s,t,u,f,h,c,ch,sh,shc,y,y}
If Len( sRusString ) = 0 Then Exit Function
Dim sFrom(0 To 1) As String, sTo(0 To 1) As String
sFrom(0) = sRuAlph
sFrom(1) = sUaAlph
sTo(0) = sRu2EnAlph
sTo(1) = sUa2EnAlph
Dim aFromLC As Variant, aToLC As Variant
Dim aFromUC As Variant, aToUC As Variant
Dim aTo As String
Dim i As Integer, j As Integer
aFromLC = Split ( Lcase(sFrom(LangID)), |,| )
aToLC = Split ( Lcase(sTo(LangID)), |,| )
aFromUC = Split ( Ucase(sFrom(LangID)), |,| )
aToUC = Split ( Ucase(sTo(LangID)), |,| )
aTo = sRusString
For i = 1 To Len(sRusString ) ' для каждого символа строки
For j = 0 To Ubound( aFromLC )
If Instr( Lcase( Mid( sRusString, i, 1 ) ) , Lcase( aFromLC(j) ) ) > 0 Then
' если для ниж. регистра
If Instr( Mid(sRusString, i, 1 ) , aFromLC(j) ) > 0 Then aTo = Implode( Split( aTo, aFromLC(j) ), aToLC(j) )
' если для верх. регистра
If Instr( Mid(sRusString, i, 1 ) , aFromUC(j) ) > 0 Then aTo = Implode( Split( aTo, aFromUC(j) ), aToUC(j) )
End If
Next
Next
Translit = aTo
End Function