If you want to translate/localize/internationalize Find into another language, this article is for you!
How language bundles in Find work
Find uses Require.js for loading JavaScript modules. Require has a i18n
(short for “internationalization”) module for translating web applications. The documentation is here.
When a user navigates to the Find web application, the Find code “requires” the internationization bundle. Internally, the i18n
plugin reads the browser’s locale and checks to see if there is a translation for that language - if there isn’t, the default language bundle is used.
Adding a new language bundle
Let’s translate Find into French.
- Navigate to the Find i18n bundles directory: find-core/src/main/public/static/js/find/nls
- Open
bundle.js
- this is the master list of all translations -root
is the default language, and anen-gb
dummy translation has been provided as an example. - Add a new key-value pair to
bundle.js
. The key should be the RFC 1766 language tag (e.g.fr-ca
for French (Canadian),nv
for Navajo, etc). The value should betrue
, to enable the new translation. - Add the same key-value pair to
errors.js
andindexes.js
. - Copy the
root
directory and give you copy the same name as the language tag you have added to the JavaScript files, e.g.fr-ca
. - Open and edit all of the JavaScript files in your new folder. Replace the values of each key-value pair with your translations. Make sure that you match up all
"
and'
characters - using a tool like JSLint to check your syntax would be a good idea here (expect it to produce warnings, but keep an eye out forUnclosed string.
messages) - Build and deploy Find. Your translation is now available!
Replacing the default language bundle
The root
language bundle is used as a default. Changing the language of the default is as simple as editing the root bundle.
- Follow the steps for “Adding a new language bundle”, to add a new
en-us
language bundle, using the existingroot
bundle. - Instead of editing your new language bundle, edit the JavaScript files in the
root
directory.