Skip to content
rodionmoiseev edited this page Dec 31, 2012 · 1 revision

Inspection Tools

Since 1.1

Localisation process can be error prone, and tools for to help identify problems in the process are very important.

C10N offers an inspection tool, to help you automate various checks for compliance with your localisation process.

Usage Overview

Inspector is a simple tool that scans your source for all c10n-enabled interfaces and extracts all possible messages. For each message, inspector determines what locales are translated and how.

The basic inspector usage:

  1. Create an instance of the inspector
C10NInspector inspector = C10NTools.inspectorBuilder().build();

By default, inspector will use settings from the last c10n configuration used declared with C10N.configure(...) method.

  1. Launch inspection
List<C10NUnit> units = inspector.inspect("com.example.messages");
  1. Write custom checking logic. For instance, let's write a JUnit test to check all methods have at least declared annotation for Locale.ENGLISH.
List<C10NUnit> units = checker.inspect("com.example.messages");
for (C10NUnit unit : units) {
  C10NTranslations translations = unit.getTranslations().get(Locale.ENGLISH);
  assertNotNull("No translations for 'en' found", translations);
  assertThat("Annotation count for 'en'",
  translations.getAnnotations().size(), is(greaterThan(0)));
}

Further Configuration

Inspector instance builder provides you with following parameters:

C10NTools.inspectorBuilder()
  .module(myModule)
  .checkLocales(locales)
  .fetchTranslations(enableTranslations)
  .dummyInstanceProvider(provider)
  .build();

Where:

  • module(myModule) - takes the module configuration to use during checking. myModule is an instance of ConfiguredC10NModule class, that can be retrieved with C10N.configure(...) method.
  • checkLocales(locales) - inspection will be restricted only to the given locales. Other locale related translations will not be reflected in inspection results. By default, all locales mentioned in the configuration will be inspected for.
  • fetchTranslations(enableTranslations) - when true, inspection results will contain the actual translated values for each of the locale. When false, translated values will be null.
  • dummyInstanceProvider(provider) - A provider of dummy instances for parameterised methods, such as greet(String name). Only enabled when fetchTranslations(true).

In addition, you can restrict the scan to one or more packages by passing the list of packages to the inspect(...) method. Specified packages and their sub-packages will be scanned recursively.

inspector.inspect("com.example.package1", "com.example.package2");

Note: At least one package has to be specified.

Clone this wiki locally