Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I managed to get multilanguage support, via .NET Resource files, by applying an interesting hack. There is an unused Property for every single Report Control, called ValueLocId. Using this property, you can specify the resource name to use for each control. The idea here is that you will be looping through your report definition, looking for controls that have the ValueLocID property set. If the property is set, replace the Text of that control with the Resource Text specified in the ValueLocID. So basically, the idea is this:</p> <ol> <li>Load the RDLC file in memory, as an XML file</li> <li>Traverse the XML file using XPath, looking for ValueLocID properties</li> <li>Replace the innerText of that XML node with the Resource specified in ValueLocID</li> <li>Load the ReportViewer control using the memory copy of the RDLC file.</li> </ol> <p>See the function below, which will do exactly what I mentioned above. </p> <pre><code>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 </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload