Adding additional languages to JPedal Viewer
The Viewers text content is handled and controlled by a resource bundle. This bundle contains files that are used to populate the text in the JPedal Viewer. JPedal currently has built in support for English, French, German, Japanese, and Chinese. You can also provide you own resource bundle to add support for additional languages.
How to add your own resource bundle
To add support for another language you will need to do two things.
- Create a resource bundle in a directory in your jar.
- Set the org.jpedal.customBundle flag with the name for this directory.
Below we will cover both of these steps in detail.
Creating a resource bundle in a directory in your jar
When creating the resource bundle you will need to create a directory to store all languages you wish to support and then create a file for each language.
First you must create a directory for the resource bundle. This should be a resource directory within your jar that is not used for anything else, just language files.
For example, create a directory called org.jpedal.languages.custom within your projects jar.
Next you need to create a file for each language you wish to support. Within this file will be a list of keys and values, the values are the text as it will appear in the Viewer. An english example can be found here. You can use this as a template yo create you own language files.
Once a file is complete it can be added to your resource directory but the filename must match a given pattern. [BUNDLE_NAME]_[LANG].properties where BUNDLE_NAME is a prefix for all language files and LANG is the ISO 639 Set 1 language code. For example, using messages as the BUNDLE_NAME, the english file name would be messages_en.properties
Finally, if you wish to ignore the default languages supported by JPedal and only use your custom bundle you can provide your own default fallback language file. After creating a file for the default fallback language, if you save it without any language code (for example, messages.properties) this language will be used in the systems language is not found in the bundle. If this default fallback file is not present then JPedal will check the default resource bundle if the custom bundle does not support the language.
Using your new resource bundle
Once you have created your resource bundle you just need to provide 1 JVM flag to allow JPedal to use your bundle.
org.jpedal.customBundle=[BUNDLE_DIRECTORY].[BUNDLE_NAME]
So if you used the examples above (BUNDLE_DIRECTORY of org.jpedal.languages.custom and BUNDLE_NAME of messages) the value would be org.jpedal.languages.custom.messages