Localization in .NET MAUI Smart PDF Viewer
22 Sep 20267 minutes to read
Localization is the process of translating the application resources into a different language for specific cultures. SfSmartPdfViewer is set up by default with the language code en-US. However, by including a resource file (.resx) in the application with the language code, the static text used in the SfSmartPdfViewer can be localized to a different language.
The Smart PDF Viewer uses the SfSmartPdfViewerResources accessor, which falls back to the built-in English strings whenever a localized value is not found.
Change the current user interface culture
Set the CurrentUICulture property in the App.xaml.cs file to the desired user interface culture. Refer to the following code sample to change the current culture to French.
using System.Globalization;
namespace SmartPdfViewerLocalization;
public partial class App : Application
{
public App()
{
InitializeComponent();
CultureInfo.CurrentUICulture = new CultureInfo("fr-FR");
MainPage = new AppShell();
}
}Create and add the resource file to the application
Follow the given steps to create and add the resource file to the application.
-
Right-click on the
Resourcesfolder in the application. -
Click the
Addoption and then selectNew Item. -
In the
Add New Itemwizard, select theResource Fileoption and name the file in the format<control name>.<culture name>.resx. For example, name the file asSfSmartPdfViewer.fr.resxfor theFrenchculture. -
Click the
Addoption to add the resource file to the Resources folder. -
Change the
Build Actionof the resource file toEmbedded Resource. -
Double-click the resource file to add the name and value details in the Resource Designer. Use the names listed in the default names and values section below.
-
Set the
ResourceManageras shown in the following code example, which looks up the resource file with the specified root name.
using System.Resources;
using System.Globalization;
using Syncfusion.Maui.SmartPdfViewer;
namespace SmartPdfViewerLocalization;
public partial class App : Application
{
public App()
{
InitializeComponent();
CultureInfo.CurrentUICulture = new CultureInfo("fr-FR");
SfSmartPdfViewerResources.ResourceManager = new ResourceManager("SmartPdfViewerLocalization.Resources.SfSmartPdfViewer",
Application.Current.GetType().Assembly);
MainPage = new AppShell();
}
}When localizing multiple Syncfusion MAUI controls in a .NET MAUI application, it’s important to understand that these controls support only a single ResourceManager instance for localization. If you assign different ResourceManager instances for separate resource (.resx) files, the last-assigned ResourceManager will override the others. This can result in incomplete or incorrect localization across your controls. To ensure consistent and accurate localization, consolidate all localization keys (name-value pairs) into a single resource (.resx) file and assign the ResourceManager using that unified resource file, as shown below:
using Syncfusion.Maui.Core.Localization; // Assign the ResourceManager using the unified .resx file LocalizationResourceAccessor.ResourceManager = new ResourceManager("Localization.Resources.SyncfusionControls", Application.Current.GetType().Assembly); // Replace the above string with your resource file's actual namespace and name.
The Smart PDF Viewer inherits the core PDF Viewer features from SfPdfViewer. To localize the core PDF Viewer text (toolbars, annotations, forms, and so on), include the
SfPdfViewerresource keys in the same resource file, as described in the PDF Viewer localization documentation. The Smart PDF Viewer also reuses some core viewer keys — for example,OkandCanceldisplayed in the redaction confirmation and AI failure warning dialogs are resolved through theSfPdfViewerresources.
Default names and values
The following table contains the default name and value details used in the SfSmartPdfViewer in the en-US culture.
The default values listed below are the hard-coded fallback strings in the
SfSmartPdfViewerResourcesaccessor. When a localized value is found in the assigned resource file, it overrides the default value.
| Name | Value |
|---|---|
| AIAssist | AI Assist |
| AssistViewHeaderText | Can I help you? |
| AIAssistanceDescription | How can I help you with this document? |
| AIAssistanceTitle | AI Assistance |
| AIServiceNotAvailableContent | No AI service has been configured for Smart PDF Viewer. |
| AIServiceNotAvailableTitle | AI Service Not Available |
| AITools | AI Tools |
| AIModelNotReadyContent | The AI model is still preparing the document. Please try again in a few moments. |
| AIModelNotReadyTitle | AI Not Ready |
| AuthenticationFailedContent | The credentials were not provided, incorrect, or invalid. Please verify your AI configuration. |
| AuthenticationFailedTitle | Authentication Failed |
| ConnectionErrorContent | The connection to the AI service has been lost. Please check your network connection and try again. |
| ConnectionErrorTitle | Connection Error |
| DisclaimerContent | AI-generated content may contain inaccuracies. |
| NoInformationErrorContent | No sensitive information was found in the document. |
| NoInformationErrorContentHeader | No Data Found |
| NoPatternSelectedContent | Please select at least one pattern. |
| NoPatternSelectedTitle | Pattern Required |
| ModelNotAvailableContent | The configured AI model is unavailable or does not exist. |
| ModelNotAvailableTitle | Model Not Available |
| RateLimitExceededContent | The AI service rate limit has been exceeded. Please try again later. |
| RateLimitExceededTitle | Rate Limit Exceeded |
| Redact | Redact |
| RedactDisclaimer | AI-detected information may not be accurate. Please verify results before use. |
| RedactOptionsHeader | Select the pattern |
| Scan | Scan |
| RedactViewHeader | Select the patterns |
| SmartFill | Smart Fill |
| SmartRedaction | Smart Redaction |
| TimeOutErrorContent | Your search request took longer than expected and exceeded the maximum allowed time. |
| TimeOutErrorTitle | Request Timeout |
| UnsupportedFileErrorContent | This file doesn't support generative AI features because it's blank or doesn't contain enough text. Please try a different file. |
| UnSupportedFileErrorTitle | Unsupported File |
Localizing the redaction patterns
The default redaction pattern names (Person Names, Organization Names, Email Addresses, Phone Numbers, Addresses, Dates, Account Numbers, and Credit Card Numbers) shown in the Smart Redaction panel are provided through the RedactPatterns property. To present these patterns in a different language, assign the localized pattern names to the SmartRedactSettings.RedactPatterns property.
using System.Globalization;
using Syncfusion.Maui.SmartPdfViewer;
. . .
SfSmartPdfViewer pdfViewer = new SfSmartPdfViewer
{
SmartRedactSettings = new SmartRedactSettings
{
RedactPatterns = CultureInfo.CurrentUICulture.TwoLetterISOLanguageName == "fr"
? new string[] { "Noms de personnes", "Noms d'organisations", "Adresses e-mail", "Numéros de téléphone", "Adresses", "Dates", "Numéros de compte", "Numéros de carte de crédit" }
: new string[]
{
"Person Names",
"Organization Names",
"Email Addresses",
"Phone Numbers",
"Addresses",
"Dates",
"Account Numbers",
"Credit Card Numbers"
}
}
};Custom redaction patterns supplied via
RedactPatternsare sent to the AI service as-is for detection. Verify that the configured AI model understands the localized pattern names.