本地化Microsoft ReportViewer

本地化Microsoft ReportViewer ,網上可找尋的代碼不多,以下爲可供參考的一篇,親測有效,需稍加改動。

using System;
using System.Globalization;
using Microsoft.Reporting.WebForms;
 
namespace InfoSupport.SomeApplication
{
    public class DutchReportViewerMessages : IReportViewerMessages, IReportViewerMessages2, IReportViewerMessages3
    {
        #region IReportViewerMessages Members
 
        // English value: Back to Parent Report
        public string BackButtonToolTip
        {
            get { return "Terug naar het vorige rapport"; }
        }
 
        // English value: Change Credentials
        public string ChangeCredentialsText
        {
            get { return "Wijzig Rechten"; }
        }
 
        // English value: Change Credentials
        public string ChangeCredentialsToolTip
        {
            get { return "Wijzig Rechten"; }
        }
 
        // English value: Current Page
        public string CurrentPageTextBoxToolTip
        {
            get { return "Huidige Pagina"; }
        }
 
        // English value: Document Map
        public string DocumentMap
        {
            get { return "Document Map"; }
        }
 
        // English value: Show / Hide Document Map
        public string DocumentMapButtonToolTip
        {
            get { return "Toon / Verberg Document Map"; }
        }
 
        // English value: Export
        public string ExportButtonText
        {
            get { return "Exporteer"; }
        }
 
        // English value: Export
        public string ExportButtonToolTip
        {
            get { return "Exporteer"; }
        }
 
        // English value: Export Formats
        public string ExportFormatsToolTip
        {
            get { return "Exporteer Formaten"; }
        }
 
        // English value: False
        public string FalseValueText
        {
            get { return "Onwaar"; }
        }
 
        // English value: Find
        public string FindButtonText
        {
            get { return "Zoek"; }
        }
 
        // English value: Find
        public string FindButtonToolTip
        {
            get { return "Zoek"; }
        }
 
        // English value: Next
        public string FindNextButtonText
        {
            get { return "Volgende"; }
        }
 
        // English value: Find Next
        public string FindNextButtonToolTip
        {
            get { return "Volgend Resultaat"; }
        }
 
        // English value: First Page
        public string FirstPageButtonToolTip
        {
            get { return "Eerste Pagina"; }
        }
 
        // English value: Enter a valid page number
        public string InvalidPageNumber
        {
            get { return "Voer een geldig paginanummer in"; }
        }
 
        // English value: Last Page
        public string LastPageButtonToolTip
        {
            get { return "Laatste Pagina"; }
        }
 
        // English value: Next Page
        public string NextPageButtonToolTip
        {
            get { return "Volgende Pagina"; }
        }
 
        // English value: The entire report has been searched.
        public string NoMoreMatches
        {
            get { return "Het volledige rapport is doorzocht."; }
        }
 
        // English value: NULL
        public string NullCheckBoxText
        {
            get { return "Geen waarde"; }
        }
 
        // English value: Null
        public string NullValueText
        {
            get { return "Geen waarde"; }
        }
 
        // English value: of
        public string PageOf
        {
            get { return "van"; }
        }
 
        // English value: Show / Hide Parameters
        public string ParameterAreaButtonToolTip
        {
            get { return "Toon / Verberg Parameters"; }
        }
 
        // English value: Password:
        public string PasswordPrompt
        {
            get { return "Wachtwoord:"; }
        }
 
        // English value: Previous Page
        public string PreviousPageButtonToolTip
        {
            get { return "Vorige Pagina"; }
        }
 
        // English value: Print
        public string PrintButtonToolTip
        {
            get { return "Afdrukken"; }
        }
 
        // English value: Loading...
        public string ProgressText
        {
            get { return "Verwerken..."; }
        }
 
        // English value: Refresh
        public string RefreshButtonToolTip
        {
            get { return "Vernieuwen"; }
        }
 
        // English value: Find Text in Report
        public string SearchTextBoxToolTip
        {
            get { return "Zoek naar tekst binnen het rapport"; }
        }
 
        // English value: <Select a Value>
        public string SelectAValue
        {
            get { return "<Selecteer een waarde>"; }
        }
 
        // English value: (Select All)
        public string SelectAll
        {
            get { return "(Selecteer alles)"; }
        }
 
        // English value: Select a format
        public string SelectFormat
        {
            get { return "Selecteer een formaat"; }
        }
 
        // English value: The search text was not found.
        public string TextNotFound
        {
            get { return "De zoektekst is niet gevonden."; }
        }
 
        // English value: Today is {0}
        public string TodayIs
        {
            get { return "Vandaag is {0}"; }
        }
 
        // English value: True
        public string TrueValueText
        {
            get { return "Waar"; }
        }
 
        // English value: Log In Name:
        public string UserNamePrompt
        {
            get { return "Gebruikersnaam:"; }
        }
 
        // English value: View Report
        public string ViewReportButtonText
        {
            get { return "Toon Rapport"; }
        }
 
        // English value: Zoom
        public string ZoomControlToolTip
        {
            get { return "Zoom"; }
        }
 
        // English value: Page Width
        public string ZoomToPageWidth
        {
            get { return "Paginabreedte"; }
        }
 
        // English value: Whole Page
        public string ZoomToWholePage
        {
            get { return "Volledige pagina"; }
        }
 
        #endregion
 
        #region IReportViewerMessages2 Members
 
        // English value: Your browser does not support scripts or has been configured not to allow scripts.
        public string ClientNoScript
        {
            get { return "Uw browser ondersteunt geen JavaScript of deze ondersteuning is uitgeschakeld."; }
        }
 
        // English value: Unable to load client print control.
        public string ClientPrintControlLoadFailed
        {
            get { return "Het laden van het client print control is niet gelukt."; }
        }
 
        // English value: One or more data sources is missing a user name.
        public string CredentialMissingUserNameError(string dataSourcePrompt)
        {
            return "Een of meerdere databronnen missen een gebruikersnaam.";
        }
 
