View Full Version : Internationalisation Module for Access


ozinm
02-03-2012, 03:15 AM
This is a simple module with functions that allow you to change captions, labels, etc. in your access interface depending on the current user's locale.
It relies on a language table.
As text fields in Access tables allow unicode, this method will allow text from Right-To-Left languages like Hebrew & Arabic too!

Module: modLanguage

Option Compare Database
' Module to assist internationalisation of database interface
' written by Marc Ozin
' version: rc2012.02.02
' Website: http://marcozin.blogspot.com


' this module requires a lanaguage table like this:

' Table Name: tblLanguage
' Fields:
' swmVar
' Type: Text
' Size: 25
' Required: Yes
' Input Mask: >Aaaaaaaaaaaaaaaaaaaaaaaaa
' lwmLanguageID
' Type: Long Integer
' Required: Yes
' Default Val: 0
' swoData
' Type: Text
' Size: 255
'
' Primary Key: Composite of swmVar & lwmLanguageID
'
' this table will store language varables & text for each lanaguage code
' plus language varables & text to default to if language code not found
' signifed using lwmLanguageID of zero (0)

' Notes:
' Table of Locale ID's can be found on these pages:
' http://msdn.microsoft.com/en-us/goglobal/bb895996
' http://msdn.microsoft.com/en-us/goglobal/bb964664

' Examples:
' to set the caption for the button called ButtonCancel in a form when it opens
' edit the OnLoad event for the form and insert the following line:
' ButtonCancel.Caption = GetLangTxt("CANCEL")
' Then in the language table create a row with these values:
' swmVar: CANCEL
' lwmLanguageID: 0
' swoData: &Cancel
' "&Cancel" will be the default text when a particular user's language cannot be found
' to have different text for German, add the following row:
' swmVar: CANCEL
' lwmLanguageID: 1031
' swoData: &Kündigen




'Get the language ID for the current user's locale from kernel32
'returns Long number representing the Language ID
Public Declare Function GetUserDefaultLCID% Lib "kernel32" ()


Public Function GetLangTxt(sLangVar As String, Optional ByVal lLanguageID As Long = -1) As String
' returns language text from specified variable stored in the Language Table
' function will try and return text for specified varable for current language (or language specified by lLanguageID)
' if no text found, then it will try and return text for varable with a language id of zero
' if still no text found, then it will return the name of the varable incased in square brackets

Const cLanguageTable = "tblLanguage"
Const cLanguageDataField = "[swoData]"
Const cLanguageVarableNameField = "[swmVar]"
Const cLanguageIDField = "[lwmLanguageID]"

Dim vTemp As Variant

If lLanguageID = -1 Then
lLanguageID = GetUserDefaultLCID()
End If

'try for a specific language id
vTemp = DLookup(cLanguageDataField, cLanguageTable _
, cLanguageVarableNameField & " like '" & UCase(Trim(sLangVar)) & "' and " & cLanguageIDField & "=" & CStr(lLanguageID))

' if nothing found
If IsNull(vTemp) Then
'try for language zero
vTemp = DLookup(cLanguageDataField, cLanguageTable _
, cLanguageVarableNameField & " like '" & UCase(Trim(sLangVar)) & "' and " & cLanguageIDField & "=0")
End If
GetLangTxt = Nz(vTemp, "[" & sLangVar & "]")
End Function