Wrox Programmer Forums
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 12th, 2006, 09:49 AM
Registered User
 
Join Date: Sep 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Two languages application


Hi,

I'm building an application that has to be available in two languages. I don't want to duplicate the coding so I don't want two files or copy-and-translate forms duplicating the code.

What do you think could be a good approach?

I've had some thoughts but I don't want to suggest anything, so any feedback will be highly appreciated!!!

Cheers,
Sergio
 
Old October 12th, 2006, 09:55 AM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 564
Thanks: 0
Thanked 4 Times in 4 Posts
Default

I have used this approach and found it to work well.

Create a table with 2 columns - for the sake of Argument, lets say English and German.

Next create a function called getText, that takes the English Text as an argument. This function will check to see what language is needed (However you want to do that). If it is German, then the function queries the table to find the matching phrase, and returns it, otherwise it returns the English phrase.

On your form in the On_Load event, then go through your controls and set the language.
    me.lblWelcome = getText(me.lblWelcome)

Hope that helps,

Mike

Mike
EchoVue.com
 
Old October 12th, 2006, 06:04 PM
Registered User
 
Join Date: Sep 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default


Hi Mike,

Your suggestion led me on the right direction. This morning I thought the whole thing will take 2 or 3 of my already few days to deadline but at the end of today I had it done.

I'm posting the whole result, just in case someone else needs this in the future. Or if someone wants to suggest an improvement it'll be more than welcome.

Cheers,
Sergio
-------------------------------------
Solution to have multiple languages on a single Access Application

1. Create a table with your original description and its foreign description

SAMPLE
'I use rowid (autonumber) as a standard in my tables
english chinese rowid
Bin Maintenance ¿âλµ÷Õû 39
Bin to bin transfers ¿âλµ÷Õû 27


2. Create a translation function:

Function getLanguage(variable As String) As String
'I leave the very first form open but hidden,
' with a text control having the selected language
    If Forms!LanguageSelection.language = "english" Then
        getLanguage = variable 'No changes
    Else
'Some buttons don't have description, so nothing to translate
        If Nz(variable, "") <> "" Then
            getLanguage = Nz(DLookup("[chinese]", "shanman_syslangmatrix", "[english] = " & qo(variable)), "@" & variable)
            'The @ will indicate me if a description doesn't have a matching translation yet
        Else
            getLanguage = variable 'No changes if blank captions (without this it was changing them to @)
        End If
    End If
End Function




3. Create a procedure to translate all controls in the form

Public Sub translateForm(frm As Form)
On Error GoTo Exit_translateForm 'Until I find a way to know the number of controls
                                    'the error is the loop exit

    Dim i As Integer
    Dim j As Integer
    Dim x As String

    For i = 0 To 1000 'I don't think I'll have more than 1,000 controls in a form ...
        j = frm.Controls(i).ControlType
        If j = 100 Or j = 104 Then 'I only want to translate Labels & Buttons
            frm.Controls(i).Caption = getLanguage(frm.Controls(i).Caption)
        End If
    Next i

Exit_translateForm:
End Sub



4. Guess what? It works on reports too

Public Sub translateReport(rep As Report)
On Error GoTo Exit_translateReport 'Until I find a way to know the number of controls
                                    'the error is the loop exit

    Dim i As Integer
    Dim j As Integer
    Dim x As String

    For i = 0 To 1000 'I don't think I'll have more than 1,000 controls in a report ...
        j = rep.Controls(i).ControlType
        If j = 100 Or j = 104 Then 'I only want to translate Labels
            rep.Controls(i).Caption = getLanguage(rep.Controls(i).Caption)
        End If
    Next i

Exit_translateReport:
End Sub



5. Put the corresponding routine as part of your ON LOAD event of form or your ON OPEN event of report

Private Sub Form_Load()
    translateForm Me
End Sub

Private Sub Report_Open(Cancel As Integer)
    translateReport Me
End Sub





Similar Threads
Thread Thread Starter Forum Replies Last Post
One "web.sitemap" for two languages!!?? MTLedari ASP.NET 2.0 Professional 0 May 18th, 2007 01:42 AM
SCRIPTING LANGUAGES itsmepiyush_kool Intro Programming 2 December 13th, 2006 03:50 PM
what languages should i learn? NewProgrammer Intro Programming 4 June 18th, 2006 03:02 AM
Using Resource files for different Languages Bexm BOOK: Professional ASP.NET 2.0 and Special Edition; ISBN: 978-0-7645-7610-2; ISBN: 978-0-470-04178-9 1 January 23rd, 2006 08:12 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.