Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7815399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:30:40+00:00 2026-06-02T05:30:40+00:00

I’m currently working on a bigger Java desktop-application and now are at the point

  • 0

I’m currently working on a bigger Java desktop-application and now are at the point where I want to add translations. What bothers me about the l18n-system is, that it doesn’t provide any kind of compiletime checking.

In java’s system, you have something like a HashMap, where every localized string has a “Key” and the translated string then is the “Value”. This looks something like this (taken from the tutorials example):

Locale currentLocale;
ResourceBundle messages;

currentLocale = new Locale(language, country);

messages = ResourceBundle.getBundle("MessagesBundle", currentLocale);
System.out.println(messages.getString("greetings"));

This works nice if you have a simple/small application. But in a big application with thousands of translated strings, it might so happen that you have a typo in the “Key” and therefore get an empty or wrong string.

With a little luck, the application throws a RuntimeException to tell you about it, but even then it is possible that you don’t even come to this point because the wrong “Key” is used in a dialog that might not show up under certain circumstances (say it’s an error dialog).

To prevent this from happening, using a system which offers compiletime checking of the used “Keys” would be the better idea. This is for example used in Android, where you specify the Resources in an XML-file which is then indexed and mapped to a class (including the “Keys” to use). This way, you get something like this (from the Android Docs):

// Set the text on a TextView object using a resource ID
TextView msgTextView = (TextView) findViewById(R.id.msg);
msgTextView.setText(R.string.hello_message);

If you have a typo in that “key”, you’ll get an error at compile-time (also you have “auto-completion” from your IDE).

Now, to make something like this work, you’ll need a little tool/script that does the indexing part and generates the Resource-class (R.java). In Android, the Eclipse-plugin (or your IDE in general) does that for you.

My question now is: Is there already a system that that I can use for normal desktop-applications in Java? Or am I horribly wrong with what I’m saying?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T05:30:41+00:00Added an answer on June 2, 2026 at 5:30 am

    There is a fairly simple solution to this problem. First, don’t use magic strings as codes, define constants and refer to them. So you change..

    messages.getString("greetings");
    

    to

    messages.getString(I18.GREETINGS_CODE);
    

    and have the corresponding class;

    public class I18 {
    
      public static final String GREETINGS_CODE = "greetings";
    
    }
    

    Next write a test case where each code in your I18 class is looked up in each language resource file. If any resource file is missing the code, then fail the test. Its not compile time, but your project will fail its test if you have any problems.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want use html5's new tag to play a wav file (currently only supported
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
i want to parse a xhtml file and display in UITableView. what is the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.