        // English value is different for each Rendering Extension. See comment behind each type.
        public string GetLocalizedNameForRenderingExtension(string format)
        {
            switch (format)
            {
                case "XML"   : return "XML databestand (.xml)";  // XML file with report data
                case "CSV"   : return "CSV databestand (.csv)";  // CSV (comma delimited)
                case "PDF"   : return "PDF document (.pdf)";     // PDF
                case "MHTML" : return "Webarchief (.mhtml)";     // MHTML (web archive)
                case "EXCEL" : return "Excel rekenblad (.xls)";  // Excel
                case "IMAGE" : return "Afbeelding (.tif)";       // TIFF file
                case "WORD"  : return "Word document (.doc)";    // Word
                default      : return null;
            }
        }
 
        // English value: Select a value
        public string ParameterDropDownToolTip
        {
            get { return "Selecteer een waarde"; }
        }
 
        // English value: Please select a value for the parameter '{0}'.
        public string ParameterMissingSelectionError(string parameterPrompt)
        {
            return String.Format(CultureInfo.CurrentCulture, "Selecteer een waarde voor de parameter '{0}'", parameterPrompt);
        }
 
        // English value: Please enter a value for the parameter '{0}'. The parameter cannot be blank.
        public string ParameterMissingValueError(string parameterPrompt)
        {
            return String.Format(CultureInfo.CurrentCulture, "Selecteer een waarde voor de parameter '{0}'. De parameter mag niet leeg zijn.", parameterPrompt);
        }
 
        #endregion
 
        #region IReportViewerMessages3 Members
 
        // English value: Loading...
        public string CalendarLoading
        {
            get { return "Verwerken..."; }
        }
 
        // English value: Cancel
        public string CancelLinkText
        {
            get { return "Annuleer"; }
        }
 
        // English value: pageCount if PageCountMode.Actual, else pageCount suffixed with a ?
        public string TotalPages(int pageCount, PageCountMode pageCountMode)
        {
            return string.Format(CultureInfo.CurrentCulture, "{0}{1}", pageCount, pageCountMode == PageCountMode.Estimate ? "~" : String.Empty);
        }
 
        #endregion
    }
}

https://devillers.nl/blog/localizing-microsoft-reportviewer/

相關msdn鏈接:https://docs.microsoft.com/zh-cn/previous-versions/visualstudio/visual-studio-2010/dd468082(v=vs.100)

https://docs.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-2010/ms255036(v=vs.100)

https://docs.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-2010/ms255383%28v%3dvs.100%29

https://docs.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-2010/dd468082%28v%3dvs.100%29

可以通過實現三個IReportViewerMessages接口來本地化Microsoft ReportViewer Control 。但是,這些接口的文檔缺少原始的字符串值,這反過來又使得難以提供適當的轉換。在此博客中,提供了這些值的完整列表以及IReportViewerMessages的荷蘭語實現。

Microsoft ReportViewer

Microsoft ReportViewer是一個.NET控件,可以在Windows和Web應用程序中使用它來呈現Microsoft Reports。顧名思義,ReportViewer的功能遠不只是查看報告。該控件能夠加載(遠程)RDL文件,執行其內容並以各種格式(包括HTML,Excel,Word,PDF)呈現最終結果。呈現後,用戶可以與控件進行交互,以傳遞報告參數,瀏覽多頁報告等等。

ReportViewer本地化爲荷蘭的文化和語言。

ReportViewer本地化爲荷蘭的文化和語言。

在我當前的項目中,我們將ReportViewer嵌入到ASP MVC Web應用程序中。由於應用程序的受衆是荷蘭人,因此所有內容(包括ReportViewer)都必須本地化爲荷蘭文化。不幸的是,可用於ReportViewer的語言包不包括荷蘭語,因此我不得不提出一種替代解決方案。

善良

幸運的是,Microsoft在ReportViewer控件中包含了一種機制,該機制允許開發人員覆蓋默認消息。這是通過在利用ReportViewer的父應用程序中實現各種接口,然後將這些自定義實現傳遞給ReportViewer控件來實現的。

更具體地講,這些接口IReportViewerMessagesIReportViewerMessages2並且IReportViewerMessages3,它駐留在Microsoft.Reporting.WebForms命名空間(或的WinForms,如果你正在使用的)。這些接口實質上只是具有靜態硬編碼值的只讀字符串屬性的集合。

壞人

儘管Microsoft足夠優雅地記錄了 這些 接口,但它們的文檔缺少這些字符串屬性的原始值。結果,任何想要爲這些屬性創建有意義的翻譯的人都必須從屬性的名稱和描述而不是原始值中推斷出含義。這可能是當面對神祕的名字,如相當具有挑戰性ParameterAreaButtonToolTipNullValueTextClientPrintControlLoadFailed

醜陋的

儘管缺乏原始價值是一件令人討厭的事,但這絕不是一件容易的事。翻譯不善可能導致用戶面對看似不合適的消息,但應用程序本身仍將保持功能。或者我以爲:

輸入的字符串格式不正確。

首次嘗試本地化ReportViewer會導致FormatException

大多數.NET開發人員都會熟悉此異常,因爲它是String.Format被用格式字符串調用的結果,該格式字符串與要格式化的預期對象不匹配。換句話說,我要翻譯的一個或多個字符串使用了複合格式設置功能。如果沒有這些字符串的原始英文值,則可以猜測這些字符串中的哪些必須包含格式佔位符。

解決方案

爲了解決此問題,我對ReportViewer程序集進行了反編譯,並提取了這些屬性的原始字符串值。下面是我的荷蘭語IReportViewerMessages接口實現的版本。每個屬性均包含英文原始文本,因此您可以將其用作自己的翻譯的模板。

 

自然地,如果我沒有一些匹配的單元測試就粘貼代碼是不負責任的:

using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using InfoSupport.SomeApplication;
 
