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 334845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:05:35+00:00 2026-05-12T10:05:35+00:00

We have a Java project which contains a large number of English-language strings for

  • 0

We have a Java project which contains a large number of English-language strings for user prompts, error messages and so forth. We want to extract all the translatable strings into a properties file so that they can be translated later.

For example, we would want to replace:

Foo.java

String msg = "Hello, " + name + "! Today is " + dayOfWeek;

with:

Foo.java

String msg = Language.getString("foo.hello", name, dayOfWeek);

language.properties

foo.hello = Hello, {0}! Today is {1}

I understand that doing in this in a completely automated way is pretty much impossible, as not every string should be translated. However, we were wondering if there was a semi-automated way which removes some of the laboriousness.

  • 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-05-12T10:05:35+00:00Added an answer on May 12, 2026 at 10:05 am

    What you want is a tool that replaces every expression involving string concatenations with a library call, with the obvious special case of expressions involving just a single literal string.

    A program transformation system in which you can express your desired patterns can do this.
    Such a system accepts rules in the form of:

             lhs_pattern -> rhs_pattern  if condition ;
    

    where patterns are code fragments with syntax-category constraints on the pattern variables. This causes the tool to look for syntax matching the lhs_pattern, and if found, replace by the rhs_pattern, where the pattern matching is over langauge structures rather than text. So it works regardless of code formatting, indentation, comments, etc.

    Sketching a few rules (and oversimplifying to keep this short)
    following the style of your example:

      domain Java;
    
      nationalize_literal(s1:literal_string):
        " \s1 " -> "Language.getString1(\s1 )";
    
      nationalize_single_concatenation(s1:literal_string,s2:term):
        " \s1 + \s2 " -> "Language.getString1(\s1) + \s2"; 
    
      nationalize_double_concatenation(s1:literal_string,s2:term,s3:literal_string): 
          " \s1 + \s2 + \s3 " -> 
          "Language.getString3(\generate_template1\(\s1 + "{1}" +\s3\, s2);"
       if IsNotLiteral(s2);
    

    The patterns are themselves enclosed in “…”; these aren’t Java string literals, but rather a way of saying to the multi-computer-lingual pattern matching engine
    that the suff inside the “…” is (domain) Java code. Meta-stuff are marked with \,
    e.g., metavariables \s1, \s2, \s3 and the embedded pattern call \generate with ( and ) to denote its meta-parameter list :-}

    Note the use of the syntax category constraints on the metavariables s1 and s3 to ensure matching only of string literals. What the meta variables match on the left hand side pattern, is substituted on the right hand side.

    The sub-pattern generate_template is a procedure that at transformation time (e.g., when the rule fires) evaluates its known-to-be-constant first argument into the template string you suggested and inserts into your library, and returns a library string index.
    Note that the 1st argument to generate pattern is this example is composed entirely of literal strings concatenated.

    Obviously, somebody will have to hand-process the templated strings that end up in the library to produce the foreign language equivalents.
    You’re right in that this may over templatize the code because some strings shouldn’t be placed in the nationalized string library. To the extent that you can write programmatic checks for those cases, they can be included as conditions in the rules to prevent them from triggering. (With a little bit of effort, you could place the untransformed text into a comment, making individual transformations easier to undo later).

    Realistically, I’d guess you have to code ~~100 rules like this to cover the combinatorics and special cases of interests. The payoff is that the your code gets automatically enhanced. If done right, you could apply this transformation to your code repeatedly as your code goes through multiple releases; it would leave previously nationalized expressions alone and just revise the new ones inserted by the happy-go-lucky programmers.

    A system which can do this is the DMS Software Reengineering Toolkit. DMS can parse/pattern match/transform/prettyprint many langauges, include Java and C#.

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

Sidebar

Related Questions

On my java project, I have a bunch of strings externalized on a messages.properties
I have to give a general note to some huge Java project for which
I have been working on a Java project for a class for a while
I have a project written in Java (>1.5). Is it possible to write parts
I have a side project I do = in Java. It's a pretty straight-forward
In a software-project written in java you often have resources, that are part of
I have a maven project with the following packages (for illustration only): Root: src/main/java
Java Newbie here. I have a JFrame that I added to my netbeans project,
I have a large Java app that is split up into multiple projects. Each
I have a login.jsp page which contains a login form. Once logged in 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.