-
Notifications
You must be signed in to change notification settings - Fork 10
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.
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:
- 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.
- Launch inspection
List<C10NUnit> units = inspector.inspect("com.example.messages");
- 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)));
}
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 ofConfiguredC10NModule
class, that can be retrieved withC10N.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)
- whentrue
, inspection results will contain the actual translated values for each of the locale. Whenfalse
, translated values will benull
. -
dummyInstanceProvider(provider)
- A provider of dummy instances for parameterised methods, such asgreet(String name)
. Only enabled whenfetchTranslations(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.