LRP-614 practice question 1 of 25

The best way to add a new language key to the portal is through:

Full set: 144 questions
Answer options
A: The Control Panel
B: A hook plugin Correct answer
C: An Ext plugin
D: Modifying Liferay's source
Correct Answer:
B. A hook plugin
Explanation

A hook plugin is the officially recommended and best method for adding new language keys or overriding existing ones in the Liferay portal. This approach is modular, hot-deployable, and upgrade-friendly, as it does not modify Liferay's core source code. When a hook containing custom Language.properties files is deployed, Liferay's ResourceBundleLoader aggregates these new keys with the existing portal keys, making them available globally. This maintains a clean separation between customizations and the core product, which is a fundamental principle of Liferay development.

Why Incorrect

A. The Control Panel allows for overriding existing language key values at runtime, but it does not provide a mechanism for adding entirely new keys to the portal's resource bundle.
C. An Ext plugin can achieve this, but it is a much more invasive and heavyweight solution. It is not the "best" way, as hooks were specifically designed for this type of customization.
D. Modifying Liferay's source code directly is the worst practice. It makes applying patches and performing upgrades extremely difficult and is strongly discouraged by Liferay.

References

1. Liferay Portal 6.2 Developer's Guide, Chapter 5: Customizing Liferay Portal with Hooks, Section: "Customizing Language Keys".

Quote/Paraphrase: The guide explicitly states, "You can use a hook to customize the language keys used in Liferay Portal. You can override Liferay’s default language keys or add your own custom language keys." This section details the process of creating a Language.properties file within a hook to achieve this, confirming it as the standard procedure.

2. Liferay Portal 6.2 Developer's Guide, Chapter 6: Extending Liferay Portal with Ext Plugins, Section: "Deciding Whether to Use a Hook or an Ext Plugin".

Quote/Paraphrase: This section advises developers to "always favor using a hook over using an Ext plugin" for customizations that a hook can handle. It specifically lists "overriding or adding language keys" as a primary use case for hooks, reinforcing that an Ext plugin is not the best choice for this task.

Scroll to Top