apply new internal data structure
This commit is contained in:
parent
c906f144fa
commit
92d6e6604d
@ -1,9 +1,9 @@
|
|||||||
package de.marhali.easyi18n;
|
package de.marhali.easyi18n;
|
||||||
|
|
||||||
import de.marhali.easyi18n.model.KeyPath;
|
|
||||||
import de.marhali.easyi18n.model.bus.BusListener;
|
import de.marhali.easyi18n.model.bus.BusListener;
|
||||||
import de.marhali.easyi18n.model.TranslationData;
|
import de.marhali.easyi18n.model.TranslationData;
|
||||||
|
|
||||||
|
import de.marhali.easyi18n.model.KeyPath;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ package de.marhali.easyi18n;
|
|||||||
import com.intellij.openapi.application.ApplicationManager;
|
import com.intellij.openapi.application.ApplicationManager;
|
||||||
import com.intellij.openapi.project.Project;
|
import com.intellij.openapi.project.Project;
|
||||||
|
|
||||||
import de.marhali.easyi18n.model.TranslationUpdate;
|
import de.marhali.easyi18n.model.action.TranslationUpdate;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
@ -67,7 +67,7 @@ public class InstanceManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(!update.isDeletion()) { // Create or re-create translation with changed data
|
if(!update.isDeletion()) { // Create or re-create translation with changed data
|
||||||
this.store.getData().setTranslation(update.getChange().getKey(), update.getChange().getTranslation());
|
this.store.getData().setTranslation(update.getChange().getKey(), update.getChange().getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
this.store.saveToPersistenceLayer(success -> {
|
this.store.saveToPersistenceLayer(success -> {
|
||||||
|
@ -7,7 +7,7 @@ import com.intellij.openapi.project.Project;
|
|||||||
import com.intellij.ui.content.Content;
|
import com.intellij.ui.content.Content;
|
||||||
|
|
||||||
import de.marhali.easyi18n.dialog.AddDialog;
|
import de.marhali.easyi18n.dialog.AddDialog;
|
||||||
import de.marhali.easyi18n.model.translation.KeyPath;
|
import de.marhali.easyi18n.model.KeyPath;
|
||||||
import de.marhali.easyi18n.service.WindowManager;
|
import de.marhali.easyi18n.service.WindowManager;
|
||||||
import de.marhali.easyi18n.util.KeyPathConverter;
|
import de.marhali.easyi18n.util.KeyPathConverter;
|
||||||
import de.marhali.easyi18n.util.TreeUtil;
|
import de.marhali.easyi18n.util.TreeUtil;
|
||||||
|
@ -5,10 +5,10 @@ import com.intellij.openapi.ui.DialogBuilder;
|
|||||||
import com.intellij.openapi.ui.DialogWrapper;
|
import com.intellij.openapi.ui.DialogWrapper;
|
||||||
|
|
||||||
import de.marhali.easyi18n.InstanceManager;
|
import de.marhali.easyi18n.InstanceManager;
|
||||||
import de.marhali.easyi18n.model.TranslationCreate;
|
import de.marhali.easyi18n.model.action.TranslationCreate;
|
||||||
import de.marhali.easyi18n.model.translation.KeyPath;
|
import de.marhali.easyi18n.model.KeyPath;
|
||||||
import de.marhali.easyi18n.model.translation.Translation;
|
import de.marhali.easyi18n.model.Translation;
|
||||||
import de.marhali.easyi18n.model.translation.TranslationValue;
|
import de.marhali.easyi18n.model.TranslationValue;
|
||||||
import de.marhali.easyi18n.settings.ProjectSettingsService;
|
import de.marhali.easyi18n.settings.ProjectSettingsService;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
@ -6,9 +6,9 @@ import com.intellij.openapi.ui.DialogWrapper;
|
|||||||
|
|
||||||
import de.marhali.easyi18n.InstanceManager;
|
import de.marhali.easyi18n.InstanceManager;
|
||||||
import de.marhali.easyi18n.dialog.descriptor.DeleteActionDescriptor;
|
import de.marhali.easyi18n.dialog.descriptor.DeleteActionDescriptor;
|
||||||
import de.marhali.easyi18n.model.TranslationDelete;
|
import de.marhali.easyi18n.model.action.TranslationDelete;
|
||||||
import de.marhali.easyi18n.model.TranslationUpdate;
|
import de.marhali.easyi18n.model.action.TranslationUpdate;
|
||||||
import de.marhali.easyi18n.model.translation.Translation;
|
import de.marhali.easyi18n.model.Translation;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
@ -7,9 +7,9 @@ import com.intellij.ui.components.JBTextField;
|
|||||||
import com.intellij.util.ui.FormBuilder;
|
import com.intellij.util.ui.FormBuilder;
|
||||||
|
|
||||||
import de.marhali.easyi18n.InstanceManager;
|
import de.marhali.easyi18n.InstanceManager;
|
||||||
import de.marhali.easyi18n.model.translation.KeyPath;
|
import de.marhali.easyi18n.model.KeyPath;
|
||||||
import de.marhali.easyi18n.model.translation.Translation;
|
import de.marhali.easyi18n.model.Translation;
|
||||||
import de.marhali.easyi18n.model.translation.TranslationValue;
|
import de.marhali.easyi18n.model.TranslationValue;
|
||||||
import de.marhali.easyi18n.settings.ProjectSettings;
|
import de.marhali.easyi18n.settings.ProjectSettings;
|
||||||
import de.marhali.easyi18n.settings.ProjectSettingsService;
|
import de.marhali.easyi18n.settings.ProjectSettingsService;
|
||||||
import de.marhali.easyi18n.util.KeyPathConverter;
|
import de.marhali.easyi18n.util.KeyPathConverter;
|
||||||
|
@ -1,59 +1,37 @@
|
|||||||
package de.marhali.easyi18n.model;
|
package de.marhali.easyi18n.model;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a full translation key with all sections.
|
* Represents the absolute key path for a desired translation.
|
||||||
* Implementations can use single section or variable section length variants.
|
* The key could be based one or many sections.
|
||||||
* The respective layer (io, presentation) is responsible for using the correct mapping mechanism.
|
* Classes implementing this structure need to take care on how to layer translations paths.
|
||||||
* @author marhali
|
* @author marhali
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
|
||||||
public class KeyPath extends ArrayList<String> {
|
public class KeyPath extends ArrayList<String> {
|
||||||
|
|
||||||
public static final String DELIMITER = ".";
|
public KeyPath() {}
|
||||||
|
|
||||||
public static KeyPath of(@NotNull String... path) {
|
public KeyPath(@Nullable String... path) {
|
||||||
return new KeyPath(List.of(path));
|
super.addAll(List.of(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
public KeyPath() {
|
public KeyPath(@NotNull List<String> path) {
|
||||||
super();
|
super(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public KeyPath(@NotNull KeyPath path, String... pathToAppend) {
|
public KeyPath(@NotNull KeyPath path, @Nullable String... pathToAppend) {
|
||||||
this(path);
|
this(path);
|
||||||
this.addAll(List.of(pathToAppend));
|
super.addAll(List.of(pathToAppend));
|
||||||
}
|
}
|
||||||
|
|
||||||
public KeyPath(@NotNull Collection<? extends String> c) {
|
@Override
|
||||||
super(c);
|
public String toString() {
|
||||||
}
|
// Just a simple array view (e.g. [first, second]) - use KeyPathConverter to properly convert a key path
|
||||||
|
return super.toString();
|
||||||
public KeyPath(@NotNull String simplePath) {
|
|
||||||
this(List.of(simplePath.split(Pattern.quote(DELIMITER))));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* <b>Note: </b>Use {@link KeyPathConverter} if you want to keep hierarchy.
|
|
||||||
* @return simple path representation by adding delimiter between the secton nodes
|
|
||||||
*/
|
|
||||||
public String toSimpleString() {
|
|
||||||
StringBuilder builder = new StringBuilder();
|
|
||||||
|
|
||||||
for(String section : this) {
|
|
||||||
if(builder.length() > 0) {
|
|
||||||
builder.append(DELIMITER);
|
|
||||||
}
|
|
||||||
|
|
||||||
builder.append(section);
|
|
||||||
}
|
|
||||||
|
|
||||||
return builder.toString();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,30 +1,54 @@
|
|||||||
package de.marhali.easyi18n.model;
|
package de.marhali.easyi18n.model;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents all translations for an element. The assignment to an element is done in the using class.
|
* Represents a translation with defined key and locale values.
|
||||||
* This class contains only the translations for this unspecific element.
|
*
|
||||||
* @author marhali
|
* @author marhali
|
||||||
*/
|
*/
|
||||||
@Deprecated // Replaced by TranslationValue
|
public class Translation {
|
||||||
public class Translation extends HashMap<String, String> {
|
|
||||||
public Translation() {
|
private final @NotNull KeyPath key;
|
||||||
super();
|
private @Nullable TranslationValue value;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new translation instance.
|
||||||
|
* @param key Absolute key path
|
||||||
|
* @param value Values to set - nullable to indicate removal
|
||||||
|
*/
|
||||||
|
public Translation(@NotNull KeyPath key, @Nullable TranslationValue value) {
|
||||||
|
this.key = key;
|
||||||
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Translation(String locale, String content) {
|
/**
|
||||||
this();
|
* @return Absolute key path
|
||||||
super.put(locale, content);
|
*/
|
||||||
|
public @NotNull KeyPath getKey() {
|
||||||
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Translation add(String locale, String content) {
|
/**
|
||||||
super.put(locale, content);
|
* @return values - nullable to indicate removal
|
||||||
return this;
|
*/
|
||||||
|
public @Nullable TranslationValue getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param value Values to set - nullable to indicate removal
|
||||||
|
*/
|
||||||
|
public void setValue(@Nullable TranslationValue value) {
|
||||||
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return super.toString();
|
return "Translation{" +
|
||||||
|
"key=" + key +
|
||||||
|
", value=" + value +
|
||||||
|
'}';
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -93,7 +93,7 @@ public class TranslationData {
|
|||||||
* @param fullPath Absolute translation key path
|
* @param fullPath Absolute translation key path
|
||||||
* @return Found translation. Can be null if path is empty or is not a leaf element
|
* @return Found translation. Can be null if path is empty or is not a leaf element
|
||||||
*/
|
*/
|
||||||
public @Nullable Translation getTranslation(@NotNull KeyPath fullPath) {
|
public @Nullable TranslationValue getTranslation(@NotNull KeyPath fullPath) {
|
||||||
TranslationNode node = this.getNode(fullPath);
|
TranslationNode node = this.getNode(fullPath);
|
||||||
|
|
||||||
if(node == null || !node.isLeaf()) {
|
if(node == null || !node.isLeaf()) {
|
||||||
@ -109,7 +109,7 @@ public class TranslationData {
|
|||||||
* @param fullPath Absolute translation key path
|
* @param fullPath Absolute translation key path
|
||||||
* @param translation Translation to set. Can be null to delete the corresponding node
|
* @param translation Translation to set. Can be null to delete the corresponding node
|
||||||
*/
|
*/
|
||||||
public void setTranslation(@NotNull KeyPath fullPath, @Nullable Translation translation) {
|
public void setTranslation(@NotNull KeyPath fullPath, @Nullable TranslationValue translation) {
|
||||||
if(fullPath.isEmpty()) {
|
if(fullPath.isEmpty()) {
|
||||||
throw new IllegalArgumentException("Key path cannot be empty");
|
throw new IllegalArgumentException("Key path cannot be empty");
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ public class TranslationNode {
|
|||||||
private Map<String, TranslationNode> children;
|
private Map<String, TranslationNode> children;
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private Translation value;
|
private TranslationValue value;
|
||||||
|
|
||||||
public TranslationNode(boolean sort) {
|
public TranslationNode(boolean sort) {
|
||||||
this(sort ? new TreeMap<>() : new LinkedHashMap<>());
|
this(sort ? new TreeMap<>() : new LinkedHashMap<>());
|
||||||
@ -40,7 +40,7 @@ public class TranslationNode {
|
|||||||
public TranslationNode(@NotNull Map<String, TranslationNode> children) {
|
public TranslationNode(@NotNull Map<String, TranslationNode> children) {
|
||||||
this.parent = null;
|
this.parent = null;
|
||||||
this.children = children;
|
this.children = children;
|
||||||
this.value = new Translation();
|
this.value = new TranslationValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -62,11 +62,11 @@ public class TranslationNode {
|
|||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
public @NotNull Translation getValue() {
|
public @NotNull TranslationValue getValue() {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setValue(@NotNull Translation value) {
|
public void setValue(@NotNull TranslationValue value) {
|
||||||
this.children.clear();
|
this.children.clear();
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
@ -93,7 +93,7 @@ public class TranslationNode {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setChildren(@NotNull String key, @NotNull Translation translation) {
|
public void setChildren(@NotNull String key, @NotNull TranslationValue translation) {
|
||||||
this.setChildren(key).setValue(translation);
|
this.setChildren(key).setValue(translation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
package de.marhali.easyi18n.model.translation;
|
package de.marhali.easyi18n.model;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@ -27,7 +28,7 @@ public class TranslationValue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public TranslationValue(@NotNull String locale, @NotNull String value) {
|
public TranslationValue(@NotNull String locale, @NotNull String value) {
|
||||||
this(Map.of(locale, value));
|
this(new HashMap<>(Map.of(locale, value)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public TranslationValue() {
|
public TranslationValue() {
|
||||||
@ -58,6 +59,10 @@ public class TranslationValue {
|
|||||||
this.values = values;
|
this.values = values;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public @NotNull Map<String, String> getValues() {
|
||||||
|
return values;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Overrides or sets a value for a specific locale.
|
* Overrides or sets a value for a specific locale.
|
||||||
* @param locale Locale type
|
* @param locale Locale type
|
||||||
@ -71,6 +76,10 @@ public class TranslationValue {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void remove(String locale) {
|
||||||
|
values.remove(locale);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the associated value for a specific locale
|
* Retrieves the associated value for a specific locale
|
||||||
* @param locale Locale type
|
* @param locale Locale type
|
||||||
@ -80,6 +89,24 @@ public class TranslationValue {
|
|||||||
return values.get(locale);
|
return values.get(locale);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean containsLocale(@Nullable String locale) {
|
||||||
|
return values.containsKey(locale);
|
||||||
|
}
|
||||||
|
|
||||||
|
public @NotNull Collection<String> getLocaleValues() {
|
||||||
|
return values.values();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int size() {
|
||||||
|
return values.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clear() {
|
||||||
|
description = null;
|
||||||
|
values.clear();
|
||||||
|
misc = null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* I18n support data
|
* I18n support data
|
||||||
* @return Data
|
* @return Data
|
@ -1,4 +1,6 @@
|
|||||||
package de.marhali.easyi18n.model;
|
package de.marhali.easyi18n.model.action;
|
||||||
|
|
||||||
|
import de.marhali.easyi18n.model.Translation;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
@ -7,7 +9,7 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
* @author marhali
|
* @author marhali
|
||||||
*/
|
*/
|
||||||
public class TranslationCreate extends TranslationUpdate {
|
public class TranslationCreate extends TranslationUpdate {
|
||||||
public TranslationCreate(@NotNull KeyedTranslation translation) {
|
public TranslationCreate(@NotNull Translation translation) {
|
||||||
super(null, translation);
|
super(null, translation);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,6 @@
|
|||||||
package de.marhali.easyi18n.model;
|
package de.marhali.easyi18n.model.action;
|
||||||
|
|
||||||
|
import de.marhali.easyi18n.model.Translation;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
@ -7,7 +9,7 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
* @author marhali
|
* @author marhali
|
||||||
*/
|
*/
|
||||||
public class TranslationDelete extends TranslationUpdate {
|
public class TranslationDelete extends TranslationUpdate {
|
||||||
public TranslationDelete(@NotNull KeyedTranslation translation) {
|
public TranslationDelete(@NotNull Translation translation) {
|
||||||
super(translation, null);
|
super(translation, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,5 +1,6 @@
|
|||||||
package de.marhali.easyi18n.model;
|
package de.marhali.easyi18n.model.action;
|
||||||
|
|
||||||
|
import de.marhali.easyi18n.model.Translation;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -10,19 +11,19 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
*/
|
*/
|
||||||
public class TranslationUpdate {
|
public class TranslationUpdate {
|
||||||
|
|
||||||
private final @Nullable KeyedTranslation origin;
|
private final @Nullable Translation origin;
|
||||||
private final @Nullable KeyedTranslation change;
|
private final @Nullable Translation change;
|
||||||
|
|
||||||
public TranslationUpdate(@Nullable KeyedTranslation origin, @Nullable KeyedTranslation change) {
|
public TranslationUpdate(@Nullable Translation origin, @Nullable Translation change) {
|
||||||
this.origin = origin;
|
this.origin = origin;
|
||||||
this.change = change;
|
this.change = change;
|
||||||
}
|
}
|
||||||
|
|
||||||
public @Nullable KeyedTranslation getOrigin() {
|
public @Nullable Translation getOrigin() {
|
||||||
return origin;
|
return origin;
|
||||||
}
|
}
|
||||||
|
|
||||||
public @Nullable KeyedTranslation getChange() {
|
public @Nullable Translation getChange() {
|
||||||
return change;
|
return change;
|
||||||
}
|
}
|
||||||
|
|
@ -1,7 +1,10 @@
|
|||||||
package de.marhali.easyi18n.util;
|
package de.marhali.easyi18n.util;
|
||||||
|
|
||||||
import de.marhali.easyi18n.model.translation.KeyPath;
|
import com.intellij.openapi.project.Project;
|
||||||
|
|
||||||
|
import de.marhali.easyi18n.model.KeyPath;
|
||||||
import de.marhali.easyi18n.settings.ProjectSettings;
|
import de.marhali.easyi18n.settings.ProjectSettings;
|
||||||
|
import de.marhali.easyi18n.settings.ProjectSettingsService;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
@ -20,10 +23,18 @@ public class KeyPathConverter {
|
|||||||
* Constructs a new converter instance
|
* Constructs a new converter instance
|
||||||
* @param settings Delimiter configuration
|
* @param settings Delimiter configuration
|
||||||
*/
|
*/
|
||||||
public KeyPathConverter(ProjectSettings settings) {
|
public KeyPathConverter(@NotNull ProjectSettings settings) {
|
||||||
this.settings = settings;
|
this.settings = settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see #KeyPathConverter(ProjectSettings)
|
||||||
|
* @param project Opened project
|
||||||
|
*/
|
||||||
|
public KeyPathConverter(@NotNull Project project) {
|
||||||
|
this(ProjectSettingsService.get(project).getState());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transform to character literal representation
|
* Transform to character literal representation
|
||||||
* @param path Absolute key path
|
* @param path Absolute key path
|
||||||
|
@ -2,7 +2,7 @@ package de.marhali.easyi18n;
|
|||||||
|
|
||||||
import de.marhali.easyi18n.io.parser.ParserStrategyType;
|
import de.marhali.easyi18n.io.parser.ParserStrategyType;
|
||||||
import de.marhali.easyi18n.model.FolderStrategyType;
|
import de.marhali.easyi18n.model.FolderStrategyType;
|
||||||
import de.marhali.easyi18n.model.translation.KeyPath;
|
import de.marhali.easyi18n.model.KeyPath;
|
||||||
import de.marhali.easyi18n.settings.ProjectSettings;
|
import de.marhali.easyi18n.settings.ProjectSettings;
|
||||||
import de.marhali.easyi18n.util.KeyPathConverter;
|
import de.marhali.easyi18n.util.KeyPathConverter;
|
||||||
|
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
package de.marhali.easyi18n;
|
package de.marhali.easyi18n;
|
||||||
|
|
||||||
import de.marhali.easyi18n.model.KeyPath;
|
|
||||||
import de.marhali.easyi18n.model.Translation;
|
|
||||||
import de.marhali.easyi18n.model.TranslationData;
|
import de.marhali.easyi18n.model.TranslationData;
|
||||||
import de.marhali.easyi18n.model.TranslationNode;
|
import de.marhali.easyi18n.model.TranslationNode;
|
||||||
|
|
||||||
|
import de.marhali.easyi18n.model.KeyPath;
|
||||||
|
import de.marhali.easyi18n.model.TranslationValue;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
@ -17,27 +17,27 @@ import java.util.*;
|
|||||||
public class TranslationDataTest {
|
public class TranslationDataTest {
|
||||||
|
|
||||||
private final int numOfTranslations = 14;
|
private final int numOfTranslations = 14;
|
||||||
private final Translation translation = new Translation("en", "test");
|
private final TranslationValue translation = new TranslationValue("en", "test");
|
||||||
|
|
||||||
private void addTranslations(TranslationData data) {
|
private void addTranslations(TranslationData data) {
|
||||||
data.setTranslation(KeyPath.of("zulu"), translation);
|
data.setTranslation(new KeyPath("zulu"), translation);
|
||||||
data.setTranslation(KeyPath.of("gamma"), translation);
|
data.setTranslation(new KeyPath("gamma"), translation);
|
||||||
|
|
||||||
data.setTranslation(KeyPath.of("foxtrot.super.long.key"), translation);
|
data.setTranslation(new KeyPath("foxtrot.super.long.key"), translation);
|
||||||
data.setTranslation(KeyPath.of("foxtrot", "super", "long", "key"), translation);
|
data.setTranslation(new KeyPath("foxtrot", "super", "long", "key"), translation);
|
||||||
|
|
||||||
data.setTranslation(KeyPath.of("charlie.b", "sub"), translation);
|
data.setTranslation(new KeyPath("charlie.b", "sub"), translation);
|
||||||
data.setTranslation(KeyPath.of("charlie.a", "sub"), translation);
|
data.setTranslation(new KeyPath("charlie.a", "sub"), translation);
|
||||||
|
|
||||||
data.setTranslation(KeyPath.of("bravo.b"), translation);
|
data.setTranslation(new KeyPath("bravo.b"), translation);
|
||||||
data.setTranslation(KeyPath.of("bravo.c"), translation);
|
data.setTranslation(new KeyPath("bravo.c"), translation);
|
||||||
data.setTranslation(KeyPath.of("bravo.a"), translation);
|
data.setTranslation(new KeyPath("bravo.a"), translation);
|
||||||
data.setTranslation(KeyPath.of("bravo.d"), translation);
|
data.setTranslation(new KeyPath("bravo.d"), translation);
|
||||||
|
|
||||||
data.setTranslation(KeyPath.of("bravo", "b"), translation);
|
data.setTranslation(new KeyPath("bravo", "b"), translation);
|
||||||
data.setTranslation(KeyPath.of("bravo", "c"), translation);
|
data.setTranslation(new KeyPath("bravo", "c"), translation);
|
||||||
data.setTranslation(KeyPath.of("bravo", "a"), translation);
|
data.setTranslation(new KeyPath("bravo", "a"), translation);
|
||||||
data.setTranslation(KeyPath.of("bravo", "d"), translation);
|
data.setTranslation(new KeyPath("bravo", "d"), translation);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -46,13 +46,13 @@ public class TranslationDataTest {
|
|||||||
this.addTranslations(data);
|
this.addTranslations(data);
|
||||||
|
|
||||||
Set<KeyPath> expectation = new LinkedHashSet<>(Arrays.asList(
|
Set<KeyPath> expectation = new LinkedHashSet<>(Arrays.asList(
|
||||||
KeyPath.of("bravo", "a"), KeyPath.of("bravo", "b"), KeyPath.of("bravo", "c"), KeyPath.of("bravo", "d"),
|
new KeyPath("bravo", "a"), new KeyPath("bravo", "b"), new KeyPath("bravo", "c"), new KeyPath("bravo", "d"),
|
||||||
KeyPath.of("bravo.a"), KeyPath.of("bravo.b"), KeyPath.of("bravo.c"), KeyPath.of("bravo.d"),
|
new KeyPath("bravo.a"), new KeyPath("bravo.b"), new KeyPath("bravo.c"), new KeyPath("bravo.d"),
|
||||||
KeyPath.of("charlie.a", "sub"), KeyPath.of("charlie.b", "sub"),
|
new KeyPath("charlie.a", "sub"), new KeyPath("charlie.b", "sub"),
|
||||||
KeyPath.of("foxtrot", "super", "long", "key"),
|
new KeyPath("foxtrot", "super", "long", "key"),
|
||||||
KeyPath.of("foxtrot.super.long.key"),
|
new KeyPath("foxtrot.super.long.key"),
|
||||||
KeyPath.of("gamma"),
|
new KeyPath("gamma"),
|
||||||
KeyPath.of("zulu")
|
new KeyPath("zulu")
|
||||||
));
|
));
|
||||||
|
|
||||||
Assert.assertEquals(data.getFullKeys(), expectation);
|
Assert.assertEquals(data.getFullKeys(), expectation);
|
||||||
@ -65,13 +65,13 @@ public class TranslationDataTest {
|
|||||||
this.addTranslations(data);
|
this.addTranslations(data);
|
||||||
|
|
||||||
Set<KeyPath> expectation = new LinkedHashSet<>(Arrays.asList(
|
Set<KeyPath> expectation = new LinkedHashSet<>(Arrays.asList(
|
||||||
KeyPath.of("zulu"),
|
new KeyPath("zulu"),
|
||||||
KeyPath.of("gamma"),
|
new KeyPath("gamma"),
|
||||||
KeyPath.of("foxtrot.super.long.key"),
|
new KeyPath("foxtrot.super.long.key"),
|
||||||
KeyPath.of("foxtrot", "super", "long", "key"),
|
new KeyPath("foxtrot", "super", "long", "key"),
|
||||||
KeyPath.of("charlie.b", "sub"), KeyPath.of("charlie.a", "sub"),
|
new KeyPath("charlie.b", "sub"), new KeyPath("charlie.a", "sub"),
|
||||||
KeyPath.of("bravo.b"), KeyPath.of("bravo.c"), KeyPath.of("bravo.a"), KeyPath.of("bravo.d"),
|
new KeyPath("bravo.b"), new KeyPath("bravo.c"), new KeyPath("bravo.a"), new KeyPath("bravo.d"),
|
||||||
KeyPath.of("bravo", "b"), KeyPath.of("bravo", "c"), KeyPath.of("bravo", "a"), KeyPath.of("bravo", "d")
|
new KeyPath("bravo", "b"), new KeyPath("bravo", "c"), new KeyPath("bravo", "a"), new KeyPath("bravo", "d")
|
||||||
));
|
));
|
||||||
|
|
||||||
Assert.assertEquals(data.getFullKeys(), expectation);
|
Assert.assertEquals(data.getFullKeys(), expectation);
|
||||||
@ -82,35 +82,35 @@ public class TranslationDataTest {
|
|||||||
public void testDelete() {
|
public void testDelete() {
|
||||||
TranslationData data = new TranslationData(true);
|
TranslationData data = new TranslationData(true);
|
||||||
|
|
||||||
data.setTranslation(KeyPath.of("alpha"), translation);
|
data.setTranslation(new KeyPath("alpha"), translation);
|
||||||
data.setTranslation(KeyPath.of("nested.alpha"), translation);
|
data.setTranslation(new KeyPath("nested.alpha"), translation);
|
||||||
data.setTranslation(KeyPath.of("nested.long.bravo"), translation);
|
data.setTranslation(new KeyPath("nested.long.bravo"), translation);
|
||||||
|
|
||||||
data.setTranslation(KeyPath.of("beta"), translation);
|
data.setTranslation(new KeyPath("beta"), translation);
|
||||||
data.setTranslation(KeyPath.of("nested", "alpha"), translation);
|
data.setTranslation(new KeyPath("nested", "alpha"), translation);
|
||||||
data.setTranslation(KeyPath.of("nested", "long", "bravo"), translation);
|
data.setTranslation(new KeyPath("nested", "long", "bravo"), translation);
|
||||||
|
|
||||||
Assert.assertEquals(data.getFullKeys().size(), 6);
|
Assert.assertEquals(data.getFullKeys().size(), 6);
|
||||||
|
|
||||||
data.setTranslation(KeyPath.of("alpha"), null);
|
data.setTranslation(new KeyPath("alpha"), null);
|
||||||
data.setTranslation(KeyPath.of("nested.alpha"), null);
|
data.setTranslation(new KeyPath("nested.alpha"), null);
|
||||||
data.setTranslation(KeyPath.of("nested.long.bravo"), null);
|
data.setTranslation(new KeyPath("nested.long.bravo"), null);
|
||||||
|
|
||||||
Assert.assertEquals(data.getFullKeys().size(), 3);
|
Assert.assertEquals(data.getFullKeys().size(), 3);
|
||||||
|
|
||||||
data.setTranslation(KeyPath.of("beta"), null);
|
data.setTranslation(new KeyPath("beta"), null);
|
||||||
data.setTranslation(KeyPath.of("nested", "alpha"), null);
|
data.setTranslation(new KeyPath("nested", "alpha"), null);
|
||||||
data.setTranslation(KeyPath.of("nested", "long", "bravo"), null);
|
data.setTranslation(new KeyPath("nested", "long", "bravo"), null);
|
||||||
|
|
||||||
Assert.assertEquals(data.getFullKeys().size(), 0);
|
Assert.assertEquals(data.getFullKeys().size(), 0);
|
||||||
|
|
||||||
Assert.assertNull(data.getTranslation(KeyPath.of("alpha")));
|
Assert.assertNull(data.getTranslation(new KeyPath("alpha")));
|
||||||
Assert.assertNull(data.getTranslation(KeyPath.of("nested.alpha")));
|
Assert.assertNull(data.getTranslation(new KeyPath("nested.alpha")));
|
||||||
Assert.assertNull(data.getTranslation(KeyPath.of("nested.long.bravo")));
|
Assert.assertNull(data.getTranslation(new KeyPath("nested.long.bravo")));
|
||||||
|
|
||||||
Assert.assertNull(data.getTranslation(KeyPath.of("beta")));
|
Assert.assertNull(data.getTranslation(new KeyPath("beta")));
|
||||||
Assert.assertNull(data.getTranslation(KeyPath.of("nested", "alpha")));
|
Assert.assertNull(data.getTranslation(new KeyPath("nested", "alpha")));
|
||||||
Assert.assertNull(data.getTranslation(KeyPath.of("nested", "long", "bravo")));
|
Assert.assertNull(data.getTranslation(new KeyPath("nested", "long", "bravo")));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -118,10 +118,10 @@ public class TranslationDataTest {
|
|||||||
TranslationData data = new TranslationData(true);
|
TranslationData data = new TranslationData(true);
|
||||||
this.addTranslations(data);
|
this.addTranslations(data);
|
||||||
|
|
||||||
data.setTranslation(KeyPath.of("foxtrot.super.long.key"), null);
|
data.setTranslation(new KeyPath("foxtrot.super.long.key"), null);
|
||||||
data.setTranslation(KeyPath.of("foxtrot", "super", "long", "key"), null);
|
data.setTranslation(new KeyPath("foxtrot", "super", "long", "key"), null);
|
||||||
|
|
||||||
Assert.assertNull(data.getTranslation(KeyPath.of("foxtrot.super.long.key")));
|
Assert.assertNull(data.getTranslation(new KeyPath("foxtrot.super.long.key")));
|
||||||
Assert.assertNull(data.getRootNode().getChildren().get("foxtrot"));
|
Assert.assertNull(data.getRootNode().getChildren().get("foxtrot"));
|
||||||
Assert.assertEquals(data.getFullKeys().size(), numOfTranslations - 2);
|
Assert.assertEquals(data.getFullKeys().size(), numOfTranslations - 2);
|
||||||
}
|
}
|
||||||
@ -130,70 +130,70 @@ public class TranslationDataTest {
|
|||||||
public void testOverwrite() {
|
public void testOverwrite() {
|
||||||
TranslationData data = new TranslationData(true);
|
TranslationData data = new TranslationData(true);
|
||||||
|
|
||||||
Translation before = new Translation("en", "before");
|
TranslationValue before = new TranslationValue("en", "before");
|
||||||
Translation after = new Translation("en", "after");
|
TranslationValue after = new TranslationValue("en", "after");
|
||||||
|
|
||||||
data.setTranslation(KeyPath.of("alpha"), before);
|
data.setTranslation(new KeyPath("alpha"), before);
|
||||||
data.setTranslation(KeyPath.of("nested.alpha"), before);
|
data.setTranslation(new KeyPath("nested.alpha"), before);
|
||||||
data.setTranslation(KeyPath.of("nested.long.bravo"), before);
|
data.setTranslation(new KeyPath("nested.long.bravo"), before);
|
||||||
data.setTranslation(KeyPath.of("beta"), before);
|
data.setTranslation(new KeyPath("beta"), before);
|
||||||
data.setTranslation(KeyPath.of("nested", "alpha"), before);
|
data.setTranslation(new KeyPath("nested", "alpha"), before);
|
||||||
data.setTranslation(KeyPath.of("nested", "long", "bravo"), before);
|
data.setTranslation(new KeyPath("nested", "long", "bravo"), before);
|
||||||
|
|
||||||
Assert.assertEquals(data.getTranslation(KeyPath.of("alpha")), before);
|
Assert.assertEquals(data.getTranslation(new KeyPath("alpha")), before);
|
||||||
Assert.assertEquals(data.getTranslation(KeyPath.of("nested.alpha")), before);
|
Assert.assertEquals(data.getTranslation(new KeyPath("nested.alpha")), before);
|
||||||
Assert.assertEquals(data.getTranslation(KeyPath.of("nested.long.bravo")), before);
|
Assert.assertEquals(data.getTranslation(new KeyPath("nested.long.bravo")), before);
|
||||||
Assert.assertEquals(data.getTranslation(KeyPath.of("beta")), before);
|
Assert.assertEquals(data.getTranslation(new KeyPath("beta")), before);
|
||||||
Assert.assertEquals(data.getTranslation(KeyPath.of("nested", "alpha")), before);
|
Assert.assertEquals(data.getTranslation(new KeyPath("nested", "alpha")), before);
|
||||||
Assert.assertEquals(data.getTranslation(KeyPath.of("nested", "long", "bravo")), before);
|
Assert.assertEquals(data.getTranslation(new KeyPath("nested", "long", "bravo")), before);
|
||||||
|
|
||||||
data.setTranslation(KeyPath.of("alpha"), after);
|
data.setTranslation(new KeyPath("alpha"), after);
|
||||||
data.setTranslation(KeyPath.of("nested.alpha"), after);
|
data.setTranslation(new KeyPath("nested.alpha"), after);
|
||||||
data.setTranslation(KeyPath.of("nested.long.bravo"), after);
|
data.setTranslation(new KeyPath("nested.long.bravo"), after);
|
||||||
data.setTranslation(KeyPath.of("beta"), after);
|
data.setTranslation(new KeyPath("beta"), after);
|
||||||
data.setTranslation(KeyPath.of("nested", "alpha"), after);
|
data.setTranslation(new KeyPath("nested", "alpha"), after);
|
||||||
data.setTranslation(KeyPath.of("nested", "long", "bravo"), after);
|
data.setTranslation(new KeyPath("nested", "long", "bravo"), after);
|
||||||
|
|
||||||
Assert.assertEquals(data.getTranslation(KeyPath.of("alpha")), after);
|
Assert.assertEquals(data.getTranslation(new KeyPath("alpha")), after);
|
||||||
Assert.assertEquals(data.getTranslation(KeyPath.of("nested.alpha")), after);
|
Assert.assertEquals(data.getTranslation(new KeyPath("nested.alpha")), after);
|
||||||
Assert.assertEquals(data.getTranslation(KeyPath.of("nested.long.bravo")), after);
|
Assert.assertEquals(data.getTranslation(new KeyPath("nested.long.bravo")), after);
|
||||||
Assert.assertEquals(data.getTranslation(KeyPath.of("beta")), after);
|
Assert.assertEquals(data.getTranslation(new KeyPath("beta")), after);
|
||||||
Assert.assertEquals(data.getTranslation(KeyPath.of("nested", "alpha")), after);
|
Assert.assertEquals(data.getTranslation(new KeyPath("nested", "alpha")), after);
|
||||||
Assert.assertEquals(data.getTranslation(KeyPath.of("nested", "long", "bravo")), after);
|
Assert.assertEquals(data.getTranslation(new KeyPath("nested", "long", "bravo")), after);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTransformRecursively() {
|
public void testTransformRecursively() {
|
||||||
TranslationData data = new TranslationData(true);
|
TranslationData data = new TranslationData(true);
|
||||||
|
|
||||||
data.setTranslation(KeyPath.of("alpha.nested.key"), translation);
|
data.setTranslation(new KeyPath("alpha.nested.key"), translation);
|
||||||
data.setTranslation(KeyPath.of("alpha.other"), translation);
|
data.setTranslation(new KeyPath("alpha.other"), translation);
|
||||||
data.setTranslation(KeyPath.of("bravo"), translation);
|
data.setTranslation(new KeyPath("bravo"), translation);
|
||||||
data.setTranslation(KeyPath.of("alpha", "nested", "key"), translation);
|
data.setTranslation(new KeyPath("alpha", "nested", "key"), translation);
|
||||||
data.setTranslation(KeyPath.of("alpha", "other"), translation);
|
data.setTranslation(new KeyPath("alpha", "other"), translation);
|
||||||
data.setTranslation(KeyPath.of("charlie"), translation);
|
data.setTranslation(new KeyPath("charlie"), translation);
|
||||||
|
|
||||||
Assert.assertEquals(6, data.getFullKeys().size());
|
Assert.assertEquals(6, data.getFullKeys().size());
|
||||||
|
|
||||||
data.setTranslation(KeyPath.of("alpha.nested"), translation);
|
data.setTranslation(new KeyPath("alpha.nested"), translation);
|
||||||
data.setTranslation(KeyPath.of("alpha.other.new"), translation);
|
data.setTranslation(new KeyPath("alpha.other.new"), translation);
|
||||||
data.setTranslation(KeyPath.of("bravo"), null);
|
data.setTranslation(new KeyPath("bravo"), null);
|
||||||
data.setTranslation(KeyPath.of("alpha", "nested"), translation);
|
data.setTranslation(new KeyPath("alpha", "nested"), translation);
|
||||||
data.setTranslation(KeyPath.of("alpha", "other", "new"), translation);
|
data.setTranslation(new KeyPath("alpha", "other", "new"), translation);
|
||||||
data.setTranslation(KeyPath.of("charlie"), null);
|
data.setTranslation(new KeyPath("charlie"), null);
|
||||||
|
|
||||||
Assert.assertEquals(6, data.getFullKeys().size());
|
Assert.assertEquals(6, data.getFullKeys().size());
|
||||||
|
|
||||||
Assert.assertNotNull(data.getTranslation(KeyPath.of("alpha.nested.key")));
|
Assert.assertNotNull(data.getTranslation(new KeyPath("alpha.nested.key")));
|
||||||
Assert.assertNotNull(data.getTranslation(KeyPath.of("alpha.other")));
|
Assert.assertNotNull(data.getTranslation(new KeyPath("alpha.other")));
|
||||||
Assert.assertNull(data.getTranslation(KeyPath.of("bravo")));
|
Assert.assertNull(data.getTranslation(new KeyPath("bravo")));
|
||||||
Assert.assertEquals(data.getTranslation(KeyPath.of("alpha.nested")), translation);
|
Assert.assertEquals(data.getTranslation(new KeyPath("alpha.nested")), translation);
|
||||||
Assert.assertEquals(data.getTranslation(KeyPath.of("alpha.other.new")), translation);
|
Assert.assertEquals(data.getTranslation(new KeyPath("alpha.other.new")), translation);
|
||||||
|
|
||||||
Assert.assertNull(data.getTranslation(KeyPath.of("alpha", "nested", "key")));
|
Assert.assertNull(data.getTranslation(new KeyPath("alpha", "nested", "key")));
|
||||||
Assert.assertNull(data.getTranslation(KeyPath.of("alpha", "other")));
|
Assert.assertNull(data.getTranslation(new KeyPath("alpha", "other")));
|
||||||
Assert.assertNull(data.getTranslation(KeyPath.of("charlie")));
|
Assert.assertNull(data.getTranslation(new KeyPath("charlie")));
|
||||||
Assert.assertEquals(data.getTranslation(KeyPath.of("alpha", "nested")), translation);
|
Assert.assertEquals(data.getTranslation(new KeyPath("alpha", "nested")), translation);
|
||||||
Assert.assertEquals(data.getTranslation(KeyPath.of("alpha", "other", "new")), translation);
|
Assert.assertEquals(data.getTranslation(new KeyPath("alpha", "other", "new")), translation);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user