Lingobit Extractor · Java

Extract hard-coded strings from Java code into .properties files.

A message written as "Order saved" in Java stays in English in every language. Lingobit Extractor moves it into a .properties file and puts a call that reads it from the resource bundle in its place, so it can be translated.

View pricing

JavaOrderView.javaExtractvoid onSave() { saveOrder(); status.setText("Order saved");getString("Order_saved"));}PROPERTIESMessages.propertiesOrder_saved=Order savedOrder savedOrder_saved JavaOrderView.javaExtractvoid onSave() { saveOrder(); status.setText( "Order saved");getString("Order_saved"));}PROPERTIESMessages.propertiesOrder_saved=Order savedOrder savedOrder_saved
Files
.java
Resources
.properties
In the code
getString, a wrapper class, or ResourceBundle
Trial
30 days, a separate download

What Extractor changes in your Java code.

One string, before and after. The key is made from the words of the text, joined with _.

Before: OrderView.java

void onSave() {
    saveOrder();
    status.setText("Order saved");
}

After: OrderView.java

void onSave() {
    saveOrder();
    status.setText(getString("Order_saved"));
}

New in the resources: Messages.properties

Order_saved=Order saved

From hard-coded text to resources in five steps.

Not every string is text: a class name, an SQL query, or a registry key stays in the code. You decide what moves, and Extractor remembers it.

Lingobit ExtractorScanScanStringSourceState"Order saved"OrderDlg.cpp:42NewExtract"%d"OrderDlg.cpp:57Newfiltered out: no letters"OrderWindow"OrderDlg.cpp:12NewSkip"SELECT * FROM Orders"OrderDb.cpp:30NewSkip"Print the order"OrderDlg.cpp:88NewExtract"Software\\MyApp"Settings.cpp:9NewSkip"Gift wrap"OrderDlg.cpp:95NewAt the next Scan, skipped strings stay skipped and extracted ones stay in the resources:only the new string is New. Lingobit ExtractorScanScanStringState"Order saved"NewExtract"%d"Newfiltered out: no letters"OrderWindow"NewSkip"SELECT * FROM Ord…"NewSkip"Print the order"NewExtract"Software\\MyApp"NewSkip"Gift wrap"NewAt the next Scan only the new stringis New; skipped ones stay skipped.
  1. Create a projectAdd your .java files or the source folder.

  2. Add a .properties fileUse an existing .properties file or create one; turn on the wrapper class if you want it.

  3. Scan, then Skip or ExtractSkip the technical strings, extract the text with the template you chose.

  4. SaveExtractor writes the changed sources, the .properties file, and the wrapper class.

  5. BuildBuild as usual. The bundle ships with your application.

The code that loads the string.

Each extracted string gets a replace template. Pick one per resource file or per string.

  • getString("$(ID)")
    Your own getString method loads the string. The recommended name.
  • $(WRAPPERCLASS).getString("$(ID)")
    A wrapper class that Extractor generates for the bundle, such as MessagesWrapper.
  • ResourceBundle.getBundle("$(RESNAME)").getString("$(ID)")
    Loads the bundle in place; needs no other change in the code.

With the first template, make your getString method visible in every file you change.

Then translate the build.

Lingobit Localizer translates the .properties files or the JAR and writes Messages_de.properties and the other languages; ResourceBundle picks the one for the user's locale.

Before translation, check the result with Pseudo Translate in Lingobit Localizer: if a text still stays in English, it is still in the code. Pseudo Translate: Professional and higher.

Pseudo TranslateRun Localized ApplicationNew OrderNew ÖrderNeCustomer:Cüßtömer:CüQuantity:Qüäntity:QüShip todayShip tödäyShiPrint receiptPrint receiptPriCreateCreäteCCancelCäncelCOrder savedÖrder ßävedÖrdFrom the resourcesWorks as the original Pseudo TranslateRun Localized ApplicationNew OrderNew ÖrderNeCustomer:Cüßtömer:CüQuantity:Qüäntity:QüShip todayShip tödäyShiPrint receiptPrint receiptPriCreateCreäteCCancelCäncelCOrder savedÖrder ßävedÖrdFrom the resourcesWorks

Java string extraction FAQ

Which template should I use?

getString("…") keeps the code short if you have your own loading method. The wrapper class needs no method of your own. ResourceBundle.getBundle(…) needs no other change in the code.

Can I add strings to an existing .properties file?

Yes. Add the file to the Extractor project, and the new keys are written to it.

Where do the translated files come from?

Lingobit Localizer translates the bundle and writes Messages_de.properties and the other languages, or translates them inside the JAR.

What happens to strings I skip?

They stay in the code and keep the Skip state. At the next Scan only new strings show up.

Try Extractor on your own Java code.

The trial runs for 30 days with every function. In each resource file the first 50 extracted strings are written as they are; after that, some may end in _TRIAL.

  • Lingobit ExtractorAll languages, how to work with Extractor, and the check after extraction.
  • C and C++Hard-coded strings in C and C++ code into an .rc string table.
  • C#Hard-coded strings in C# code into .resx resources.
  • Visual Basic .NETHard-coded strings in Visual Basic .NET code into .resx resources.
  • DelphiHard-coded strings in Delphi code into a resourcestring unit.