Java properties

Last updated: September 09, 2024Author: Jakub Pomykała
java-properties
File format value
java-properties

One of the most common formats used for localization in all Java and JVM apps are property files as shown below. Every file contains translations for a different language translation. It's a common case where those files have naming convention like messages_{language}.properties. For example: messages_pl-PL.properties.

java i18n properties file structure

Such files are often used together with Thymeleaf template engine and for e-mail translations.

File format example

# common
email.user.hello=Hello, {0}
email.team=SimpleLocalize.com Team
email.broken.button.instruction=In case the button link doesn't work for you, please copy and paste the link in your browser
# user created
email.user.created.subject=Setup password for SimpleLocalize account
email.user.created.instruction.button=In order to set up a new password, click on the button below:
email.user.created.button.text=Setup password

Characters escaping

When exporting translations to Java properties file, SimpleLocalize will escape special characters like \t, \n, \r, \f, \, # and = by default. Those characters are also unescaped automatically when importing translations to SimpleLocalize.

Spring Boot and MessageSource

If you are using Spring Boot and MessageSource, you may want to escape single quotes ' in your messages. To do that, add ESCAPE_SINGLE_QUOTES as an export option in your CLI or API request. There is also option to unescape single quotes by replacing every two single-quotes to one single-quote when importing translations back to SimpleLocalize. To do that, add UNESCAPE_SINGLE_QUOTES as an import option.

Remember to set ResourceBundleMessageSource.setAlwaysUseMessageFormat to true in your bean configuration.

Upload with CLI

simplelocalize upload --apiKey <PROJECT_KEY> \
  --uploadFormat java-properties \
  --uploadPath ./messages_{lang}.properties

Learn more about SimpleLocalize CLI and translations upload feature.

Download with CLI

simplelocalize download --apiKey <PROJECT_KEY> \
  --downloadFormat java-properties \
  --downloadPath ./messages_{lang}.properties

Learn more about SimpleLocalize CLI and translations download feature.

Import with API

curl
    --request POST \
    --url 'https://api.simplelocalize.io/api/v2/import?uploadFormat=java-properties' \
    --header 'x-simplelocalize-token: <API_KEY>' \
    --form file=@/path/to/your/messages.properties

Learn more about importing translations with API

Export with API

curl
    --request GET \
    --url https://api.simplelocalize.io/api/v3/export?downloadFormat=java-properties \
    --header 'x-simplelocalize-token: <API_KEY>'

Learn more about exporting translations with API

Was this helpful?