Java Properties is a simple text-based file format that is used to store key-value pairs of translations. Learn how to use Java Properties with SimpleLocalize
Java Properties files are simple text files that contain key-value pairs of translations, metadata or configurations. Each line in a Java Properties file represents a single key-value pair, with the key and value separated by an equals sign ( =
). The key is typically a short, descriptive string that identifies the translation, while the value is the translated text. Comments can be added to the file using the hash symbol ( #
). Interpolation is supported by using the {0}
syntax to insert dynamic values into the translation. Alternatively, you can use {name}
syntax to insert named parameters.
# Polish
user.hello=Witaj, {0}
login.title=Zaloguj się
login.email=Adres e-mail
login.password=Hasło
In most cases, one file contains translations for a single language. For example, you can have a file with translations for English (messages_en.properties) and another file with translations for Polish (messages_pl.properties).
# English
user.hello=Hello, {0}
login.title=Log in
login.email=Email address
login.password=Password
Java Properties files are typically named using the .properties extension. For example, messages.properties or labels.properties. The name of the file should reflect the purpose of the translations it contains. Since Java properties in most cases contain translations for a specific language, it is a good practice to include the language code in the file name. For example, messages_en.properties
or labels_pl.properties
.
Property files can be very large, especially in enterprise applications with many modules and components. Splitting translations into multiple files is rarely needed, since *.properties files loaded on application startup are merged into a single ResourceBundle. Unlike frontend applications, where splitting translations into multiple files by namespace or component is a common practice.
Java Properties is a simple and lightweight file format that is easy to work with and understand. It is widely used in JVM based applications (mainly Java, Kotlin, Scala) for storing translations, configuration settings, and other key-value pairs. Thanks to built-in support in Java standard library, it is easy to read and write *.properties files in your application code. For example:
Properties messages = new Properties();
messages.load(new FileInputStream("messages_en.properties"));
Historically, Java Properties files used the ISO-8859-1 encoding, which supports only a limited set of characters. However, with the introduction of Java 9 in 2017, the default encoding for properties files was changed to UTF-8, which supports a wider range of characters and is more suitable for internationalization. When working with Java Properties files, it is recommended to use the UTF-8 encoding to ensure that your translations are correctly displayed in all languages. SimpleLocalize encodes all Java Properties files in UTF-8 by default.
Due to this changes in Java 9, it is recommended to set the encoding explicitly in your application. For example to set UTF-8 encoding in Spring Boot application, you can use the following configuration:
# application.yml
spring:
config:
encoding: UTF-8
Lesser known fact is that *.properties files can also be represented as XML and still be used in Java applications via natively available Properties class. This format is useful when you need to store additional metadata along with the key-value pairs. The XML representation of Java Properties files uses the <properties>
element to enclose the key-value pairs, and the<entry>
element to represent each key-value pair.
<?xml version="1.0" encoding="utf-8" ?>
<properties>
<comment>My comment</comment>
<entry key="hello-world">Witaj Świecie</entry>
<entry key="sign-in">Zaloguj się</entry>
<entry key="sign-up">Zarejestruj się</entry>
</properties>
Property files are commonly used in Java applications to store translations, configuration settings, and other key-value pairs. They are often used for localization, allowing developers to provide translations for different languages without modifying the source code. Files with *.properties extension are used by all JVM based languages like Scala, Groovy, Kotlin. Many frameworks for app development like Spring, Play, Micronaut, Quarkus, etc. use Java Properties for configuration and translations.
Property files are popular choice for translations, and configurations in Java projects thanks to native support in Java standard library and their simplicity and ease of use. If you are looking for alternatives to Java Properties, you may consider using JSON (single language), YAML, Excel, CSV or other file formats that are commonly used for storing translations and configuration settings.
Managing translations in Java Properties files can be challenging, especially as your project grows and you need to support more and more languages. Updating every property file manually can be time-consuming and error-prone, leading to inconsistencies and missing translations.
SimpleLocalize makes it easy to manage translations in Java properties by providing a centralized platform for storing and updating your translations. You can upload your Java Properties files to our translation editor and manage your translations in one place. With our powerful features like auto-translation, AI actions, bulk actions, and CLI integration, you can keep your translations up-to-date and ensure that your application is localized for all your users.
Your partner in managing translations and localization workflow.
Web-based translation editor helps Java developers keep their *.properties files in sync.
Translate your application into multiple languages with just a few clicks. Choose from OpenAI ChatGPT, Google Translate or DeepL translation providers to translate your texts. Adding support for new languages has never been easier.
Learn more about auto-translationWith SimpleLocalize CLI you can manage your translations from the terminal. It's a powerful tool that helps you to automate the translation process in your project. You can easily synchronize translation files between you local project and SimpleLocalize Translation Editor, start auto-translation or publish changes to the production environment.
CLI documentation# upload strings
$ simplelocalize upload
# auto-translate strings
$ simplelocalize auto-translate
# download all translations
$ simplelocalize download
Boost collaboration with public suggestions! Public translations offer an excellent opportunity to engage your community by allowing them to contribute to translations. Enable public suggestions, share your project link, and invite users to suggest translations or improvements.
Learn more about public suggestionsGreet your customers
in their native language
Stay up to date with the latest news
Learn about Java 21 internationalization and localization. We will learn how to use formatting instances to format dates and numbers. We will take a look at the `java.text` package and its classes. We will also learn how to use the `java.time` package to work with dates and times. Finally, we will learn how to use the `ResourceBundle` object to retrieve localized messages from a properties file.
Learn how to implement internationalization in your Spring Boot application. This tutorial will show you how to use Spring Boot to create a simple application with messages.properties.
The new SimpleLocalize VS Code extension lets you manage translations directly in the editor. Explore key features and installation instructions.
Quick message extraction with using npx and OpenAI. Extract messages and auto-create translation keys using AI. Get source translations in seconds from your source code.