namespace InfoSupport.SomeApplication.Tests
{
    [TestClass]
    public class DutchReportViewerMessagesTests
    {
        [TestMethod]
        public void TranslatedStringsTests()
        {
            var m = new DutchReportViewerMessages();
            Assert.IsTrue(!String.IsNullOrEmpty(m.BackButtonToolTip));
            Assert.IsTrue(!String.IsNullOrEmpty(m.CalendarLoading));
            Assert.IsTrue(!String.IsNullOrEmpty(m.CancelLinkText));
            Assert.IsTrue(!String.IsNullOrEmpty(m.ChangeCredentialsText));
            Assert.IsTrue(!String.IsNullOrEmpty(m.ChangeCredentialsToolTip));
            Assert.IsTrue(!String.IsNullOrEmpty(m.ClientNoScript));
            Assert.IsTrue(!String.IsNullOrEmpty(m.ClientPrintControlLoadFailed));
            Assert.IsTrue(!String.IsNullOrEmpty(m.CredentialMissingUserNameError(null)));
            Assert.IsTrue(!String.IsNullOrEmpty(m.CurrentPageTextBoxToolTip));
            Assert.IsTrue(!String.IsNullOrEmpty(m.DocumentMap));
            Assert.IsTrue(!String.IsNullOrEmpty(m.DocumentMapButtonToolTip));
            Assert.IsTrue(!String.IsNullOrEmpty(m.ExportButtonText));
            Assert.IsTrue(!String.IsNullOrEmpty(m.ExportButtonToolTip));
            Assert.IsTrue(!String.IsNullOrEmpty(m.ExportFormatsToolTip));
            Assert.IsTrue(!String.IsNullOrEmpty(m.FalseValueText));
            Assert.IsTrue(!String.IsNullOrEmpty(m.FindButtonText));
            Assert.IsTrue(!String.IsNullOrEmpty(m.FindButtonToolTip));
            Assert.IsTrue(!String.IsNullOrEmpty(m.FindNextButtonText));
            Assert.IsTrue(!String.IsNullOrEmpty(m.FindNextButtonToolTip));
            Assert.IsTrue(!String.IsNullOrEmpty(m.FirstPageButtonToolTip));
            Assert.IsTrue(!String.IsNullOrEmpty(m.InvalidPageNumber));
            Assert.IsTrue(!String.IsNullOrEmpty(m.LastPageButtonToolTip));
            Assert.IsTrue(!String.IsNullOrEmpty(m.NextPageButtonToolTip));
            Assert.IsTrue(!String.IsNullOrEmpty(m.NoMoreMatches));
            Assert.IsTrue(!String.IsNullOrEmpty(m.NullCheckBoxText));
            Assert.IsTrue(!String.IsNullOrEmpty(m.NullValueText));
            Assert.IsTrue(!String.IsNullOrEmpty(m.PageOf));
            Assert.IsTrue(!String.IsNullOrEmpty(m.ParameterAreaButtonToolTip));
            Assert.IsTrue(!String.IsNullOrEmpty(m.ParameterDropDownToolTip));
            Assert.IsTrue(!String.IsNullOrEmpty(m.ParameterMissingSelectionError(String.Empty)));
            Assert.IsTrue(!String.IsNullOrEmpty(m.ParameterMissingValueError(String.Empty)));
            Assert.IsTrue(!String.IsNullOrEmpty(m.PasswordPrompt));
            Assert.IsTrue(!String.IsNullOrEmpty(m.PreviousPageButtonToolTip));
            Assert.IsTrue(!String.IsNullOrEmpty(m.PrintButtonToolTip));
            Assert.IsTrue(!String.IsNullOrEmpty(m.ProgressText));
            Assert.IsTrue(!String.IsNullOrEmpty(m.RefreshButtonToolTip));
            Assert.IsTrue(!String.IsNullOrEmpty(m.SearchTextBoxToolTip));
            Assert.IsTrue(!String.IsNullOrEmpty(m.SelectAll));
            Assert.IsTrue(!String.IsNullOrEmpty(m.SelectAValue));
            Assert.IsTrue(!String.IsNullOrEmpty(m.SelectFormat));
            Assert.IsTrue(!String.IsNullOrEmpty(m.TextNotFound));
            Assert.IsTrue(!String.IsNullOrEmpty(m.TodayIs));
            Assert.IsTrue(!String.IsNullOrEmpty(m.TrueValueText));
            Assert.IsTrue(!String.IsNullOrEmpty(m.UserNamePrompt));
            Assert.IsTrue(!String.IsNullOrEmpty(m.ViewReportButtonText));
            Assert.IsTrue(!String.IsNullOrEmpty(m.ZoomControlToolTip));
            Assert.IsTrue(!String.IsNullOrEmpty(m.ZoomToPageWidth));
            Assert.IsTrue(!String.IsNullOrEmpty(m.ZoomToWholePage));
        }
 
        [TestMethod]
        public void FormattableStringsTest()
        {
            var m = new DutchReportViewerMessages();
            var parameter = "abc123";
            Assert.IsTrue(m.ParameterMissingSelectionError(parameter).Contains(parameter));
            Assert.IsTrue(m.ParameterMissingValueError(parameter).Contains(parameter));
            Assert.IsTrue(String.Format(m.TodayIs, parameter).Contains(parameter));
        }
 
        [TestMethod]
        public void GetLocalizedNameForRenderingExtensionTest()
        {
            var m = new DutchReportViewerMessages();
            string[] knownExtensions = { "XML", "CSV", "PDF", "MHTML", "EXCEL", "IMAGE", "WORD"};
            foreach (var ext in knownExtensions)
                Assert.IsTrue(!String.IsNullOrEmpty(m.GetLocalizedNameForRenderingExtension(ext)));
        }
 
        [TestMethod]
        public void GetLocalizedNameForRenderingExtensionTest_UnknownExtensionReturnsNull()
        {
            var m = new DutchReportViewerMessages();
            string[] unknownExtensions = { "DOCX", "PNG", "JPG", "JPEG" };
            foreach (var ext in unknownExtensions)
                Assert.IsNull(m.GetLocalizedNameForRenderingExtension(ext));
        }
 
        [TestMethod]
        public void TotalPagesTest()
        {
            var m = new DutchReportViewerMessages();
            Assert.AreEqual("10",  m.TotalPages(10, Microsoft.Reporting.WebForms.PageCountMode.Actual));
            Assert.AreEqual("10~", m.TotalPages(10, Microsoft.Reporting.WebForms.PageCountMode.Estimate));
        }
    }
}

此外,下面是所有屬性的表格以及它們各自的英語和荷蘭語翻譯。請注意,該表不包括屬於接口的方法。

IREPORTVIEWER消息

