Errai 3.0.1-SNAPSHOT

org.jboss.errai.ui.rebind
Class TranslationServiceGenerator

java.lang.Object
  extended by com.google.gwt.core.ext.Generator
      extended by org.jboss.errai.config.rebind.AbstractAsyncGenerator
          extended by org.jboss.errai.ui.rebind.TranslationServiceGenerator
All Implemented Interfaces:
AsyncCodeGenerator

public class TranslationServiceGenerator
extends AbstractAsyncGenerator

Generates a concrete subclass of TranslationService. This class is responsible for scanning the classpath for all bundles, and then making them available during template translation. The TranslationService can also be used directly in the Errai application by injecting it. This allows translated strings to be used from Errai Java code, not just from templates.

Author:
eric.wittmann@redhat.com

Constructor Summary
TranslationServiceGenerator()
           
 
Method Summary
 String generate(com.google.gwt.core.ext.TreeLogger logger, com.google.gwt.core.ext.GeneratorContext context)
          Called by AbstractAsyncGenerator.generateAsync(TreeLogger, GeneratorContext) to carry out the actual code generation.
 String generate(com.google.gwt.core.ext.TreeLogger logger, com.google.gwt.core.ext.GeneratorContext context, String typeName)
           
protected static void generateI18nHelperFilesInto(Map<String,Set<String>> discoveredI18nMap, Map<String,String> translationKeyFieldMap, File destDir)
          Generates all helper files that developers can use to assist with i18n work.
static String getLocaleFromBundlePath(String bundlePath)
          Gets the locale information from the given bundle path.
protected static void recordBundleKeys(Map<String,Set<String>> discoveredI18nMap, String locale, String bundlePath)
          Records all of the i18n keys found in the given bundle.
 
Methods inherited from class org.jboss.errai.config.rebind.AbstractAsyncGenerator
generateAsync, startAsyncGeneratorsAndWaitFor
 
Methods inherited from class com.google.gwt.core.ext.Generator
escape
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TranslationServiceGenerator

public TranslationServiceGenerator()
Method Detail

generate

public String generate(com.google.gwt.core.ext.TreeLogger logger,
                       com.google.gwt.core.ext.GeneratorContext context,
                       String typeName)
                throws com.google.gwt.core.ext.UnableToCompleteException
Specified by:
generate in class com.google.gwt.core.ext.Generator
Throws:
com.google.gwt.core.ext.UnableToCompleteException

generate

public String generate(com.google.gwt.core.ext.TreeLogger logger,
                       com.google.gwt.core.ext.GeneratorContext context)
Description copied from class: AbstractAsyncGenerator
Called by AbstractAsyncGenerator.generateAsync(TreeLogger, GeneratorContext) to carry out the actual code generation.

Specified by:
generate in class AbstractAsyncGenerator
context - the generator context to use.
Returns:
the generated code.

recordBundleKeys

protected static void recordBundleKeys(Map<String,Set<String>> discoveredI18nMap,
                                       String locale,
                                       String bundlePath)
Records all of the i18n keys found in the given bundle.

Parameters:
discoveredI18nMap -
locale -
bundlePath -

getLocaleFromBundlePath

public static String getLocaleFromBundlePath(String bundlePath)
Gets the locale information from the given bundle path. For example, if the bundle path is "org/example/myBundle_en_US.json" then this method will return "en_US".

Parameters:
bundlePath - path to the message bundle

generateI18nHelperFilesInto

protected static void generateI18nHelperFilesInto(Map<String,Set<String>> discoveredI18nMap,
                                                  Map<String,String> translationKeyFieldMap,
                                                  File destDir)
Generates all helper files that developers can use to assist with i18n work. This includes the "missing i18n keys" report(s) as well as a set of JSON files that can be used as a starting-point for translations.

Parameters:
discoveredI18nMap - a map of keys found in all scanned bundles
translationKeyFieldMap - a map of translation keys found in TranslationKey annotated fields
destDir - where to write the *.json files
context - the generator context

Errai 3.0.1-SNAPSHOT

Copyright © 2013-2014 JBoss, a division of Red Hat. All Rights Reserved.