In JavaServer Faces, now Jakarta Faces, a ResourceBundle holds the translatable text of your pages: labels, button captions and messages stored as key-value pairs in .properties files, one file per language. Faces picks the right file for the user's locale and lets views read values through the expression language, so you can support several languages without touching page markup or Java code.
The same mechanism also stores validation and conversion messages, which makes it the standard foundation for internationalisation (i18n) in a Faces application.
A java.util.ResourceBundle loads a family of files by base name plus a locale suffix. For the base name messages:
messages_en.properties:
messages_fr.properties:
Java 9 and later read properties-based bundles as UTF-8, so you can write accented and non-Latin characters directly. Older Java versions needed \uXXXX escapes. Keep the default file complete, because Java falls back to it for missing keys.
Declare the bundle and the supported locales once, and Faces exposes it under a variable name.
Here i18n.messages is the path on the classpath, such as src/main/resources/i18n/messages_fr.properties. Faces 4.0 uses the Jakarta namespace and the jakarta.faces package; older JSF 2.x applications use javax.faces and a different schema, but the resource-bundle element is the same.
With the bundle registered, reference keys through the msg variable:
The bracket form msg['welcome.title'] is needed for keys containing dots, and h:outputFormat with f:param fills the {0} placeholders using MessageFormat.
If you only need a bundle on one page, <f:loadBundle basename="i18n.messages" var="msg"/> loads it in the view. The configuration-file approach is preferred because it is shared and cached.
Faces determines the locale from the browser's Accept-Language header, limited to the supported locales. To let the user choose, keep the locale in a session-scoped bean:
Then apply it on the view and bind links or a menu to setLanguage:
For text built in a backing bean, such as a message after a save, read the same bundle:
The second argument is the var name from faces-config.xml. This keeps all user-facing text in the bundle.
Faces has its own message keys, such as jakarta.faces.component.UIInput.REQUIRED. Point a second bundle at your file with <message-bundle> in faces-config.xml and override them:
Per-component overrides use attributes such as requiredMessage="#{msg['field.required']}".
The key is missing in the resolved bundle, or the expression name does not match the var. Check spelling, the base name path and that the file is on the classpath.
By default it uses the browser's accepted languages, matched against the declared supported locales, and falls back to the default locale. You can override it with f:view locale or UIViewRoot.setLocale.
Prefer resource-bundle in faces-config.xml. It is defined once for the whole application, and the bundle is also available to Java code through the Application object.
Yes, as UTF-8 on Java 9 and later. On Java 8 and earlier, escape them with \uXXXX or use a build step.
A ResourceBundle separates text from markup so a Faces application can speak many languages. Store keys in per-locale properties files, register the bundle and supported locales in faces-config.xml, read values with #{msg['key']}, and let users change the locale through a session bean and f:view. Use the bundle from Java code and for validation messages too, so every visible string is translatable.