473,320 Members | 1,982 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Wrong language displayed when using ResourceManager

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;
}

Nov 19 '05 #1
4 2851
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

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Peter" <Pe***@discussions.microsoft.com> wrote in message
news:78**********************************@microsof t.com...
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;
}

Nov 19 '05 #2
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

"Karl Seguin" wrote:
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

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Peter" <Pe***@discussions.microsoft.com> wrote in message
news:78**********************************@microsof t.com...
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;
}


Nov 19 '05 #3
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

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Peter" <Pe***@discussions.microsoft.com> wrote in message
news:29**********************************@microsof t.com...
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

"Karl Seguin" wrote:
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

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Peter" <Pe***@discussions.microsoft.com> wrote in message
news:78**********************************@microsof t.com...
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;
}


Nov 19 '05 #4
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

"Karl Seguin" wrote:
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

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Peter" <Pe***@discussions.microsoft.com> wrote in message
news:29**********************************@microsof t.com...
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

"Karl Seguin" wrote:
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

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Peter" <Pe***@discussions.microsoft.com> wrote in message
news:78**********************************@microsof t.com...
> 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;
> }
>


Nov 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Gwl | last post by:
I'm writing an application in which the user can change the default ouput language while the program is running. I have no problem to do it when there is only a form opened, but if I have a...
0
by: marcus | last post by:
I am developing a web site at work that needs to be both in French and English. I have been reading up on using resource files (.resx files) in combination with setting the CultureInfo to either...
0
by: nthpixel | last post by:
Hey Folks, I am getting the following errors when I try to connect to my db with the MySqlConnection. I added MySql.Data to my Reference list and have the .dll in my bin directory. I also have...
1
by: Chukkalove | last post by:
I originally created several "copy" resource reader classes which worked great individually, but after I converted them into an parent class with children they no longer find the resources. Each...
1
by: scpedicini | last post by:
Let's say that I've built an assembly called MyApi.dll with two different language resource files, one called DefaultResource.resx (which is my english resource file), and a german resource file...
4
by: Hans Kesting | last post by:
Can I change the language of an existing form on the fly? Say I have two radiobuttons: "dutch" and "english". When the user selects one, the form must switch to the selected language. Is that...
1
by: Screaming Eagles 101 | last post by:
This is not a question but something I found, it might not be the best solution, but hey, it works... :-) Thought someone else could also use this, so here it is. I made 2 resource files, one...
4
by: GS | last post by:
Hello, I use vs2005 and I try to find out how I can get a list of the cultures where I have made resources for. So I can make a combobox where I can choose the language I want to use. With...
14
by: yxq | last post by:
Hello, I want to build the multi-language application with the xml file, how to do? could anyone tell a sample? Thank you
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.