How to Translate Java Properties Files with PTC

PTC delivers Better Than Human AI translations for .properties files, which are often used to localize Java desktop applications and web apps. Learn how to prepare .properties files for translation, integrate your Git repository with PTC, and translate your software.

Translating Your Application for the First Time with PTC

Your first setup takes a few steps. You’ll move all translatable text into a .properties file, handle dynamic content with placeholders, and connect your code repository to PTC. After that, PTC translates your .properties file and manages translation updates whenever your text changes.

Step 1: Create a .properties File to Store All User-Facing Text

Create a new .properties file to store every user-facing string in your app, such as button labels, error messages, form instructions, tooltips, and more. Place the file in src/main/resources.

You can name the file however you like (messages.properties, labels.properties, etc.), but make sure it matches the name you use later in ResourceBundle.getBundle().

Example of a well-structured .properties file:

# Navigation
navigation.home=Home
navigation.about=About Us

# Buttons
button.submit=Submit
button.cancel=Cancel

# Errors
error.unauthorized=You are not authorized to access this page.
error.timeout=Your session has expired. Please log in again.

# Dynamic message
greeting=Hello, {0}! You have {1} new messages.

 Incorrect – Keys are cryptic or inconsistent:

a1=Home
btn=Submit
msg1=Unauthorized

Using clear, descriptive keys instead of short or cryptic ones like btn1 or msg2 makes the file easier to maintain—especially if multiple developers work on the project.

Step 2: Add Placeholders for Dynamic Text

When a string includes variable content (like names, numbers, or dates), add numbered placeholders like {0}, {1}.

Correct – Use a full string with placeholders

.properties:

greeting=Hello, {0}! You have {1} new messages.

In your Java code, use MessageFormat to insert dynamic content at runtime:

String user = "Maria";
int count = 3;

String message = MessageFormat.format(
    bundle.getString("greeting"), user, count);

System.out.println(message);
// Output: Hello, Maria! You have 3 new messages.

Incorrect – Sentence split or concatenated in code:

System.out.println("Hello, " + user + "! You have " + count + " new messages.");

This approach breaks grammar and word order in many languages. As a result, translations may be incorrect or sound unnatural.

Step 3: Replace Hardcoded Strings with Keys from the File

Once you’ve created your .properties file and added any necessary placeholders, go through your code and replace hardcoded strings with references to the file using ResourceBundle.

Correct – Load and use localized strings:

properties

ResourceBundle bundle = ResourceBundle.getBundle("messages", Locale.getDefault());

button.setText(bundle.getString("button.submit"));
System.out.println(bundle.getString("nav.home"));

 Incorrect – Hardcoded strings that can’t be translated:

button.setText("Submit");
System.out.println("Home");

PTC only translates strings stored in your .properties files. Hardcoded strings will stay in the source language.

Step 4: Save the File in UTF-8 Format

Make sure to save your .properties file in UTF-8. This allows accented characters and non-Latin scripts to display correctly. Most modern IDEs use UTF-8 by default, but double-check your editor settings to avoid encoding issues.

Step 5: Create a Free PTC Account and Connect Your Repository

To start translating with PTC:

  1. Create a free 30-day account
  2. Connect your GitHub, GitLab, or Bitbucket repository

PTC needs read/write access so it can detect .properties files, translate them automatically, and push translated files back via merge requests.

Step 6: Confirm Output File Paths

PTC will list each .properties file it detects and suggest output file paths for translations — for example, messages_fr.properties for French.

You can:

  • Accept the default output path, or
  • Update it to match your project structure

Step 7: Choose Target Languages and Describe Your App

PTC uses project context to improve translation accuracy. Before translating, you’ll be asked to:

  • Provide the name of your application
  • Explain what it does
  • Describe your audience

Then choose the languages you want to translate into. PTC supports 33+ languages.

Step 8: Check the Output Files and Accept the Merge Request

Once PTC finishes translating your .properties files, it creates a merge request in your repository.

Before merging, make sure:

  • Translated files are saved with the correct name (e.g., messages_fr.properties for French)
  • File paths match your project’s structure

Example translation ( French)

nav.home=Accueil
nav.about=À propos de nous
button.submit=Envoyer
greeting=Bonjour, {0}! Vous avez {1} nouveaux messages.

If you see a missing file or an unexpected folder path, go to Settings → Monitored Files in your PTC project and update the resource file settings.

Step 9: Load the Translations at Runtime

At runtime, Java automatically loads the correct .properties file based on the user’s locale.

Example

Locale locale = new Locale("fr"); // French
ResourceBundle bundle = ResourceBundle.getBundle("messages", locale);

String label = bundle.getString("button.submit");
System.out.println(label); // Output: Envoyer

In this example, Java will use messages_fr.properties for French, falling back to messages.properties if no translation is available.

Bonus Step: Translate Text Not Stored in .properties Files

If your application includes translatable content not stored in a resource file—such as emails, onboarding messages, or app store listings—you can translate it using the Paste to translate feature in PTC.

  1. From your PTC dashboard, go to Translations → Paste to translate
  2. Paste your content and choose your languages  
  3. Copy the translations and add them into your app or docs

How PTC Keeps Your Translations Up to Date

After setup, PTC continues to monitor your repository. Whenever you update a .properties file, PTC:

  • Detects new or modified strings
  • Translates the changes automatically
  • Sends a new merge request with the updated translations

Start translating your Java app

Get fast, accurate translations for your Java .properties files. PTC keeps everything up to date and integrated with your development workflow.

Scroll to Top