remove description for now

This commit is contained in:
marhali 2022-04-11 22:07:45 +02:00
parent c348ea7d78
commit 6887a4e416
2 changed files with 25 additions and 93 deletions

View File

@ -37,7 +37,6 @@ abstract class TranslationDialog {
protected final @NotNull Translation origin;
protected final JTextField keyField;
protected final JTextField descriptionField;
protected final Map<String, JTextField> localeValueFields;
/**
@ -55,7 +54,6 @@ abstract class TranslationDialog {
TranslationValue value = origin.getValue();
this.keyField = new JBTextField(converter.toString(origin.getKey()));
this.descriptionField = new JBTextField(value != null ? value.getDescription() : null);
this.localeValueFields = new HashMap<>();
for(String locale : InstanceManager.get(project).store().getData().getLocales()) {
@ -92,9 +90,8 @@ abstract class TranslationDialog {
*/
protected @NotNull Translation getState() {
KeyPath key = converter.fromString(keyField.getText());
TranslationValue value = new TranslationValue();
value.setDescription(descriptionField.getText());
TranslationValue value = new TranslationValue();
for(Map.Entry<String, JTextField> entry : localeValueFields.entrySet()) {
value.put(entry.getKey(), entry.getValue().getText());
@ -106,7 +103,6 @@ abstract class TranslationDialog {
private DialogBuilder createDialog() {
JPanel panel = FormBuilder.createFormBuilder()
.addLabeledComponent(bundle.getString("translation.key"), keyField, true)
.addLabeledComponent(bundle.getString("translation.description"), descriptionField, 6, true)
.addComponent(createLocalesPanel(), 12)
.getPanel();

View File

@ -6,6 +6,7 @@ import org.jetbrains.annotations.Nullable;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
/**
* Represents the set values behind a specific translation.
@ -13,122 +14,57 @@ import java.util.Map;
*/
public class TranslationValue {
private @Nullable String description;
private @NotNull Map<String, String> values;
private @Nullable Object misc;
public TranslationValue(@Nullable String description, @NotNull Map<String, String> values, @Nullable Object misc) {
this.description = description;
this.values = values;
this.misc = misc;
}
public TranslationValue(@NotNull Map<String, String> values) {
this(null, values, null);
}
public TranslationValue(@NotNull String locale, @NotNull String value) {
this(new HashMap<>(Map.of(locale, value)));
}
private @NotNull Map<String, String> localeValues;
public TranslationValue() {
this(null, new HashMap<>(), null);
this.localeValues = new HashMap<>();
}
/**
* Retrieve additional description for this translation
* @return Description
*/
public @Nullable String getDescription() {
return description;
public TranslationValue(@NotNull String locale, @NotNull String content) {
this();
localeValues.put(locale, content);
}
/**
* Override or set description for this translation
* @param description Description
*/
public void setDescription(@Nullable String description) {
this.description = description;
public Set<Map.Entry<String, String>> getEntries() {
return this.localeValues.entrySet();
}
/**
* Set locale specific values.
* @param values New values
*/
public void setValues(@NotNull Map<String, String> values) {
this.values = values;
public Collection<String> getLocaleContents() {
return this.localeValues.values();
}
public @NotNull Map<String, String> getValues() {
return values;
public void setLocaleValues(@NotNull Map<String, String> localeValues) {
this.localeValues = localeValues;
}
/**
* Overrides or sets a value for a specific locale.
* @param locale Locale type
* @param value New value
*/
public void put(@NotNull String locale, @Nullable String value) {
if(value == null) { // Delete operation
values.remove(locale);
} else {
values.put(locale, value);
}
}
public void remove(String locale) {
values.remove(locale);
}
/**
* Retrieves the associated value for a specific locale
* @param locale Locale type
* @return Value or null if missing
*/
public @Nullable String get(@NotNull String locale) {
return values.get(locale);
return this.localeValues.get(locale);
}
public boolean containsLocale(@Nullable String locale) {
return values.containsKey(locale);
public void put(@NotNull String locale, @NotNull String content) {
this.localeValues.put(locale, content);
}
public @NotNull Collection<String> getLocaleValues() {
return values.values();
public void remove(@NotNull String locale) {
this.localeValues.remove(locale);
}
public boolean containsLocale(@NotNull String locale) {
return this.localeValues.containsKey(locale);
}
public int size() {
return values.size();
return this.localeValues.size();
}
public void clear() {
description = null;
values.clear();
misc = null;
}
/**
* I18n support data
* @return Data
*/
public @Nullable Object getMisc() {
return misc;
}
/**
* Set or update I18n support data
* @param misc New Data
*/
public void setMisc(@Nullable Object misc) {
this.misc = misc;
this.localeValues.clear();
}
@Override
public String toString() {
return "TranslationValue{" +
"description='" + description + '\'' +
", values=" + values +
", misc=" + misc +
"localeValues=" + localeValues +
'}';
}
}