物業名稱 原始英語價值 荷蘭語翻譯
BackButtonToolTip 返回上級報告 Terug naar het vorige融洽關係
ChangeCredentialsText 變更憑證 維希格·雷希滕
ChangeCredentialsToolTip 變更憑證 維希格·雷希滕
CurrentPageTextBoxToolTip 當前頁面 希迪格·帕吉納
DocumentMap 文件圖 文件圖
DocumentMapButtonToolTip 顯示/隱藏文檔圖 Toon / Verberg文檔圖
ExportButtonText 出口 出口商
ExportButtonToolTip 出口 出口商
ExportFormatsToolTip 導出格式 出口商格式化
FalseValueText Onwaar
FindButtonText 佐克
FindButtonToolTip 佐克
FindNextButtonText 下一個 伏根德
FindNextButtonToolTip 找下一個 Volgend結果
FirstPageButtonToolTip 第一頁 埃斯特·帕吉納(Eerste Pagina)
InvalidPageNumber 輸入有效的頁碼 Voer een geldig paginanummer在
LastPageButtonToolTip 最後一頁 Laatste Pagina
NextPageButtonToolTip 下一頁 Volgende Pagina
NoMore比賽 整個報告已被搜索。 混血兒和睦相處是doorzocht。
NullCheckBoxText 空值 吉恩·沃德
空值文本 空值 吉恩·沃德
PageOf 貨車
ParameterAreaButtonToolTip 顯示/隱藏參數 Toon / Verberg參數
密碼提示 密碼: Wachtwoord:
PreviousPageButtonToolTip 上一頁 沃裏格·帕吉納(Vorige Pagina)
打印按鈕工具提示 打印 阿夫德魯肯
ProgressText 載入中... Verwerken…
刷新按鈕工具提示 刷新 韋爾紐紐
SearchTextBoxToolTip 在報告中查找文本 Zoek Naar Tekst Binnen Het融洽
選擇值 <選擇值> <選帝侯瓦德>
全選 (全選) (選拔隊)
選擇格式 選擇格式 選擇者形成
TextNotFound 找不到搜索文字。 De zoektekst是niet gevonden。
今天是 今天是{0} Vandaag是{0}
TrueValueText 真正 Waar
用戶名提示 登錄名: Gebruikersnaam:
查看報告 ViewReportButtonText 卡通香椿
ZoomControlToolTip 放大 放大
ZoomToPageWidth 頁面寬度 Paginabreedte
縮放到整個頁面 整頁 Volledige Pagina

IREPORTVIEWERMESSAGES2

物業名稱 原始英語價值 荷蘭語翻譯
ClientNoScript 您的瀏覽器不支持腳本或已被配置爲不允許腳本。 Uw瀏覽器ondesteunting的deze ondersteuninging JavaScript是uitgeschakeld。
ClientPrintControlLoadFailed 無法加載客戶端打印控件。 雜貨客戶的打印控件是niet gelukt。
ParameterDropDownToolTip 選擇一個值 甄選人

IREPORTVIEWERMESSAGES3

物業名稱 原始英語價值 荷蘭語翻譯
日曆加載 載入中... Verwerken…
取消鏈接文字 取消 安樂兒

附加條款

  • 返回null將使ReportViewer默認返回原始值。將此屬性用於不希望轉換的字符串屬性或方法。
  • 要使ReportViewer接管您的自定義實施,需要更改應用程序的web.config或app.config。添加<add key="ReportViewerMessages" value="MyClass, MyAssembly" />到您的appSettings中,並用實現類及其所在的程序集的名稱替換MyClass和MyAssembly。

摘要

可以通過實現三個IReportViewerMessages接口來本地化Microsoft ReportViewer Control。但是,這些接口的文檔缺少原始的字符串值,從而使提供正確的轉換變得很困難。在此博客中,提供了這些值的完整列表以及IReportViewerMessages的荷蘭語實現。

https://docs.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-2010/aa992078%28v%3dvs.100%29

