.NET Framework Bookmark and Share   
 index > .NET Base Class Library > Chaning Culture for dll project
 

Chaning Culture for dll project

Hello:

I have two projects (for simplicity, let's call them BackEnd and FrontEnd) in one solution. Both of them need to have access to a resource (.resx) file, which I added to the BackEnd project.

I added the BackEnd project as refrence for FrontEnd so now FrontEnd can see the all the resources.

When I start the application, FrontEnd project is running and i changethe CurrentUICulture in the main (program file) by -

Thread.CurrentThread.CurrentUICulture = new CultureInfo(language.ToString());

When the application is running and the Backend project is looking for resource it fails because the backEnd culture is different from the FrontEnd project.

how do i change the backEnd project culture ?

Shauliz

Shauliz,

Based on your post, you are using Thread.CurrentUICulture property to set the current culture used by the Resource Manager to look up culture-specific resources at run time. However, there is still something wrong with the Backend DLL project resource file. I would like to provide you the suggestions as follows:

1. Except the Thread.CurrentUICulture property, you can also try to use AssemblyName.CultureInfo property that sets the culture supported by the assembly. The following code snippet shows you the way:

Code Snippet

' Create a dynamic assembly with name 'MyAssembly' and build version '1.0.0.2001'.

Dim myAssemblyName As New Reflection.AssemblyName()

' Set the codebase to the physical directory were the assembly resides.

myAssemblyName.CodeBase = IO.Directory.GetCurrentDirectory()

' Set the culture information of the assembly to 'English-American'.

myAssemblyName.CultureInfo = New Globalization.CultureInfo("en-US")

2. The article How to: Set the Culture and UI Culture for Windows Forms Globalizationcan help you to specify a culture so that every part of the application's UI is appropriate to that culture.

3. The article Resources and Localization from MSDN Magazine can help you. Once you have compiled a resource file into a .NET assembly, you can access the resources inside using the ResourceManager class that is defined in the System.Resources namespace. The following shows a simple example of code that accesses a string resource using the ResourceManager:

Code Snippet

Dim asm As Assembly = Assembly.Load("LitwareStrings.resources")

Dim rm As New System.Resources.ResourceManager("LitwareStrings", asm)

Dim caption As String = rm.GetString("MainFormCaption")

Additionally, Microsoft .NET Framework Resource Basics can provide further support on resource issues. The Microsoft .NET Framework supports two kinds of resources—untyped manifest resources and typed resources. Visual Studio .NET supports untyped manifest resources by setting a file's Build Action to Embedded Resource, and supports typed resources through .resx files, either custom files or as the backing store for component resources. Manifest resources have the benefit that they're directly editable in the IDE, while typed resources require extraordinary effort to edit, but provide typed access. Both resource types have some stringent naming requirements, so be extra careful when you compose method calls to load them.

Hope that can help you.

Bruno Yu
Well I think that you must set some public property inside BackEnd dll so that you can
set CurrentUICulture inside BackEnd dll in same moment as in FrontEnd :

Thread.CurrentThread.CurrentUICulture = new CultureInfo(language.ToString());

BackEnd.CurrentCulture = new CultureInfo(language.ToString());


and in BackEnd you have something like:


public static void CurrentCulture

{

set
{

Thread.CurrentThread.CurrentUICulture = value;

}

}



greet
Dragoslav Zaric

Moved to BCL Forum.

Thanks.

Nathan Anderson - MSFT

Shauliz,

Based on your post, you are using Thread.CurrentUICulture property to set the current culture used by the Resource Manager to look up culture-specific resources at run time. However, there is still something wrong with the Backend DLL project resource file. I would like to provide you the suggestions as follows:

1. Except the Thread.CurrentUICulture property, you can also try to use AssemblyName.CultureInfo property that sets the culture supported by the assembly. The following code snippet shows you the way:

Code Snippet

' Create a dynamic assembly with name 'MyAssembly' and build version '1.0.0.2001'.

Dim myAssemblyName As New Reflection.AssemblyName()

' Set the codebase to the physical directory were the assembly resides.

myAssemblyName.CodeBase = IO.Directory.GetCurrentDirectory()

' Set the culture information of the assembly to 'English-American'.

myAssemblyName.CultureInfo = New Globalization.CultureInfo("en-US")

2. The article How to: Set the Culture and UI Culture for Windows Forms Globalizationcan help you to specify a culture so that every part of the application's UI is appropriate to that culture.

3. The article Resources and Localization from MSDN Magazine can help you. Once you have compiled a resource file into a .NET assembly, you can access the resources inside using the ResourceManager class that is defined in the System.Resources namespace. The following shows a simple example of code that accesses a string resource using the ResourceManager:

Code Snippet

Dim asm As Assembly = Assembly.Load("LitwareStrings.resources")

Dim rm As New System.Resources.ResourceManager("LitwareStrings", asm)

Dim caption As String = rm.GetString("MainFormCaption")

Additionally, Microsoft .NET Framework Resource Basics can provide further support on resource issues. The Microsoft .NET Framework supports two kinds of resources—untyped manifest resources and typed resources. Visual Studio .NET supports untyped manifest resources by setting a file's Build Action to Embedded Resource, and supports typed resources through .resx files, either custom files or as the backing store for component resources. Manifest resources have the benefit that they're directly editable in the IDE, while typed resources require extraordinary effort to edit, but provide typed access. Both resource types have some stringent naming requirements, so be extra careful when you compose method calls to load them.

Hope that can help you.

Bruno Yu
Well I think that you must set some public property inside BackEnd dll so that you can
set CurrentUICulture inside BackEnd dll in same moment as in FrontEnd :

Thread.CurrentThread.CurrentUICulture = new CultureInfo(language.ToString());

BackEnd.CurrentCulture = new CultureInfo(language.ToString());


and in BackEnd you have something like:


public static void CurrentCulture

{

set
{

Thread.CurrentThread.CurrentUICulture = value;

}

}



greet
Dragoslav Zaric

You can use google to search for other answers

Custom Search

More Threads

• why Graphics.DrawImage acts weired for .png format?
• ConfigurationManager & medium trust = FileIOPermission exception
• How to return my OrderID from ArrayList
• .Net Versions 1.1,2.0,3.0 on the same machine
• <app>.exe.config vs <app>.config
• Drawing Pipe
• .Net 1.1, console application , Dynamically select config file as app.config.
• Localize Common dialog at runtime
• Access Denied to a folder after Directory.Delete
• Problems with reading from an INI file