Localization in .NET MAUI PDF Viewer (SfPdfViewer)

13 Mar 20243 minutes to read

Localization is the process of translating the application resources into a different language for the specific cultures. SfPdfViewer 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 SfPdfViewer can be localized to a different language.

Follow the instructions given to apply localization to the SfPdfViewer.

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 PdfViewerLocalization;

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.

  1. Right-click on the Resources folder in the application.

    Resources folder in the .NET MAUI PDF Viewer application.

  2. Click the Add option and then select NewItem.

    Add new item in the .NET MAUI PDF Viewer application.

  3. In the Add New Item wizard, select the Resource File option and name the file in the format <control name>.<culture name>.resx. For example, name the file as SfPdfViewer.fr.resx for French culture.

    Adding resource file in the .NET MAUI PDF Viewer application.

  4. Click the Add option to add the resource file in the Resources folder.

  5. Change the Build Action of the resource file as Embedded resource.

    Build action of resource file

  6. Double tap on the resource file to add the name and value details in the Resource Designer.

  7. Set the ResourceManager as shown in the following code example, that looks up the resource file with the specified root name.

using System.Resources;
using System.Globalization;
using Syncfusion.Maui.PdfViewer;

namespace PdfViewerLocalization;

public partial class App : Application
{
	public App()
	{
		InitializeComponent();
        CultureInfo.CurrentUICulture = new CultureInfo("fr-FR");
        SfPdfViewerResources.ResourceManager = new ResourceManager("PdfViewerLocalization.Resources.SfPdfViewer", 
			Application.Current.GetType().Assembly);
        MainPage = new AppShell();
	}
}

Default names and values

The following table contains the default name and value details used in the SfPdfViewer in the en-US

Name Value
Cancel CANCEL
CanOpenWebPage Do you want to open
Close CLOSE
DocumentLoadFailed Failed to load the PDF document.
EnterPassword Enter Password
Error Error
NoOutline No outline
Ok OK
Open OPEN
OpenWebPage Open Web Page
Outline Outline
PasswordErrorHint Check your password
RequestPassword This PDF file is protected. Please enter the password to open it.
Copy Copy
Highlight Highlight
Save Save
Squiggly Squiggly
Strikeout Strikeout
Underline Underline
StickyNoteEditorPlaceholder Write Your Note...
FreeTextEditorPlaceHolder Text...
AddFreeTextToastMessage Tap on the page to add the free text annotation
Draw your signature Draw your signature
Color Color
Clear Clear
Add Signature Add Signature
Draw Draw
Type Type
Upload Upload
Type your signature Type your signature
Signature Signature
Create Create
Insert Insert
Upload an image Upload an image
Drag and drop an image here Drag and drop an image here