https://blogs.infosupport.com/localizing-microsoft-reportviewer/

  • 本地化Microsoft ReportViewer

     

    可以通過實現三個IReportViewerMessages接口來本地化Microsoft ReportViewer Control 。但是,這些接口的文檔缺少原始的字符串值,這反過來又使得難以提供適當的轉換。在此博客中,提供了這些值的完整列表以及IReportViewerMessages的荷蘭語實現。

     

    Microsoft ReportViewer

    Microsoft ReportViewer是一個.NET控件,可以在Windows和Web應用程序中使用它來呈現Microsoft Reports。顧名思義,ReportViewer的功能遠不只是查看報告。該控件能夠加載(遠程)RDL文件,執行其內容並以各種格式(包括HTML,Excel,Word,PDF)呈現最終結果。呈現後,用戶可以與控件進行交互,以傳遞報告參數,瀏覽多頁報告等等。

    ReportViewer本地化爲荷蘭的文化和語言。

    在我當前的項目中,我們將ReportViewer嵌入到ASP MVC Web應用程序中。由於應用程序的受衆是荷蘭人,因此所有內容(包括ReportViewer)都必須本地化爲荷蘭文化。不幸的是,可用於ReportViewer的語言包不包括荷蘭語,因此我不得不提出一種替代解決方案。

    善良

    幸運的是,Microsoft在ReportViewer控件中包含了一種機制,該機制允許開發人員覆蓋默認消息。這是通過在利用ReportViewer的父應用程序中實現各種接口,然後將這些自定義實現傳遞給ReportViewer控件來實現的。

    更具體地講,這些接口IReportViewerMessagesIReportViewerMessages2 並且IReportViewerMessages3,它駐留在Microsoft.Reporting.WebForms命名空間(或的WinForms,如果你正在使用的)。這些接口實質上只是具有靜態硬編碼值的只讀字符串屬性的集合。

    壞人

    儘管Microsoft足夠優雅地記錄了 這些 接口,但它們的文檔缺少這些字符串屬性的原始值。結果,任何想要爲這些屬性創建有意義的翻譯的人都必須從屬性的名稱和描述而不是原始值中推斷出含義。這可能是當面對神祕的名字,如相當具有挑戰性ParameterAreaButtonToolTipNullValueText ClientPrintControlLoadFailed

    醜陋的

    儘管缺乏原始價值是一件令人討厭的事,但這絕不是一件容易的事。翻譯不善可能導致用戶面對看似不合適的消息,但應用程序本身仍將保持功能。或者我以爲:

    首次嘗試本地化ReportViewer會導致FormatException

    大多數.NET開發人員都將熟悉此異常,因爲它是String.Format用格式字符串調用的結果,該字符串與要格式化的預期對象不匹配。換句話說,我要翻譯的一個或多個字符串使用了複合格式設置功能。如果沒有這些字符串的原始英文值,則可以猜測這些字符串中的哪些必須包含格式佔位符。

    解決方案

    爲了解決此問題,我對ReportViewer程序集進行了反編譯,並提取了這些屬性的原始字符串值。下面是我的荷蘭語IReportViewerMessages接口實現的版本。每個屬性均包含英文原始文本,因此您可以將其用作自己的翻譯的模板。

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    using System;
    using System.Globalization;
    using Microsoft.Reporting.WebForms;
     
    namespace InfoSupport.SomeApplication
    {
        public class DutchReportViewerMessages : IReportViewerMessages, IReportViewerMessages2, IReportViewerMessages3
        {
            #region IReportViewerMessages Members
     
            // English value: Back to Parent Report
            public string BackButtonToolTip
            {
                get { return &quot;Terug naar het vorige rapport&quot;; }
            }
     
            // English value: Change Credentials
            public string ChangeCredentialsText
            {
                get { return &quot;Wijzig Rechten&quot;; }
            }
     
            // English value: Change Credentials
            public string ChangeCredentialsToolTip
            {
                get { return &quot;Wijzig Rechten&quot;; }
            }
     
            // English value: Current Page
            public string CurrentPageTextBoxToolTip
            {
                get { return &quot;Huidige Pagina&quot;; }
            }
     
            // English value: Document Map
            public string DocumentMap
            {
                get { return &quot;Document Map&quot;; }
            }
     
            // English value: Show / Hide Document Map
            public string DocumentMapButtonToolTip
            {
                get { return &quot;Toon / Verberg Document Map&quot;; }
            }
     
            // English value: Export
            public string ExportButtonText
            {
                get { return &quot;Exporteer&quot;; }
            }
     
            // English value: Export
            public string ExportButtonToolTip
            {
                get { return &quot;Exporteer&quot;; }
            }
     
            // English value: Export Formats
            public string ExportFormatsToolTip
            {
                get { return &quot;Exporteer Formaten&quot;; }
            }
     
            // English value: False
            public string FalseValueText
            {
                get { return &quot;Onwaar&quot;; }
            }
     
            // English value: Find
            public string FindButtonText
            {
                get { return &quot;Zoek&quot;; }
            }
     
            // English value: Find
            public string FindButtonToolTip
            {
                get { return &quot;Zoek&quot;; }
            }
     
            // English value: Next
            public string FindNextButtonText
            {
                get { return &quot;Volgende&quot;; }
            }
     
            // English value: Find Next
            public string FindNextButtonToolTip
            {
                get { return &quot;Volgend Resultaat&quot;; }
            }
     
            // English value: First Page
            public string FirstPageButtonToolTip
            {
                get { return &quot;Eerste Pagina&quot;; }
            }
     
            // English value: Enter a valid page number
            public string InvalidPageNumber
            {
                get { return &quot;Voer een geldig paginanummer in&quot;; }
            }
     
            // English value: Last Page
            public string LastPageButtonToolTip
            {
                get { return &quot;Laatste Pagina&quot;; }
            }
     
            // English value: Next Page
            public string NextPageButtonToolTip
            {
                get { return &quot;Volgende Pagina&quot;; }
            }
     
            // English value: The entire report has been searched.
            public string NoMoreMatches
            {
                get { return &quot;Het volledige rapport is doorzocht.&quot;; }
            }
     
            // English value: NULL
            public string NullCheckBoxText
            {
                get { return &quot;Geen waarde&quot;; }
            }
     
            // English value: Null
            public string NullValueText
            {
                get { return &quot;Geen waarde&quot;; }
            }
     
            // English value: of
            public string PageOf
            {
                get { return &quot;van&quot;; }
            }
     
            // English value: Show / Hide Parameters
            public string ParameterAreaButtonToolTip
            {
                get { return &quot;Toon / Verberg Parameters&quot;; }
            }
     
            // English value: Password:
            public string PasswordPrompt
            {
                get { return &quot;Wachtwoord:&quot;; }
            }
     
            // English value: Previous Page
            public string PreviousPageButtonToolTip
            {
                get { return &quot;Vorige Pagina&quot;; }
            }
     
            // English value: Print
            public string PrintButtonToolTip
            {
                get { return &quot;Afdrukken&quot;; }
            }
     
            // English value: Loading...
            public string ProgressText
            {
                get { return &quot;Verwerken...&quot;; }
            }
     
            // English value: Refresh
            public string RefreshButtonToolTip
            {
                get { return &quot;Vernieuwen&quot;; }
            }
     
            // English value: Find Text in Report
            public string SearchTextBoxToolTip
            {
                get { return &quot;Zoek naar tekst binnen het rapport&quot;; }
            }
     
            // English value: <Select a Value>
            public string SelectAValue
            {
                get { return &quot;<Selecteer een waarde>&quot;; }
            }
     
            // English value: (Select All)
            public string SelectAll
            {
                get { return &quot;(Selecteer alles)&quot;; }
            }
     
            // English value: Select a format
            public string SelectFormat
            {
                get { return &quot;Selecteer een formaat&quot;; }
            }
     
            // English value: The search text was not found.
            public string TextNotFound
            {
                get { return &quot;De zoektekst is niet gevonden.&quot;; }
            }
     
            // English value: Today is {0}
            public string TodayIs
            {
                get { return &quot;Vandaag is {0}&quot;; }
            }
     
            // English value: True
            public string TrueValueText
            {
                get { return &quot;Waar&quot;; }
            }
     
            // English value: Log In Name:
            public string UserNamePrompt
            {
                get { return &quot;Gebruikersnaam:&quot;; }
            }
     
            // English value: View Report
            public string ViewReportButtonText
            {
                get { return &quot;Toon Rapport&quot;; }
            }
     
            // English value: Zoom
            public string ZoomControlToolTip
            {
                get { return &quot;Zoom&quot;; }
            }
     
            // English value: Page Width
            public string ZoomToPageWidth
            {
                get { return &quot;Paginabreedte&quot;; }
            }
     
            // English value: Whole Page
            public string ZoomToWholePage
            {
                get { return &quot;Volledige pagina&quot;; }
            }
     
            #endregion
     
            #region IReportViewerMessages2 Members
     
            // English value: Your browser does not support scripts or has been configured not to allow scripts.
            public string ClientNoScript
            {
                get { return &quot;Uw browser ondersteunt geen JavaScript of deze ondersteuning is uitgeschakeld.&quot;; }
            }
     
            // English value: Unable to load client print control.
            public string ClientPrintControlLoadFailed
            {
                get { return &quot;Het laden van het client print control is niet gelukt.&quot;; }
            }
     
            // English value: One or more data sources is missing a user name.
            public string CredentialMissingUserNameError(string dataSourcePrompt)
            {
                return &quot;Een of meerdere databronnen missen een gebruikersnaam.&quot;;
            }
     
            // English value is different for each Rendering Extension. See comment behind each type.
            public string GetLocalizedNameForRenderingExtension(string format)
            {
                switch (format)
                {
                    case &quot;XML&quot;   : return &quot;XML databestand (.xml)&quot;;  // XML file with report data
                    case &quot;CSV&quot;   : return &quot;CSV databestand (.csv)&quot;;  // CSV (comma delimited)
                    case &quot;PDF&quot;   : return &quot;PDF document (.pdf)&quot;;     // PDF
                    case &quot;MHTML&quot; : return &quot;Webarchief (.mhtml)&quot;;     // MHTML (web archive)
                    case &quot;EXCEL&quot; : return &quot;Excel rekenblad (.xls)&quot;;  // Excel
                    case &quot;IMAGE&quot; : return &quot;Afbeelding (.tif)&quot;;       // TIFF file
                    case &quot;WORD&quot;  : return &quot;Word document (.doc)&quot;;    // Word
                    default      : return null;
                }
            }
     
            // English value: Select a value
            public string ParameterDropDownToolTip
            {
                get { return &quot;Selecteer een waarde&quot;; }
            }
     
            // English value: Please select a value for the parameter '{0}'.
            public string ParameterMissingSelectionError(string parameterPrompt)
            {
                return String.Format(CultureInfo.CurrentCulture, &quot;Selecteer een waarde voor de parameter '{0}'&quot;, parameterPrompt);
            }
     
            // English value: Please enter a value for the parameter '{0}'. The parameter cannot be blank.
            public string ParameterMissingValueError(string parameterPrompt)
            {
                return String.Format(CultureInfo.CurrentCulture, &quot;Selecteer een waarde voor de parameter '{0}'. De parameter mag niet leeg zijn.&quot;, parameterPrompt);
            }
     
            #endregion
     
            #region IReportViewerMessages3 Members
     
            // English value: Loading...
            public string CalendarLoading
            {
                get { return &quot;Verwerken...&quot;; }
            }
     
            // English value: Cancel
            public string CancelLinkText
            {
                get { return &quot;Annuleer&quot;; }
            }
     
            // English value: pageCount if PageCountMode.Actual, else pageCount suffixed with a ?
            public string TotalPages(int pageCount, PageCountMode pageCountMode)
            {
                return string.Format(CultureInfo.CurrentCulture, &quot;{0}{1}&quot;, pageCount, pageCountMode == PageCountMode.Estimate ? &quot;~&quot; : String.Empty);
            }
     
            #endregion
        }
    }

    自然地,如果我沒有一些匹配的單元測試就粘貼代碼是不負責任的:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    using System;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using InfoSupport.SomeApplication;
     
    namespace InfoSupport.SomeApplication.Tests
    {
        [TestClass]
        public class DutchReportViewerMessagesTests
        {
            [TestMethod]
            public void TranslatedStringsTests()
            {
                var m = new DutchReportViewerMessages();
                Assert.IsTrue(!String.IsNullOrEmpty(m.BackButtonToolTip));
                Assert.IsTrue(!String.IsNullOrEmpty(m.CalendarLoading));
                Assert.IsTrue(!String.IsNullOrEmpty(m.CancelLinkText));
                Assert.IsTrue(!String.IsNullOrEmpty(m.ChangeCredentialsText));
                Assert.IsTrue(!String.IsNullOrEmpty(m.ChangeCredentialsToolTip));
                Assert.IsTrue(!String.IsNullOrEmpty(m.ClientNoScript));
                Assert.IsTrue(!String.IsNullOrEmpty(m.ClientPrintControlLoadFailed));
                Assert.IsTrue(!String.IsNullOrEmpty(m.CredentialMissingUserNameError(null)));
                Assert.IsTrue(!String.IsNullOrEmpty(m.CurrentPageTextBoxToolTip));
                Assert.IsTrue(!String.IsNullOrEmpty(m.DocumentMap));
                Assert.IsTrue(!String.IsNullOrEmpty(m.DocumentMapButtonToolTip));
                Assert.IsTrue(!String.IsNullOrEmpty(m.ExportButtonText));
                Assert.IsTrue(!String.IsNullOrEmpty(m.ExportButtonToolTip));
                Assert.IsTrue(!String.IsNullOrEmpty(m.ExportFormatsToolTip));
                Assert.IsTrue(!String.IsNullOrEmpty(m.FalseValueText));
                Assert.IsTrue(!String.IsNullOrEmpty(m.FindButtonText));
                Assert.IsTrue(!String.IsNullOrEmpty(m.FindButtonToolTip));
                Assert.IsTrue(!String.IsNullOrEmpty(m.FindNextButtonText));
                Assert.IsTrue(!String.IsNullOrEmpty(m.FindNextButtonToolTip));
                Assert.IsTrue(!String.IsNullOrEmpty(m.FirstPageButtonToolTip));
                Assert.IsTrue(!String.IsNullOrEmpty(m.InvalidPageNumber));
                Assert.IsTrue(!String.IsNullOrEmpty(m.LastPageButtonToolTip));
                Assert.IsTrue(!String.IsNullOrEmpty(m.NextPageButtonToolTip));
                Assert.IsTrue(!String.IsNullOrEmpty(m.NoMoreMatches));
                Assert.IsTrue(!String.IsNullOrEmpty(m.NullCheckBoxText));
                Assert.IsTrue(!String.IsNullOrEmpty(m.NullValueText));
                Assert.IsTrue(!String.IsNullOrEmpty(m.PageOf));
                Assert.IsTrue(!String.IsNullOrEmpty(m.ParameterAreaButtonToolTip));
                Assert.IsTrue(!String.IsNullOrEmpty(m.ParameterDropDownToolTip));
                Assert.IsTrue(!String.IsNullOrEmpty(m.ParameterMissingSelectionError(String.Empty)));
                Assert.IsTrue(!String.IsNullOrEmpty(m.ParameterMissingValueError(String.Empty)));
                Assert.IsTrue(!String.IsNullOrEmpty(m.PasswordPrompt));
                Assert.IsTrue(!String.IsNullOrEmpty(m.PreviousPageButtonToolTip));
                Assert.IsTrue(!String.IsNullOrEmpty(m.PrintButtonToolTip));
                Assert.IsTrue(!String.IsNullOrEmpty(m.ProgressText));
                Assert.IsTrue(!String.IsNullOrEmpty(m.RefreshButtonToolTip));
                Assert.IsTrue(!String.IsNullOrEmpty(m.SearchTextBoxToolTip));
                Assert.IsTrue(!String.IsNullOrEmpty(m.SelectAll));
                Assert.IsTrue(!String.IsNullOrEmpty(m.SelectAValue));
                Assert.IsTrue(!String.IsNullOrEmpty(m.SelectFormat));
                Assert.IsTrue(!String.IsNullOrEmpty(m.TextNotFound));
                Assert.IsTrue(!String.IsNullOrEmpty(m.TodayIs));
                Assert.IsTrue(!String.IsNullOrEmpty(m.TrueValueText));
                Assert.IsTrue(!String.IsNullOrEmpty(m.UserNamePrompt));
                Assert.IsTrue(!String.IsNullOrEmpty(m.ViewReportButtonText));
                Assert.IsTrue(!String.IsNullOrEmpty(m.ZoomControlToolTip));
                Assert.IsTrue(!String.IsNullOrEmpty(m.ZoomToPageWidth));
                Assert.IsTrue(!String.IsNullOrEmpty(m.ZoomToWholePage));
            }
     
            [TestMethod]
            public void FormattableStringsTest()
            {
                var m = new DutchReportViewerMessages();
                var parameter = &quot;abc123&quot;;
                Assert.IsTrue(m.ParameterMissingSelectionError(parameter).Contains(parameter));
                Assert.IsTrue(m.ParameterMissingValueError(parameter).Contains(parameter));
                Assert.IsTrue(String.Format(m.TodayIs, parameter).Contains(parameter));
            }
     
            [TestMethod]
            public void GetLocalizedNameForRenderingExtensionTest()
            {
                var m = new DutchReportViewerMessages();
                string[] knownExtensions = { &quot;XML&quot;, &quot;CSV&quot;, &quot;PDF&quot;, &quot;MHTML&quot;, &quot;EXCEL&quot;, &quot;IMAGE&quot;, &quot;WORD&quot;};
                foreach (var ext in knownExtensions)
                    Assert.IsTrue(!String.IsNullOrEmpty(m.GetLocalizedNameForRenderingExtension(ext)));
            }
     
            [TestMethod]
            public void GetLocalizedNameForRenderingExtensionTest_UnknownExtensionReturnsNull()
            {
                var m = new DutchReportViewerMessages();
                string[] unknownExtensions = { &quot;DOCX&quot;, &quot;PNG&quot;, &quot;JPG&quot;, &quot;JPEG&quot; };
                foreach (var ext in unknownExtensions)
                    Assert.IsNull(m.GetLocalizedNameForRenderingExtension(ext));
            }
     
            [TestMethod]
            public void TotalPagesTest()
            {
                var m = new DutchReportViewerMessages();
                Assert.AreEqual(&quot;10&quot;,  m.TotalPages(10, Microsoft.Reporting.WebForms.PageCountMode.Actual));
                Assert.AreEqual(&quot;10~&quot;, m.TotalPages(10, Microsoft.Reporting.WebForms.PageCountMode.Estimate));
            }
        }
    }

    此外,下面是所有屬性的表格以及它們各自的英語和荷蘭語翻譯。請注意,該表不包括屬於接口的方法。

    IReportViewerMessages

    物業名稱 原始英文價值 荷蘭語翻譯
    BackButtonToolTip Back to Parent Report Terug naar het vorige rapport
    ChangeCredentialsText Change Credentials Wijzig Rechten
    ChangeCredentialsToolTip Change Credentials Wijzig Rechten
    CurrentPageTextBoxToolTip Current Page Huidige Pagina
    DocumentMap Document Map Document Map
    DocumentMapButtonToolTip Show / Hide Document Map Toon / Verberg Document Map
    ExportButtonText Export Exporteer
    ExportButtonToolTip Export Exporteer
    ExportFormatsToolTip Export Formats Exporteer Formaten
    FalseValueText False Onwaar
    FindButtonText Find Zoek
    FindButtonToolTip Find Zoek
    FindNextButtonText Next Volgende
    FindNextButtonToolTip Find Next Volgend Resultaat
    FirstPageButtonToolTip First Page Eerste Pagina
    InvalidPageNumber Enter a valid page number Voer een geldig paginanummer in
    LastPageButtonToolTip Last Page Laatste Pagina
    NextPageButtonToolTip Next Page Volgende Pagina
    NoMoreMatches The entire report has been searched. Het volledige rapport is doorzocht.
    NullCheckBoxText NULL Geen waarde
    NullValueText Null Geen waarde
    PageOf of van
    ParameterAreaButtonToolTip Show / Hide Parameters Toon / Verberg Parameters
    PasswordPrompt Password: Wachtwoord:
    PreviousPageButtonToolTip Previous Page Vorige Pagina
    PrintButtonToolTip Print Afdrukken
    ProgressText Loading... Verwerken...
    RefreshButtonToolTip Refresh Vernieuwen
    SearchTextBoxToolTip Find Text in Report Zoek naar tekst binnen het rapport
    SelectAValue <Select a Value> <Selecteer een waarde>
    SelectAll (Select All) (Selecteer alles)
    SelectFormat Select a format Selecteer een formaat
    TextNotFound The search text was not found. De zoektekst is niet gevonden.
    TodayIs Today is {0} Vandaag is {0}
    TrueValueText True Waar
    UserNamePrompt Log In Name: Gebruikersnaam:
    View Report ViewReportButtonText Toon Rapport
    ZoomControlToolTip Zoom Zoom
    ZoomToPageWidth Page Width Paginabreedte
    ZoomToWholePage Whole Page Volledige pagina

    IReportViewerMessages2

    物業名稱 原始英文價值 荷蘭語翻譯
    ClientNoScript Your browser does not support scripts or has been configured not to allow scripts. Uw browser ondersteunt geen JavaScript of deze ondersteuning is uitgeschakeld.
    ClientPrintControlLoadFailed Unable to load client print control. Het laden van het client print control is niet gelukt.
    ParameterDropDownToolTip Select a value Selecteer een waarde

    IReportViewerMessages3

    物業名稱 原始英文價值 荷蘭語翻譯
    CalendarLoading Loading... Verwerken...
    CancelLinkText Cancel Annuleer

    附加條款

    • 返回null將使ReportViewer默認返回原始值。將此屬性用於不希望轉換的字符串屬性或方法。
    • 要使ReportViewer接管您的自定義實施,需要更改應用程序的web.config或app.config。將以下行添加到您的appSettings中,並用實現類及其所在的程序集的名稱替換MyClass和MyAssembly。

