Localization
The ComPDFKit SDK for Flutter comes with the following built-in languages:
- English(en)
- Chinese Simplified (zh-Hans)
Adding Additional Localization to ComPDFKit
Android Platform
You can add additional translations by putting them into the res/strings-XX
directory of your app. Android will automatically merge all string resources at build time. You can also override ComPDFKit strings of existing languages by putting them into the respective string folders.
Tip: To view a list of all available ComPDFKit string resources, copy them to your project from the following URL:
Here’s an example of adding French language support:
Create a
app/src/main/res/values-fr
directory in your project, and create astrings.xml
file within it.Copy the content from the link above into your
strings.xml
file.
- Translate the strings into French. For example:
Original content:
<string name="tools_document_info">Document Info</string>
Translate it to French and replace the original content:
<string name="tools_document_info">Informations du document</string>
Switch your device to French, and after running your project, you will see the translated content:
iOS Platform
Configure the languages that require internationalization
Open your Flutter project's iOS project using Xcode.Then, Select project -> Info -> Localizations, then click '+', add the desired language for internationalization/localization, as shown below (Make sure to check 'Use Base Internationalization' by default):
Here, we'll use adding French as an example, as shown below:
Pop up the following dialog, and click 'Finish' directly, as shown below:
Internationalizing the application name
Internationalizing the application name refers to displaying different names for the same app in various language environments (i.e., the language settings on the mobile device).
Creating
Localizable.strings
fileSelect
Localizable.strings
, click on Localize in the File inspection (right-side file inspector) in Xcode. The purpose is to choose the language we want to localize, as shown below:Note: Before clicking on Localize, make sure that we have already added the languages for localization. This is the step where we configure the languages for internationalization (Steps: project->Info->Localizations, then click '+', add the desired languages for internationalization/localization).
After clicking on Localize, a dialog will appear. Expand the dialog list, and you will find that the dropdown list shows the languages we configured for internationalization above. Choose the language we want to localize, then click the 'Localize' button in the dialog, as shown below:
Next, check French and English, as shown below:
Then open the ComPDFKit Flutter iOS Demo, find the
Localizable (English)
file, select all the text, copy it, and paste it into theLocalizable (English)
file you created.Finally, select the
Localizable (French)
file and configure the corresponding French translations according to theLocalizable (English)
file, ensuring that the number of text segments in both files is the same. For example, if theLocalizable (English)
file has"Viewer" = "Viewer";
, theLocalizable (French)
file should have the corresponding"Viewer" = "Téléspectatrice";
.