Skip to content

Localization

Alex Bruch edited this page Dec 5, 2024 · 6 revisions

Localization process

Entry class has StringProperty name for displayed name. We create Binding in a Constructor with help of L10N class;

L10N class

The L10N class is part of the services package (package org.example.globalgoodsindex.services). It provides methods for handling localization in the application, allowing it to adapt to different languages and regions. The class manages locale settings, loads appropriate resource bundles, and provides methods for fetching localized strings and creating bindings based on the current locale.

Methods

getLocale

Purpose:

Retrieves the current locale set for the application.

Description:

  • This method simply returns the current locale, which is wrapped in an ObjectProperty<Locale>.
  • The locale property can be updated dynamically, and this method reflects the current setting.

Error Handling:

  • None.

setLocale

Purpose:

Sets a new locale for the application.

Description:

  • This method updates the locale property and also changes the default locale of the Java system to the provided locale.
  • It allows the user to dynamically switch the language of the application at runtime.

Error Handling:

  • None.

get

Purpose:

Fetches a localized string for a given key and formats it with optional arguments.

Description:

  • The method retrieves the localized string associated with the provided key from multiple resource bundles: countries, products, and ui.

Error Handling:

  • If the key is not found in any of the resource bundles, the method returns null.

createStringBinding

Purpose:

Creates a StringBinding for a localized string based on the given message bundle key.

Description:

  • This method creates a JavaFX StringBinding which will automatically update whenever the locale changes.
  • The binding fetches the localized string using the get method.

Error Handling:

  • None.

getShortNameBinding

Purpose:

Creates a StringBinding for a product's short name.

Description:

  • This method takes a Product object and retrieves its short name by looking up a key in the resource bundles based on the product's database name.
  • It creates a StringBinding that will automatically update if the locale changes.

Error Handling:

  • None.

Purpose:

Creates a StringBinding for a product's short name.

Description:

  • This method takes a Product object and retrieves its short name by looking up a key in the resource bundles based on the product's database name.
  • It creates a StringBinding that will automatically update if the locale changes.

Error Handling:

  • None.

Clone this wiki locally