Java i18n (Internationalization) Guide: How to Add Different Language Support?
🧠 What Will You Learn in This Guide?
In this guide, you will learn how to make your Java applications multilingual by adapting them to different languages and regions (Locale).
With the classes ResourceBundle and Locale you will see step by step how to manage text, currency and date formats according to regional settings.
You will also learn how to name properties, how to load different Locales, and how the i18n structure can be used in web applications.
🌐 Java i18n and Locale Concept
Internationalization (i18n) is the process of making an application suitable for different languages and regions.
Java provides this support through the ResourceBundle class.
Special properties are created for each region and these files are automatically loaded according to the Locale information.
🧩 Property File Naming Convention
Filenames follow this pattern:
<dosyaAdı><dilKodu><ülkeKodu>.properties
| Örnek Dosya Adı | Açıklama |
|:-----------------|:----------|
| `ApplicationMessages.properties` | Varsayılan dil dosyası (Locale belirtilmezse bu yüklenir) |
| `ApplicationMessages_fr_FR.properties` | Fransızca (Fransa) |
| `ApplicationMessages_tr_TR.properties` | Türkçe (Türkiye) |
🛠️ Step 1: Create Different Locale Files
🇺🇸 Default (U.S.)
# ApplicationMessages.properties
UlkeAdi=Amerika Birleşik Devletleri
ParaBirimiKodu=USD
🇫🇷 Fransızca (Fransa)
# ApplicationMessages_fr_FR.properties
UlkeAdi=France
ParaBirimiKodu=Euro
🇸🇪 İsveççe (İsveç)
# ApplicationMessages_sv_SE.properties
UlkeAdi=Sverige
ParaBirimiKodu=Kr
💬 Note: All files must be located in the same directory within the project classpath.
💻 Step 2: Uploading Messages with ResourceBundle
The example below loads property files for three different Locales and writes messages to the screen.
import java.util.Locale;
import java.util.ResourceBundle;
public class GenixNodeI18nOrnek {
public static void main(String[] args) {
// 1️⃣ Varsayılan Locale
ResourceBundle paketVarsayilan = ResourceBundle.getBundle("ApplicationMessages");
// 2️⃣ Ön tanımlı Locale (Fransa)
ResourceBundle paketFR = ResourceBundle.getBundle("ApplicationMessages", Locale.FRANCE);
// 3️⃣ Manuel Locale oluşturma (İsveççe)
ResourceBundle paketSWE = ResourceBundle.getBundle("ApplicationMessages", new Locale("sv", "SE"));
mesajlariYazdir(paketVarsayilan);
mesajlariYazdir(paketFR);
mesajlariYazdir(paketSWE);
}
private static void mesajlariYazdir(ResourceBundle bundle) {
System.out.println(bundle.getString("UlkeAdi"));
System.out.println(bundle.getString("ParaBirimiKodu"));
}
}
💬 Description: ResourceBundle loads the appropriate file based on the given Locale information and returns texts corresponding to the keys.
🧾 Sample Output
Amerika Birleşik Devletleri
USD
France
Euro
Sverige
Kr
💬 Comment: If the file for the requested Locale is not found, Java automatically loads the default file (ApplicationMessages.properties).
⚙️ Step 3: Using the Locale Class
The Locale class represents information about a specific language and country. Some Locales are predefined in Java (Locale.FRANCE, Locale.US), but you can also create custom Locales.
Locale turkce = new Locale("tr", "TR");
ResourceBundle bundleTR = ResourceBundle.getBundle("ApplicationMessages", turkce);```
💬 Açıklama: Bu kod, ApplicationMessages_tr_TR.properties dosyasını yükler.
🔄 Adım 4: Web Uygulamalarında Dinamik Locale
Kullanıcının tarayıcı dili veya tercihine göre otomatik Locale seçimi yapılabilir.
Locale userLocale = request.getLocale();
ResourceBundle bundle = ResourceBundle.getBundle("ApplicationMessages", userLocale);
💬 Description: This method provides dynamic texts in web applications by detecting the user's browser language.
📚 Frequently Asked Questions (FAQ)
- What is Locale and how is it created?
Locale is a Java object that represents a language and country. It is created as new Locale("tr", "TR") or with the constant Locale.TURKEY.
- How does ResourceBundle choose the right file?
Java first looks for the exact matching file (fr_FR), if not, it loads the language code (fr), and if not, it loads the default file.
- Does i18n also affect dates and currencies?
Yes. DateFormat and NumberFormat classes automatically adjust the formatting by taking the Locale parameter.
- What does the abbreviation “i18n” mean?
The word "Internationalization" is abbreviated this way because there are 18 letters between "i" and "n".
- How to provide UTF-8 support?
In Java 9 and later, .properties files support UTF-8 by default. In older versions, the native2ascii tool can be used.
🧩 Result
Java i18n makes your applications ready for global users. Thanks to the ResourceBundle and Locale classes, you can create multilingual support by simply adding a few files.
🌍 Bring multilingual experience to your applications — Expand into the global market by testing your Java projects on GenixNode!

