Localize an App
Localize an App
You can localize the UI labels in an app in multiple languages of your choice.Appkit obtains the correct labels for a language by making calls to an Appkit translation service. The service provides a label in the chosen language, with a fallback to English if no translation exists for the label in the chosen language.
Loading translations
You can use the new<translations:localize> JSP tag to load a set of UI label translations into an app. The tag syntax is:-
dictionary. Name of the resource bundle from which to load translations. This is also the first part of the name of each property file that contains translations. Default:translations -
locale. Locale Default:en(English)
dictionary and locale are used to find the file as follows:- In
src/main/resources, the Appkit translation service looks for a resource bundle nameddictionary, for example,translations. - Within the resource bundle, the translation service looks for property files named
{resource}, for example, for the filestranslations_en.propertiesandtranslations_fr.properties.
Enabling translations
- Find label strings that need to be translated in the UI and identify the key names for the labels.
- Create translation property files and add them under the
src/main/resourcesdirectory. For example, for a dictionary calledtranslationsaddtranslations_en.propertiesandtranslations_fr.properties.
Edit the property files and include the label keys and translations. For example: Intranslations_en.properties:Intranslations_fr.properties:Some translations include variables. For example,components.response-statistics.showingisShowing {first} - {last} of {total}in English. Translations should retain the variables, though their order might differ. Labels can use<em>tags for emphasis, for example,More results like <em>{result}</em>. - Add the following dependency to your app’s
pom.xml: - Add this
taglibdirective at the top of your app’sindex.jsp: - Add the Appkit
<translations:localize>JSP tag inside the<head>element of your app’sindex.jsp: - Add this rule to the
url-rules.xmlfile:You can modify other URL rules to suit your application logic. The<translations:localize>JSP tag works the same. - Restart your app.
- Verify that the translations are present by visiting pages in the app that should be in different languages.
| Key | English Label | Additional Context |
|---|---|---|
components.search-box.placeholder | Search… | Search input placeholder |
components.search-box.button-label | Search | Search submit button label |
components.search-box.saved | My Saved Searches | |
components.search-box.bookmark | My bookmarks | |
components.spelling-suggestions.did-you-mean | Did you mean: {correction}. | As in, “Did you mean spelling-corrected query?” |
components.spelling-suggestions.auto-correct | Showing results for {correction}. | This is displayed above a list of results of a spelling-corrected query. |
components.spelling-suggestions.no-results | No results found for {query}. | |
components.response-statistics.showing | Showing {first} - {last} of {total} | |
components.pagination.next | Next | |
components.pagination.previous | Previous | |
components.breadcrumbs.clear-all | Clear All | |
components.facet.show-more | Show more | |
components.facet.show-less | Show less | |
components.no-results.title | Sorry: there are no results that match your search criteria. | |
components.no-results.subtitle | If you have checked your spelling: try using more general keywords. | |
components.response-statistics.showing-all | Showing All {total} | |
collaborate.bookmark.tooltip | Bookmark this? | As in, “Would you like to bookmark this item?” |
collaborate.bookmark.active | You have bookmarked this | As in, this is already bookmarked. |
collaborate.bookmark.single | {count} person has bookmarked this | As in the singular: “1 person has bookmarked this.” |
collaborate.bookmark.plural | {count} people have bookmarked this | As in the plural: “4 people have bookmarked this.” |
collaborate.bookmarkList.empty-text | You do not have any bookmarks yet | |
collaborate.comment.prompt | Please enter a comment | As in a prompt to add a comment. |
collaborate.comment.post | Post | The comment submit button |
collaborate.comment.placeholder | Leave a new note… | The text area placeholder |
collaborate.comment.delete | Delete | The delete comment button |
collaborate.comment.more | Show more comments | |
collaborate.comment.less | Show fewer | As in, show fewer comments. |
collaborate.comment.delete-message | Are you sure you want to remove this comment? | |
collaborate.like.tooltip | Do you like this? | As in, “Do you like this item/result?” |
collaborate.like.active | You have liked this | |
collaborate.like.singular | {count} person has liked this | As in the singular: “1 person has liked this.” |
collaborate.like.plural | {count} people have liked this | As in the plural “2 people have liked this.” |
collaborate.saved.button | Save | The save query button label |
collaborate.saved.empty-text | You do not have any saved queries yet | |
collaborate.saved.error | Please enter a name so this query can be saved | Error message indicating a name is required |
collaborate.saved.error-duplicate | A saved query with that name already exists, please use a different name | Error message flagging duplicate name |
collaborate.saved.error-network | Unable to save query, please try again | General error message |
collaborate.saved.placeholder | Search name | Guidance phrase in search box about searching names of saved searches |
collaborate.topic.button | Save | The save topic button label |
collaborate.topic.prompt | Please enter a topic name | |
collaborate.topic.name | Type a name for the new topic… | The text input placeholder |
collaborate.topic.description | Description… | Input placeholder for the topic description text |
collaborate.topic.empty | You do not have any topics yet | |
components.breadcrumbs.exclude | not {breadcrumb} | Showing the results that do not include items of this breadcrumb type |
components.facet.apply-filters | Apply Filters | |
components.facet.no-results | No results found | |
components.facet.search | Search… | |
content.form.success | Form posted successfully | |
content.form.error | Error!{status}-{statusText} | |
content.form.required | This field is required | |
content.form.submit | Submit | |
content.form.required-textarea | This field is required |