Package org.marketcetera.util.l10n

Message localization tools.

See: Description

Package org.marketcetera.util.l10n Description

Message localization tools.

Summary

Message localization (L10N) is the process by which message keys are mapped to message text, as outlined in the org.marketcetera.util.log package. The tools in this package assist in that effort.

MessageInfo and its subclasses I18NMessageInfo and PropertiesFileInfo represent meta-information derived from analyzing the representation of a single message in either a typical Message container class or inside a properties file.

ContainerClassInfo and PropertiesFileInfo perform the analysis and encapsulate all meta-information for a container class or properties file. They both implement the MessageInfoProvider interface, which defines a generic provider of a message meta-information collection.

MessageComparator compares any two collections of message meta-information. Part of the comparison result is expressed as a collection of MessageInfoPair instances, containing messages that have the same key in both source and destination, but differ in their parameter counts.

Additional tools can be built using the above classes as building blocks; such tools include translation tools (via automatic translation or a GUI-assisted manual process).

Use in unit tests

The message comparator lends itself to use within unit tests, to ensure each Message container class matches its associated fallback properties file. Here is the unit test template to accomplish this task:

package mypackage;

import org.junit.Test;
import org.marketcetera.util.l10n.MessageComparator;
import org.marketcetera.util.test.TestCaseBase;

import static org.junit.Assert.*;

public class MessagesTest
    extends TestCaseBase
{
    @Test
    public void messagesMatch()
        throws Exception
    {
        MessageComparator comparator=new MessageComparator(Messages.class);
        assertTrue(comparator.getDifferences(),comparator.isMatch());
    }
}
In order to ensure support for specific locales, it is also reasonable to add to the body of messagesMatch() the following lines (also remember to import java.util.Locale):
comparator=new MessageComparator(Messages.class,Locale.FRENCH);
assertTrue(comparator.getDifferences(),comparator.isMatch());

Copyright © 2015. All Rights Reserved.