Introduction
Localization or Internationalization means displaying the content in several languages that can help the user to access the content across the globe. Reports are currently one of the important tools and are used in various fields depending on the requirements of the user. Localization plays a very important role and now it has become a normal requirement of any project. Using localization we can make a single RDL / RDLC file available across multiple locales.
Microsoft has not provided any way to add a resource (resx) file in a report to localize it. But Microsoft provides a way to use an assembly with a report. This will become a workaround to achieve localization in SSRS reports.
To implement this solution we first need to create the assembly that will do the actual localization. This assembly contains a resource file and a class file that has a function that accepts a key name and culture and depending on the culture, the function will localize the value. The class file may have the following definition.
- using System;
- using System.Globalization;
-
- namespace ReportLocalization
- {
- public static class LocalizedValue
- {
- public static string GetString(string name, string cultureInfoName)
- {
- string returnString = string.Empty;
- try
- {
-
- CultureInfo ci = new CultureInfo(cultureInfoName);
-
- returnString = ReportResource.ResourceManager.GetString(name, ci);
- }
- catch (Exception ex) { }
- if (string.IsNullOrEmpty(returnString))
- {
- returnString = name;
- }
- return returnString;
- }
- }
- }
Now build the assembly project and get the DLL from the bin folder, either from the debug or release folder. This custom assembly is used within the report.
Create a server report project using SQL Server Business Intelligent Development Studio. Within the report, create a data-source and reports.
Use the following procedure to add this assembly and do report localization.
1. Click on Report >> Report Properties from the menu.
2. Add the custom assembly (DLL) to the report as a reference.
Click on the reference tab and click on the add button. Browse to the assembly and click on the “Ok” button.
3. Add the following function Code tab.
- Public Function LocalizedValue(name as String, culture as String) as String
- Try
- Return ReportLocalization.LocalizedValue.GetString(name,culture)
- Catch ex As Exception
- Return ex.Message
- End Try
- End Function
4. To localize a caption, right-click the TextBox and select "Expression". Use the custom code (that is written in the Code tab of the report properties) to get the localized value for any string.
=Code.LocalizedValue("Test", “en-Us”)When previewing the report, we get an error like "Could not load file or assembly 'assembly name and version information' or one of its dependencies. The system cannot find the file specified."
To resolve this issue, we need to copy our custom assembly in the following folder.
- <%Win directory %>:\Program Files (x86)\Microsoft Visual Studio <<Version of visual studio >>\Common7\IDE\PrivateAssemblies
The is an example of our Windows directory is C:
C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PrivateAssembliesUpload report on report server
When we use a server report, all the reports need to deploy to the report server. When our report contains a custom assembly, we might get an error like "Error while loading code module....".
Solution: to resolve this issue, we need to copy our custom assembly to the following path:
- <%Win directory Program Files\Microsoft SQL Server\MSRS11.<<version>> \Reporting Services\ReportServer\bin
The is an example of our Windows directory is C:
C:\ Program Files\Microsoft SQL Server\MSRS11.SQLEXPRESS\Reporting Services\ReportServer\binMost Common problem you may encounter
The most common problem using this approach is that when adding the new resource (resx) file it will not be reflected in the report. The reason for this is the custom assembly (DLL) is not updated in the following paths.
- Program Files\10.0\Common7\IDE\PrivateAssemblies
- Program Files\Microsoft SQL Server\ MSRS11.SQLEXPRESS\Reporting Services\ReportServer\bin
It's done!
The SSRS Report is now localized.
I hope this will help you.