馬丁·戴維勒斯

 

查看資料

10條評論

  1. 這是您需要在web.config中實現的鍵,以使ReportViewer加載已實現的類。

    comaunite/ 6年前

  2. comaunite/ 6年前

  3. http://msdn.microsoft.com/en-us/library/microsoft.reporting.webforms.ireportviewermessages2.aspx

    在那裏,您可以在web.config中找到所需的密鑰,以便ReportViewer加載您的類。(對垃圾評論很抱歉,網站似乎刪除了這些標籤(或嘗試使用該標籤))

    comaunite/ 6年前

    • 謝謝,看來您並不是唯一一個在使用標籤的人:片段實際上是在博客的末尾,在“將以下行添加到您的appSettings中,並用實現類的名稱和MyClass和MyAssembly代替”,但當我發佈博客時似乎已被省略。我將查看是否可以還原該代碼段。再次感謝您的關注

      馬丁·戴維勒斯/ 6年前

  4. 這是VS2005的嗎,因爲我使用2008,所以我得到了更多的字符串。

    斯塔凡·維爾坎斯/ 6年前

    • 您還會看到哪些額外的字符串?您是否實現了IReportViewerMessages,IReportViewerMessages2和IReportViewerMessages3?

      馬丁·戴維勒斯/ 6年前

  5. 嗨,馬丁,
    我對Reportviewer有一個不同的問題。我想在reportviewer中顯示HTM1。我注意到內容並未呈現所有HTM1標籤。有沒有解決的辦法,或者沒有可能性,
    我有一個保存HTML內容(即HTML標籤)的字段,所以我需要將其顯示在reportviewer中。讓我知道是否有任何可能性

    Jiju/ 6年前

  6. 非常感謝,辛苦了。我整日忙於搜索如何更改默認驗證消息,發現只有答案“無法完成”。在這裏!(實際上,我錯過了這2個其他接口)

    謝謝
    Slawek

    斯拉維克/ 5年前

  7. 這可以正常工作,但是當報表中有下拉菜單時,當我從下拉菜單中選擇一個新值並單擊“查看報表”按鈕時,控件默認爲英語。請幫助我解決這個問題。

    馬達裏/ 4年前

  8. 非常感謝。有沒有一種方法可以本地化警報
    “爲報告參數…提供的值對其類型無效。(rsReportParameterTypeMismatch)”?

 

