Change the Language at Runtime using .resx files

Posted by Marc on 24-Jun-2013 07:58

Hi All,

I'm trying to make a multilingual application using one .resx file per language for each form.

Following this web page ( http://www.dotnetcurry.com/ShowArticle.aspx?ID=174 ), I manage to generate the .resx files I need,

but as I want to use them, I get the folling error ( caused by the resources:ApplyResources ):

     System.NotSupportedException: The invoked member is not supported in a dynamic assembly.

     (in french : System.NotSupportedException: Le membre appelé n'est pas pris en charge dans un assembly dynamique.)

Here is the way a translate the code from c# to ABL :

    METHOD PRIVATE VOID ChangeLanguage(lang AS CHARACTER):

        THIS-OBJECT:SuspendLayout().

        DEF VAR cultureInf AS System.Globalization.CultureInfo NO-UNDO.

        cultureInf = NEW System.Globalization.CultureInfo(lang).

        DEF VAR resources AS CLASS System.ComponentModel.ComponentResourceManager.

        resources = NEW System.ComponentModel.ComponentResourceManager ( THIS-OBJECT:GetType() ).

        DEF VAR i AS INTEGER NO-UNDO.

        DO i = 1 TO THIS-OBJECT:Controls:Count:

            resources:ApplyResources(THIS-OBJECT:Controls[i], THIS-OBJECT:Controls[i]:Name, cultureInf). /*ApplyResources(this, "$this").*/

        END.       

        THIS-OBJECT:ResumeLayout().

    END METHOD.

Any idea why do I get this message ?

Thanks,

Marc.

All Replies

Posted by Matt Baker on 24-Jun-2013 10:53

Some of the AVM uses .dll files on disk to run .NET code and in other places, such as when creating a class, the AVM emits .NET code at runtime.   The emitted code is considered a 'dynamic assembly'.  For whatever reason, Microsoft chose not to support language switching on dynamic assemblies.

You will need to restart and make sure the corrrect language is specified before running any Windows forms in the ABL.

Posted by Marc on 24-Jun-2013 11:17

Hi Matthew, thank you for your answer.

Now, how do I "specify" the correct language before running ?

Is there something better to do than renaming myform.FR.resx to myform.resx ?

Marc.

Posted by Admin on 24-Jun-2013 11:44

Now, how do I "specify" the correct language before running ?

USING System.Globalization.* FROM ASSEMBLY .

USING System.Threading.* FROM ASSEMBLY .

Thread:CurrentThread:CurrentUICulture = NEW CultureInfo ("fr":U) .

Posted by Marc on 26-Jun-2013 07:30

Thanks Mike, this works fine!

Marc.

This thread is closed