Class TranslationMapStorage
- Direct Known Subclasses:
TranslationMapStorageAndroid
LocaleData.TranslationMap
to/from disk.
The LocaleData.TranslationMap
is represented in disk in the following format:
root
├── <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.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
A file interface that abstracts the underlying implementation.static interface
An interface that can return anTranslationMapStorage.AbstractFile
given a file path.static class
A provider that returns anTranslationMapStorage.IOFile
. -
Field Summary
-
Constructor Summary
ConstructorDescriptionTranslationMapStorage
(String filename) Creates a new instance that can be used to write or read aLocaleData.TranslationMap
. -
Method Summary
Modifier and TypeMethodDescriptionprotected LocaleData.TranslationMap
fromDisk
(TranslationMapStorage.AbstractFileProvider fileProvider, TranslationMapStorage.AbstractFile srcDirectory) Loads aLocaleData.TranslationMap
from the provided source directory.Loads aLocaleData.TranslationMap
from the provided source directory.toDisk
(LocaleData.TranslationMap translationMap, File dstDirectory) Saves the provided translation map to the provided destination directory.
-
Field Details
-
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:
-
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
-
-
Constructor Details
-
TranslationMapStorage
Creates a new instance that can be used to write or read aLocaleData.TranslationMap
.- Parameters:
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.
- Parameters:
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.- Returns:
- 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
Loads aLocaleData.TranslationMap
from the provided source directory.- Parameters:
srcDirectory
- The directory containing translations in the expected format.- Returns:
- 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
@Nullable protected LocaleData.TranslationMap fromDisk(@NonNull TranslationMapStorage.AbstractFileProvider fileProvider, @NonNull TranslationMapStorage.AbstractFile srcDirectory) Loads aLocaleData.TranslationMap
from the provided source directory.This is a more general version of
fromDisk(File)
, which can use different file providers.
-