Class Translator

java.lang.Object
de.tsl2.nano.util.Translator

public class Translator extends Object
machine translator using a REST service from WorldLingo.
Author:
Tom
  • Constructor Details

    • Translator

      public Translator()
  • Method Details

    • translate

      public static final String translate(Locale srcLang, Locale destLang, String words)
    • translateProperties

      public static Properties translateProperties(String name, Map origin, Locale srcLang, Locale destLang)
      translates all property values from srcLang to destLang. splits camel case expressions.
      Parameters:
      name - bundle name
      origin - properties to translate
      srcLang - source language
      destLang - destination language
      Returns:
      translated properties
    • translatePropertiesFast

      public static Map translatePropertiesFast(String name, Map origin, Locale srcLang, Locale destLang)
      tries to translate all properties on one request. if values have more than one word (myEntry=one two), the mapping will fail
      Parameters:
      name - bundle name
      origin - properties to translate
      srcLang - source language
      destLang - destination language
      Returns:
      translated properties
    • translateBundle

      public static Map translateBundle(String name, Set<String> keySet, Locale srcLang, Locale destLang)
      translates all property values from srcLang to destLang. Uses the ResourceBundle wrapper Messages to get the values for the given keys. splits camel case expressions. writes the bundle to a file and reloads the resource bundles.
      Parameters:
      name - bundle name
      keySet - key-set of a resource bundle.
      srcLang - source language
      destLang - destination language
      Returns:
      translated properties