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 and how to set up PTC.

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 set up a project in PTC. After that, PTC translates your .properties file in minutes.

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 Choose How to Use PTC

Once your .properties file is ready, sign up for a free 30-day trial of PTC.

You can start translating your project in one of three ways:

  • Git integration
    Connect your GitHub, GitLab, or Bitbucket repository. PTC automatically detects .properties files, translates them, and sends updates via merge requests when the source file changes.
  • Manual upload
    Upload your .properties file to try out PTC’s translations. You’ll get the translated files in a ZIP archive, ready to use.
  • API
    Send your file directly to PTC via API and receive translated versions in the response.

Step 6: 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 7: Check the Translated Files

PTC delivers translations based on the method you chose:

  • Git integration: A merge request appears in your repo.
  • Manual file upload: You’ll download a ZIP with the translated .properties files.
  • API: You get the translated content in the response.

Check that:

  • Files follow your naming conventions (messages_es.properties, etc.)
  • Placeholder syntax (like {0}) is preserved
  • All expected languages are included

Example translation ( French)

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

If something looks wrong, go to Settings → Monitored Files in your PTC dashboard to adjust file paths and output formats.

Step 8: Load the Translations at Runtime

Once translated files are merged or added to your project, Java automatically selects the correct 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

Keep Your Translations Updated Automatically

For automatic translation updates, use Git integration. When your .properties file changes:

  • PTC detects updated or new strings
  • PTC translates the changes automatically
  • You receive a new merge request with the updated translations

Start translating your Java app

Get fast, accurate translations for your Java .properties files. PTC helps you ship localized versions faster, without spending time editing translations.

Scroll to Top