create new interface for io operations
This commit is contained in:
parent
d2d8ef4cb4
commit
356038f987
51
src/main/java/de/marhali/easyi18n/io/IOStrategy.java
Normal file
51
src/main/java/de/marhali/easyi18n/io/IOStrategy.java
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
package de.marhali.easyi18n.io;
|
||||||
|
|
||||||
|
import com.intellij.openapi.project.Project;
|
||||||
|
|
||||||
|
import de.marhali.easyi18n.model.SettingsState;
|
||||||
|
import de.marhali.easyi18n.model.TranslationData;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Primary interface for the exchange of translation data with the underlying IO system.
|
||||||
|
* The selection of the right IO strategy is done by the @canUse method (first match).
|
||||||
|
* Every strategy needs to be registered inside {@link de.marhali.easyi18n.DataStore}
|
||||||
|
*
|
||||||
|
* @author marhali
|
||||||
|
*/
|
||||||
|
public interface IOStrategy {
|
||||||
|
/**
|
||||||
|
* Decides whether this strategy should be applied or not. First matching one will be used.
|
||||||
|
* @param project IntelliJ project context
|
||||||
|
* @param localesPath Root directory which leads to all i18n files
|
||||||
|
* @param state Plugin configuration
|
||||||
|
* @return true if strategy is responsible for the found structure
|
||||||
|
*/
|
||||||
|
boolean canUse(@NotNull Project project, @NotNull String localesPath, @NotNull SettingsState state);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads the translation files and passes them in the result consumer.
|
||||||
|
* Result payload might be null if operation failed.
|
||||||
|
* @param project IntelliJ project context
|
||||||
|
* @param localesPath Root directory which leads to all i18n files
|
||||||
|
* @param state Plugin configuration
|
||||||
|
* @param result Passes loaded data
|
||||||
|
*/
|
||||||
|
void read(@NotNull Project project, @NotNull String localesPath, @NotNull SettingsState state,
|
||||||
|
@NotNull Consumer<@Nullable TranslationData> result);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Writes the provided translation data to the IO system.
|
||||||
|
* @param project InteliJ project context
|
||||||
|
* @param localesPath Root directory which leads to all i18n files
|
||||||
|
* @param state Plugin configuration
|
||||||
|
* @param data Translations to save
|
||||||
|
* @param result Indicates whether the operation was successful
|
||||||
|
*/
|
||||||
|
void write(@NotNull Project project, @NotNull String localesPath, @NotNull SettingsState state,
|
||||||
|
@NotNull TranslationData data, @NotNull Consumer<Boolean> result);
|
||||||
|
}
|
@ -13,6 +13,7 @@ import java.util.function.Consumer;
|
|||||||
* Can be implemented by various standards. Such as JSON, Properties-Bundle and so on.
|
* Can be implemented by various standards. Such as JSON, Properties-Bundle and so on.
|
||||||
* @author marhali
|
* @author marhali
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public interface TranslatorIO {
|
public interface TranslatorIO {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user