Wrong language displayed when using ResourceManager

G

Guest

Hi!

I'm developing components (webparts) for a sharepoint site and are currently
having some problems with the resource manager. The site supports two
languages (English and Swedish) and when the files are published everything
works fine. However, after a few days, suddenly all texts are displayed in
English only!

Below is the code I'm using to read resource files. The project has two
resource files: resources.resx and resources.sv-SE.resx

Does anyone have an idea what may cause this?

Thanks,

Peter


private ResourceManager m_ResourceManager = new
ResourceManager("WebParts.Resources", Assembly.GetExecutingAssembly());


protected string GetString(string Key)
{
ReadLanguageFromUrl();

if (m_CultureInfo == null)
{
string Lang = "";

if (m_Language == Languages.Swedish)
Lang = "sv-SE";

m_CultureInfo = new CultureInfo(Lang);
}
return m_ResourceManager.GetString(Key, m_CultureInfo);
}

private void ReadLanguageFromUrl()
{
if (Page.Request.Path.IndexOf("/en/") != -1)
m_Language = Languages.English;
else
//Default language swedish
m_Language = Languages.Swedish;
}
 
K

Karl Seguin

Peter:
m_Language wouldn't be a static field by any chance, would it? How is the
instance of whatever class this code is in maintained?

Karl
 
G

Guest

Hi Karl

No, the variable is not static. See the code below:

public class BaseWebPart : Microsoft.SharePoint.WebPartPages.WebPart
{
protected Languages m_Language;


The instance of the class is maintained by sharepoint I suppose.

Peter
 
K

Karl Seguin

Peter,
i tried your code within my site and it worked fine. m_CultureInfo is also
not static, right (I'm curious why there's so many class members? a lot of
those should probably be refactored to local fields unless I'm not seeing
the whole picture).

Anyways.Some random thoughts
(a) the swedish resource file isn't embedded into the assembly
(b) /en/ is always in the path (maybe some context.rewritepath is happening
or server.transfer which is making this hard to track? )
(c) there's some static trickery at work

Have you debugged and stepped through your code to see what's happening?

Karl
 
G

Guest

Karl,

The strange thing is that when I run the code on my local machine, it works.
Also when I upload it to our web server it seems to work for a few days, but
then it suddenly starts displaying the wrong language.

I have been able to verify that the ReadLanguageFromUrl() function actually
works, since I'm using it elsewhere in the same class to display different
pictures depending on the current language.

Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top