-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path_.au3
More file actions
61 lines (55 loc) · 3.09 KB
/
_.au3
File metadata and controls
61 lines (55 loc) · 3.09 KB
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
; #INDEX# =======================================================================================================================
; Title .........: _Translate
; Description ...: Simple UDF to handle translation of multi-lingual strings
; Author ........: Damon Harris <TheDcoder@protonmail.com>
; ===============================================================================================================================
#include <FileConstants.au3>
#include <StringConstants.au3>
Global $__Translate_Map
; #FUNCTION# ====================================================================================================================
; Name ..........: _Translate_LoadTable
; Description ...: Load translations from an array or file
; Syntax ........: _Translate_LoadTable([$vTable = Default])
; Parameters ....: $vTable - [optional] File path to translation file generated by Extract.au3 script or an array (See Remarks).
; Return values .: Success: None
; Failure: Sets @error to non-zero
; Author ........: Damon Harris <TheDcoder@protonmail.com>
; Remarks .......: You can also supply a one dimensional array with element containing the original and translated strings seperated
; by a @TAB character. This array would be equal to what would be produced by FileReadToArray.
; ===============================================================================================================================
Func _Translate_LoadTable($vTable)
If Not IsArray($vTable) Then
Local $hFile = FileOpen($vTable, $FO_UTF8_NOBOM)
If $hFile = -1 Then Return SetError(1, @error)
$vTable = FileReadToArray($hFile)
If @error Then Return SetError(2, @error)
FileClose($hFile)
EndIf
$__Translate_Map = ObjCreate("Scripting.Dictionary")
If @error Then Return SetError(3, @error)
Local $iTabPos, $sOrig, $sTrans
For $i = 0 To UBound($vTable) - 1
If StringIsSpace($vTable[$i]) Then ContinueLoop
$iTabPos = StringInStr($vTable[$i], @TAB, $STR_NOCASESENSEBASIC)
$sOrig = StringLeft($vTable[$i], $iTabPos - 1)
$sTrans = StringTrimLeft($vTable[$i], $iTabPos)
If Not $__Translate_Map.Exists($sOrig) Then $__Translate_Map.Add($sOrig, $sTrans)
Next
EndFunc
; #FUNCTION# ====================================================================================================================
; Name ..........: _
; Description ...: Wrapper function for translatable strings
; Syntax ........: _($sStr[, $sKey = ""])
; Parameters ....: $sStr - The string.
; $sKey - [optional] Optional key to override the default string during lookup.
; Return values .: Translated $sStr or $sStr in absense of a translation
; Author ........: Damon Harris <TheDcoder@protonmail.com>
; ===============================================================================================================================
Func _($sStr, $sKey = "")
If $sKey = "" Then $sKey = $sStr
If IsObj($__Translate_Map) And $__Translate_Map.Exists($sKey) Then
Return $__Translate_Map.Item($sKey)
Else
Return $sStr
EndIf
EndFunc