https://tutorialmore.com/questions-364157.htm

我在ASP.NET MVC應用程序中使用報表查看器來查看報表。我的系統和瀏覽器文化是法語。當您在Visual Studio中打開報表或直接從服務器(在瀏覽器中)打開時,界面爲法語。但是,使用reportviewer時,界面爲英語。我如何用法語獲得它?

嘗試將頁面文化設置爲法語,如下所示:



 
  1. (`UICulture="fr-FR"`)
  2.  

或將組裝文化從中性更改爲自動:



 
  1. <%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=11.0.0.0, Culture=auto`...
  2.  

但是,沒有結果。



 
  1. System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("fr-FR");
  2. String reportFolder = System.Configuration.ConfigurationManager.AppSettings["SSRSReportsFolder"].ToString();
  3. rvSiteMapping.Height = Unit.Pixel(Convert.ToInt32(Request["Height"]) - 58);
  4. rvSiteMapping.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Remote;
  5. rvSiteMapping.ServerReport.ReportServerUrl = new Uri("http://server/PREPROD/");
  6. rvSiteMapping.ServerReport.ReportPath = String.Format("/{0}/{1}", reportFolder, Request["ReportName"].ToString());
  7. rvSiteMapping.ServerReport.Refresh();
  8.  
  • 解決的方法1

    我正在嘗試通過以下信息解決此問題:https://devillers.nl/blog/localizing-microsoft-reportviewer/

    這個想法是實現以下接口:

    
    
     
    1. public class FrenchReportViewerMessages : IReportViewerMessages, IReportViewerMessages2, IReportViewerMessages3
    2. {
    3. #region IReportViewerMessages Members
    4. // English value: Back to Parent Report
    5. public string BackButtonToolTip
    6. {
    7. get { return "Terug naar het vorige rapport"; }
    8. }
    9. ...
    10.  

    並將以下內容添加到web.config中:

    
    
     
    1. <add key="ReportViewerMessages" value="FrenchReportViewerMessages, MyAssembly" />
    2.  

    似乎是一種解決方案,但現在我得到一個錯誤:找不到類型'FrenchReportViewerMessages,MyAssembly'

 

第一次使用接口 --ReportViewer改變顯示語言

學會使用msdn

ReportViewer是一個winform控件,想讓控件裏文本全部顯示爲英文。

因爲是微軟封裝的,所以無法直接改動,這是就應該考慮微軟會提供接口。

搜索發現ReportViewer有實現本地化的IReportViewerMessages3接口,它繼承IReportViewerMessages,IReportViewerMessages2.

三個接口很類似應該都看一下,在註釋和示例裏會描述怎麼使用接口,IReportViewerMessages3只有註釋,沒有示例,看了還不清楚該怎麼用,幸好在IReportViewerMessages裏看到了示例,根據註釋的描述和示例的代碼基本可以看懂怎麼使用IReportViewerMessages3接口了。

 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章