SSRS中的多语言

时间:2010-02-17 17:27:45

标签: reporting-services multilingual report

有没有办法以其他语言显示/导出英文SSRS报告?

7 个答案:

答案 0 :(得分:6)

不,不幸的是,没有简单的方法可以做到这一点:-(我一直试图让自己运行起来,但最后我所做的基本上是通过了我想要显示的所有标签来自调用应用程序的报告(在我的案例中是一个ASP.NET应用程序)。

另一种方法可能是将文本片段存储在SQL Server表中,并将数据源添加到报告中以检索这些文本标签,然后将它们绑定到适当的控件。我尝试过类似的东西但却无法让自己发挥作用。

ASP.NET很难用资源进行国际化,但SSRS在尝试使其具有多语言意识时仍然非常混乱: - (

答案 1 :(得分:5)

通过应用有趣的黑客,我设法通过.NET资源文件获得多语言支持。每个报告控件都有一个未使用的属性,称为ValueLocId。使用此属性,可以指定要用于每个控件的资源名称。这里的想法是,您将遍历报表定义,查找具有ValueLocID属性集的控件。如果设置了该属性,请将该控件的Text替换为ValueLocID中指定的Resource Text。基本上,这个想法是这样的:

  1. 将RDLC文件作为XML文件加载到内存中
  2. 使用XPath遍历XML文件,查找ValueLocID属性
  3. 使用ValueLocID
  4. 中指定的资源替换该XML节点的innerText
  5. 使用RDLC文件的内存副本加载ReportViewer控件。
  6. 请参阅下面的功能,它将完全按照我上面提到的那样进行。

    Private Sub LocalizeReport()
    
        Dim xmlDoc As XmlDocument = New XmlDocument
        Dim asm As Reflection.Assembly = Reflection.Assembly.GetExecutingAssembly()
        'create in memory, a XML file from a embedded resource
        Dim xmlStream As Stream = asm.GetManifestResourceStream(ReportViewer1.LocalReport.ReportEmbeddedResource)
    
        Try
            'Load the RDLC file into a XML doc
            xmlDoc.Load(xmlStream)
        Catch e As Exception
            'HANDLE YOUR ERROR HERE
        End Try
    
        'Create an XmlNamespaceManager to resolve the default namespace
        Dim nsmgr As XmlNamespaceManager = New XmlNamespaceManager(xmlDoc.NameTable)
        nsmgr.AddNamespace("nm", "http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition")
        nsmgr.AddNamespace("rd", "http://schemas.microsoft.com/SQLServer/reporting/reportdesigner")
    
        'IMPORTANT LINE BELOW
        'YOU WILL NEED TO SET THIS TO YOUR RESOURCE MANAGER, OTHERWISE NOTHING WILL WORK
        Dim rm As ResourceManager = New ResourceManager("Insurance.Subs.WinUI.Controls.Resources", asm)
    
        'Loop through each node in the XML file, that has the ValueLOCId property set.
        'Using this property as a workaround for localization support.  The value specified in this
        'property will determine what resource to use for translation.
        Dim node As XmlNode
        For Each node In xmlDoc.DocumentElement.SelectNodes(String.Format("//nm:{0}[@rd:LocID]", "Value"), nsmgr)  'XPath to LocID
            Dim nodeValue As String = node.InnerText
            If (String.IsNullOrEmpty(nodeValue) Or Not nodeValue.StartsWith("=")) Then
                Try
                    Dim localizedValue As String = node.Attributes("rd:LocID").Value
    
                    'Get the resource via string
                    localizedValue = rm.GetString(localizedValue)
                    If Not String.IsNullOrEmpty(localizedValue) Then
                        'Set the text value - via the retrieved information from resource file
                        node.InnerText = localizedValue
                    End If
    
                Catch ex As Exception
                    'handle error
                End Try
            End If
        Next
    
        ReportViewer1.LocalReport.ReportPath = String.Empty
        ReportViewer1.LocalReport.ReportEmbeddedResource = Nothing
        'Load the updated RDLC document into LocalReport object.
        Dim rdlcOutputStream As StringReader = New StringReader(xmlDoc.DocumentElement.OuterXml)
        Using rdlcOutputStream
            ReportViewer1.LocalReport.LoadReportDefinition(rdlcOutputStream)
        End Using
    
    End Sub
    

答案 2 :(得分:3)

您可以公开反映用户信息的全局参数(用户!语言)。

然后您可以使用google translateapi将英语单词转换为您的语言。

这是一篇很好的文章:http://mscrm4u.blogspot.com/2008/06/multi-lingual-ssrs-reports.html

答案 3 :(得分:3)

您应该尝试以下链接,这似乎是最好的方法。

http://support.microsoft.com/kb/920769

您需要使用资源和方法创建一个程序集,以根据文化获取字符串。你可以在这里找到完整的教程:

http://www.codeproject.com/Articles/294636/Localizing-SQL-Server-Reporting-Services-Reports

您可以添加自定义程序集,其中包含要翻译的字符串的资源,并在报告中访问它们。

答案 4 :(得分:1)

使用SQL dsTranslations数据集方式(我不喜欢乱用XML)

这使您可以创建一个简单的界面,让您的客户填写翻译, 例如,一个快速的Lightswitch GUI

enter image description here

使用此数据集我会进行简单的翻译

=Lookup("WORDTOBETRANSLATED", Fields!Key.Value, Fields!Value.Value, "dsTranslation")

第二种方法是我个人使用的方法,如果密钥不在dbTranslations中,它会显示他们必须添加到db的wat键。 我可以更优雅地做第二部分,反馈非常欢迎。

=Microsoft.VisualBasic.Interaction.iif(Lookup("WORDTOBETRANSLATED", Fields!Key.Value, Fields!Value.Value, "dsTranslation") = "", "WORDTOBETRANSLATED", Lookup("WORDTOBETRANSLATED", Fields!Key.Value, Fields!Value.Value, "dsTranslation"))

答案 5 :(得分:0)

在最近完成代码项目中列出的步骤后,我同意Igoy,但是想补充一点,添加新CodeGroup时要遵循的步骤如果你将新的CodeGroup放在任何地方,在未命名的UnioncodeGroup(它是具有Url =“$ CodeGen $ / *”的那个)之后,您尝试访问自定义程序集将失败。

经过大量挖掘后,我能够在其中一个msdn页面上找到对此的确认(请参阅“用于扩展的CodeGroup元素的放置”部分)。他们的措辞是“建议”,但从我的测试中我会说它是必需的,至少在直接在报表服务器上测试时: http://msdn.microsoft.com/en-us/library/ms152828.aspx

.config文件中此位置的xpath是这样的(在wix中很有用): // PolicyLevel /代码组/代码组[[] @类= 'FirstMatchCodeGroup'[]] /代码组[[] @ PermissionSetName = 'ReportLocalization'[]]

答案 6 :(得分:0)

制作多语言ssrs报告的简单方法是硬编码或使用sharedataset。但是,如果我们使用共享数据集,我们将面临渲染性能问题。

以下是一种有效的方法,可以在报告中翻译标签并提高性能(特别是在渲染性能方面)

步骤1:实现一个库以支持获取报告字典,下面的例子仅供参考,应该修改它以返回正确的字典

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Linq;
using System.Security.Permissions;
using System.Text;
using System.Data.SqlClient;

namespace CmsReportLibrary
{
    public class DictionaryLabel
    {
        DictionaryLabel()
        {
            
        }
        
        public static string[] GetDictionary(int languageid)
        {
            System.Data.SqlClient.SqlClientPermission oPerm = new System.Data.SqlClient.SqlClientPermission(PermissionState.Unrestricted);
            oPerm.Assert();
            SqlConnection oConn = new SqlConnection();
            oConn.ConnectionString = ConfigurationManager.ConnectionStrings["appconnectionstring"].ConnectionString;

            //oConn.ConnectionString = "Data Source=(local);Initial Catalog=Northwind;User Id=<>;Password=<>";

            //oConn.Open();
            //SqlCommand oCmd = new SqlCommand();
            //oCmd.Connection = oConn;
            //oCmd.CommandText = "..................";
            // ....................

            //oConn.Close();	
            return new string[] {...............}; 
			//ex return new string[] { "Client||Klient", "Week||Woche", "Year||Jahr"}; 			

        }
    }
}

步骤2:编译库并将其复制到Report Service的ReportServer中的Bin文件夹

例如:将库复制到C:\ Program Files \ Microsoft SQL Server \ MSRS10_50.R2 \ Reporting Services \ ReportServer \ bin

步骤3:修改ReportServer文件夹中的 rssrvpolicy.config 文件(例如: C:\ Program Files \ Microsoft SQL Server \ MSRS10_50.R2 \ Reporting Services \ rssrvpolicy.config ),找到“$ CodeGen $”并添加以下代码,让SSRS知道新库的位置

<CodeGroup
        class="UnionCodeGroup"
        version="1"
        PermissionSetName="FullTrust"
        Name="CoDeMagSample"
        Description="CoDe Magazine Sample. ">
       <IMembershipCondition
            class="UrlMembershipCondition"
            version="1"
            Url="C:\Program Files\Microsoft SQL Server\MSRS10_50.R2\Reporting Services\ReportServer\bin\CmsReportLibrary.dll"
    />
</CodeGroup>

步骤4:在Reporting Service配置管理器中停止并开始报告服务

步骤5:将库应用于SSRS报告     创建新报告或修改新报告,此报告应具有languageid参数     为此报告设置对库的引用         右键单击报告,选择“报告属性”         单击“引用”选项卡         将库的引用粘贴到“添加或删除程序集”区域:

CmsReportLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null

enter image description here

第6步:添加自定义代码以支持标签翻译

public Shared Dim ListLabel as String()

函数GetListLabel(languageid as Integer)     ListLabel = CmsReportLibrary.DictionaryLabel.GetDictionary(Parameters!LanguageId.Value) 结束功能 function translate(作为String输入)为String

dim i as Integer


For i=0 to UBound(ListLabel,1)
    if Instr(ListLabel(i), input) > 0 then
        Translate = Replace(ListLabel(i), input + "||","")      
        exit function
    end if

Next

'Not found, return any string you want
Translate = "not found"
end function

第7步:添加新的报告变量 enter image description here

ListLabel变量的表达式

=Code.GetListLabel(Parameters!LanguageId.Value)

第8步:翻译报告中的标签

修改标签表达式,使用自定义代码中的Translate方法进行翻译

例如:

=Code.Translate("Client")

=Code.Translate("Week")