annefa


Hi..

I have a windows application that can change the language of the application depends on the language preference of the user. My application can switch between chinese(zh-CHS) and english(en-US). I also have a report that also can change the language (hopefully) if user change their language preference in the framework of my application.

I already follow the step provided in this link.

http://technet.microsoft.com/en-us/library/aa964130.aspx

While the code is at http://mhprofessional.com/product.php isbn=0072262397&cat=112&promocode=

Since I want to apply it in windows application and C#, i already modified to make it suitable with my application. I can successfully deploy and view my report if user key in (for testing purpose) the language they want in the report interface.

My problem is, I actually want to retrieve the value automatically from the framework. I try to retrieve the current language from thread.

namespace Mynamespace.RSLanguage.MultiLanguage

{

public class MyReports

{

private static ResourceManager LocalizeRM;

static MyReports()

{

LocalizeRM = new ResourceManager("Mynamespace.RSLanguage.MultiLanguage.MyReports", System.Reflection.Assembly.GetExecutingAssembly());

}

[System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Assert, Name = "FullTrust")]

public static string LocalizedString(string stringIdentifier, string language)

{

string getLanguage = "";

try

{

if (language != "")

{

getLanguage = language;

}

else

{

getLanguage = Thread.CurrentThread.CurrentUICulture.ToString().Trim();

}

CultureInfo currentCulture = new CultureInfo(getLanguage);

return LocalizeRM.GetString(stringIdentifier, currentCulture);

}

catch (System.Exception ex)

{

return ex.Message;

}

}

::::

}

::::

}

But, the getLanguage value still get the "en-US" from the thread even though user change their language preference to chinese. So, it still deploy the report in english. But if user key in "zh-CHS" into the interface, the report will display the report like correctly.

How can I actually retrieve the current value for the language





Re: Get Culture for Multilanguage in Reporting Service

Nick_ITConsultant


I have had a lot of experience on this subject in the past month or so, first I just have a couple of questions regarding your parameters. Are you serializing your report parameters and passing it to the server or are you just sending the client to the SRS If you are sending the parameters from the application you can simply send the language as a parameter to the report and use it in the expression like this: Mynamespace.RSLanguage.MultiLanguage.MyReports.LocalizeRM.GetString(stringIdentifier, Parameters!Language). This was the route I took, because my application has a session variable for the language that is set by the user to override the current cultureUI thread of the application.

If this is not the case I would suggest that you use the User!Language, though I have not tried this method.

Hope this helps,

Nick







Re: Get Culture for Multilanguage in Reporting Service

annefa

My situation is like this: I have application A that set the language. And another one is application B (report) which will grab the value of current language.

In this situation, I think I cannot use the expression, Mynamespace.RSLanguage.MultiLanguage.MyReports.LocalizeRM.GetString(stringIdentifier, Parameters!Language). Which actually get the value of language from application B itself.

One more thing, I also tried using User!Language that you suggested, but it did not get the current value of application A. I think User!Language get the value from regional setting but not from the application A.

How can I get the value of the culture silently from the application A My report in application B will display "#Error" in the place where it should display the string when I directly access the value from the application A that do the language setting. Is that because report cannot access the value from other place I'm totally blank about it.

From what you have said,

"This was the route I took, because my application has a session variable for the language that is set by the user to override the current cultureUI thread of the application. "

How can you do that How can you override the CurrentUICulture and do the session variable Maybe I can try this as the solution of my problem.







Re: Get Culture for Multilanguage in Reporting Service

annefa

I try to do this in application A:

public class UserPreference

{

public static string PassLanguage()

{

string language = "zh-CHS"; //try to pass hardcode data

return language;

}

::

}

In application B:

namespace Mynamespace.RSLanguage.MultiLanguage

{

public class MyReports

{

private static ResourceManager LocalizeRM;

static MyReports()

{

LocalizeRM = new ResourceManager("Mynamespace.RSLanguage.MultiLanguage.MyReports", System.Reflection.Assembly.GetExecutingAssembly());

}

[System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Assert, Name = "FullTrust")]

public static string LocalizedString(string stringIdentifier, string language)

{

string getLanguage = "";

try

{

if (language != "")

{

getLanguage = language;

}

else

{

getLanguage = UserPreference.PassLanguage();

}

CultureInfo currentCulture = new CultureInfo(getLanguage);

return LocalizeRM.GetString(stringIdentifier, currentCulture);

}

catch (System.Exception ex)

{

return ex.Message;

}

}

::::

}

::::

}

This is what I did when the report display "#Error".

*Note: I already put 'using namespace' on the top the class since bot application have different namespace.

The value of zh-CHS only for testing purpose.






Re: Get Culture for Multilanguage in Reporting Service

Nick_ITConsultant

Well that sounds all too familiar, ¡®#error¡¯, this is often caused by insufficient access to the assembly¡¯s resources or inaccurate data sent to the localization service (an empty string). In the web application that we are currently developing we created our own reporting service that calls the SRS server and sends all the parameters and attributes to the server as serialized data. Process allows us to gather our application A¡¯s parameters and send it to the SRS server who then calls Application B. Application B finds the requested resource and returns it. You could look into taking a similar approach by adding a parameter from you application A¡¯s currentUI Thread and might achieve the same results.

From the code you posted I can only notice one possible flaw;

This code is called from the report server who does not have direct access to application A. remember your calling the report server and not this function, hence the security overrides required to make the service calls work.

LocalizedString(string stringIdentifier, string language)

If you enter the parameter manually, then it can call the service, however in this case I could see it being null, because it¡¯s a three way call and your attempting to remove the middle man. You request the report from A, the SRS processes your request and then calls the assembly B. Right now it would appear that there is no communication at all between your server/report and your applications.

Without fully understanding the exact code of your application I can only assume it might be due to one of those issues. I suggest trying the parameter expression method I stated the last post.

Below are some of the links I found useful during my research for this task:

http://msdn2.microsoft.com/en-us/library/microsoft.wssux.reportingserviceswebservice.rsexecutionservice2005.reportexecutionservice.render.aspx

http://msdn2.microsoft.com/en-us/library/aa287725(VS.71).aspx

http://www.codeproject.com/sqlrs/CustomAssemblies.asp

http://blogs.msdn.com/bimusings/archive/2005/06/16/429795.aspx






Re: Get Culture for Multilanguage in Reporting Service

annefa

Hi Nick. Thanks for your response and suggestion.

I read the link that you provide and I recheck my config file. Duh! I make mistake in the config file. No wonder my report display #Error because it cannot do some access that it want. Just like what you said. Now, I'm working on getting the right culture to pass in my code.

Anyway, Thanks a lot.






Re: Get Culture for Multilanguage in Reporting Service

annefa

Hi...

I try to get the current language that have been used in my application using CurrentUICulture to implement multilanguage in Reporting Services.

My problem is, the value from thread did not give me the right value of the current language used in application.

The thread return the value from the regional setting rather than get the value from the currently running application.

I try to call the thread by modifying .cs file that have been generated from.resx file.

I dont know whether my action is proper or not.

Maybe I cannot modify the .cs file generated from .resx file or maybe I need to do something else that related to the permission or what so ever.

But when I try to call the thread from other ordinary .cs file, the thread will return the right value (language the application have).

The problem only occur when I try to call the thread from .cs that have been generated from .resx file.

Hope someone can help me.






Re: Get Culture for Multilanguage in Reporting Service

annefa

I try to solved this problem by calling the thread from other class file and declare it as the parameter of my report. It works!

From the designer, I call the parameter as usual.