com.ephox.editlive.plugins
Class Translator

java.lang.Object
  extended by com.ephox.editlive.plugins.Translator

public final class Translator
extends Object

Loads strings using the EditLive! internal translation API. This API expects language strings to be in files located in the same folder as the resourceClass constructor parameter; they are loaded using Class.getResourceAsStream(String). The filenames must conform to a the following pattern:

The list of locale codes supported can be found in the online documentation for Locale.

String number resolution is performed as follows:

Since:
7.5

Constructor Summary
Translator(Class<?> resourceClass)
          Constructs the translator.
 
Method Summary
 String getString(int id)
          Resolves a specific string using algorithms detailed in the class header.
 String getString(int id, String... strings)
          Calls getString(int) and then replaces tokens inside the resolved string with the given strings.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Translator

public Translator(Class<?> resourceClass)
Constructs the translator.

Parameters:
resourceClass - Class used to load language string files
Method Detail

getString

public String getString(int id)
Resolves a specific string using algorithms detailed in the class header.

Parameters:
id - string ID to search for
Returns:
resolved string, or an empty string if the id does not resolve

getString

public String getString(int id,
                        String... strings)
Calls getString(int) and then replaces tokens inside the resolved string with the given strings. Tokens are in the format {0}, {1}, {2} etc each corresponding to a string in the strings argument.

For example, if string id 1 is "{0} are not {1}" and this API is called using translator.getString(1, "apples", "oranges"); then this method will return "apples are not oranges". Tokens that do not exist in the strings argument are left in their token form within the resolved string.

Parameters:
id - string ID to search for
strings - replacement strings for tokens in the resolved string
Returns:
resolved string with replaced tokens, or an empty string if the id does not resolve

Copyright (c) 2005-2012 Ephox Pty Ltd. All rights reserved.