Class TranslationMapStorage

Direct Known Subclasses:

public class TranslationMapStorage extends Object
A class that allows storing and loading a LocaleData.TranslationMap to/from disk.

The LocaleData.TranslationMap is represented in disk in the following format:

 ├── <locale>
 │   ├── <filename>
 ├── <locale>
 │   ├── <filename>
 │   │

Each locale is represented by a directory named after the locale and contains a translation file using a configurable filename. Each locale translation file is encoded in JSON format using the LocaleData.TxPullResponseData structure.

  • Field Details


      public static final String DEFAULT_TRANSLATION_FILENAME
      The default name for the translations files. It is used by the command line tool's pull command and by the cache providers that read translations from disk or write translations on disk.
      See Also:

      public static final String DEFAULT_TRANSLATIONS_DIR_NAME
      The default directory that contains the translation files. It is used by the command line tool's pull command and by the standard cache implementation.
      See Also:
    • TAG

      public static final String TAG
  • Constructor Details

    • TranslationMapStorage

      public TranslationMapStorage(@NonNull String filename)
      Creates a new instance that can be used to write or read a LocaleData.TranslationMap.
      filename - The name of a locale's translation file.
  • Method Details

    • toDisk

      @NonNull public HashMap<String,File> toDisk(@NonNull LocaleData.TranslationMap translationMap, @NonNull File dstDirectory)
      Saves the provided translation map to the provided destination directory.

      The method is synchronous and returns a map where each locale points to a translation file.

      The method does not delete the content of the destination directory. When saving a locale's translation file, it will replace the existing translation file, if any. Thus, subsequent calls to this method, given the same destination directory, will result in a mix of all the provided translation maps.

      translationMap - The translations to save on disk.
      dstDirectory - The directory to save the translations to. Existing translation files will be overwritten by the supported locale translations. If the directory does not exist, it will be created.
      A map with the saved files. If there was an error saving one or more locales, they won't be included in the returned map. An empty map can be returned if everything failed.
    • fromDisk

      @Nullable public LocaleData.TranslationMap fromDisk(@NonNull File srcDirectory)
      Loads a LocaleData.TranslationMap from the provided source directory.
      srcDirectory - The directory containing translations in the expected format.
      The translation map or null if the directory isn't found or it's empty. If some locales fail to load, they won't be added in the returned map.
    • fromDisk

      Loads a LocaleData.TranslationMap from the provided source directory.

      This is a more general version of fromDisk(File), which can use different file providers.