-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLangSwither.cls
115 lines (100 loc) · 3.37 KB
/
LangSwither.cls
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
END
Attribute VB_Name = "LangSwither"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Option Explicit
Private Const KEY_NAME As String = "Keys_title"
Public Enum Methods
byTag
byCaption
End Enum
Private height
Private keyPositions As Dictionary
Private languages As Dictionary
Private content As Dictionary
Private Sub class_initialize()
Dim KeyCount As Long, langCount As Long
KeyCount = initKeys
langCount = initLanguages
Debug.Print ("Lang Switcer created. Keys:" & KeyCount & " languages:" & langCount)
End Sub
Public Function getLangArr() As Variant
getLangArr = languages.Keys
End Function
Public Function setLang(language As String, Optional mode As Methods = Methods.byTag) As Long
If Not languages.Exists(language) Then
setLang = False
Exit Function
End If
Select Case mode
Case Methods.byTag
Dim arr
Set content = New Dictionary
arr = keysTitle.Offset(1, languages(language)).Resize(height, 1)
Dim i As Long
For i = LBound(keyPositions.Keys) To UBound(keyPositions.Keys)
content.Add keyPositions.Keys(i), arr(keyPositions(keyPositions.Keys(i)), 1)
Next i
setLang = True
Case Methods.byCaption
Debug.Print ("WIP! Please waiy for updates")
setLang = False
End Select
End Function
Public Sub executeUserForm(form As Object)
Dim element As Object
executeControl form
For Each element In form.Controls
executeControl element
Next element
End Sub
Private Sub executeControl(element As Object)
If Not IsEmpty(element.Tag) Then
If content.Exists(element.Tag) Then
element.Caption = content(element.Tag)
End If
End If
End Sub
Private Function keysTitle() As Range
Set keysTitle = ThisWorkbook.Names(KEY_NAME).RefersToRange
End Function
Private Function initKeys() As Long
Dim keysRange As Range
Set keysRange = undertitle(keysTitle.Cells(1))
height = keysRange.Rows.Count
Set keyPositions = New Dictionary
Dim i As Long
For i = 1 To keysRange.Rows.Count
If Not IsEmpty(keysRange.Cells(i).Value2) Then
If Not keyPositions.Exists(keysRange.Cells(i)) Then
keyPositions.Add keysRange.Cells(i).Value2, i
End If
End If
Next i
initKeys = keyPositions.Count
End Function
Private Function initLanguages() As Long
Dim langRange As Range
Set langRange = rightTitle(keysTitle.Cells(1))
Set languages = New Dictionary
Dim i As Long
For i = 1 To langRange.Columns.Count
If Not IsEmpty(langRange.Cells(1, i)) Then
languages.Add langRange.Cells(1, i).Value2, i
End If
Next i
initLanguages = langRange.Count
End Function
Private Function rightTitle(r As Range)
Set rightTitle = r.Parent.Range(r.Offset(0, 1), _
r.EntireRow.Columns(r.EntireRow.Columns.Count).End(xlToLeft))
End Function
Private Function undertitle(r As Range) As Range
Set undertitle = r.Parent.Range(r.Offset(1, 0), _
r.EntireColumn.Rows(r.EntireColumn.Rows.Count).End(xlUp))
End Function