Add i18n flavor template setting
A new setting, `flavorTemplate` is introduced to specify how strings are replaced with i18n representation. This includes code modifications for handling this new feature and also updates in the messages.properties file for the associated UI text. The feature is especially useful for customizing how localization strings are generated in different project setups.
This commit is contained in:
parent
352dc7c47c
commit
a709db810e
@ -33,4 +33,5 @@ public interface ProjectSettings {
|
|||||||
|
|
||||||
// Experimental Configuration
|
// Experimental Configuration
|
||||||
boolean isAlwaysFold();
|
boolean isAlwaysFold();
|
||||||
|
String getFlavorTemplate();
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,7 @@ import java.util.ResourceBundle;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Configuration panel with all possible options for this plugin.
|
* Configuration panel with all possible options for this plugin.
|
||||||
|
*
|
||||||
* @author marhali
|
* @author marhali
|
||||||
*/
|
*/
|
||||||
public class ProjectSettingsComponent extends ProjectSettingsComponentState {
|
public class ProjectSettingsComponent extends ProjectSettingsComponentState {
|
||||||
@ -64,10 +65,12 @@ public class ProjectSettingsComponent extends ProjectSettingsComponentState {
|
|||||||
.addVerticalGap(24)
|
.addVerticalGap(24)
|
||||||
.addComponent(new TitledSeparator(bundle.getString("settings.experimental.title")))
|
.addComponent(new TitledSeparator(bundle.getString("settings.experimental.title")))
|
||||||
.addComponent(constructAlwaysFoldField())
|
.addComponent(constructAlwaysFoldField())
|
||||||
|
.addLabeledComponent(bundle.getString("settings.experimental.flavor-template"), constructFlavorTemplate(), 1, false)
|
||||||
.addComponentFillVertically(new JPanel(), 0)
|
.addComponentFillVertically(new JPanel(), 0)
|
||||||
.getPanel();
|
.getPanel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private JComponent constructPresetField() {
|
private JComponent constructPresetField() {
|
||||||
preset = new ComboBox<>(Preset.values());
|
preset = new ComboBox<>(Preset.values());
|
||||||
preset.setToolTipText(bundle.getString("settings.preset.tooltip"));
|
preset.setToolTipText(bundle.getString("settings.preset.tooltip"));
|
||||||
@ -219,6 +222,12 @@ public class ProjectSettingsComponent extends ProjectSettingsComponentState {
|
|||||||
return alwaysFold;
|
return alwaysFold;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private JComponent constructFlavorTemplate() {
|
||||||
|
flavorTemplate = new ExtendableTextField(20);
|
||||||
|
flavorTemplate.setToolTipText(bundle.getString("settings.experimental.flavor-template-tooltip"));
|
||||||
|
return flavorTemplate;
|
||||||
|
}
|
||||||
|
|
||||||
private ItemListener handleParserChange() {
|
private ItemListener handleParserChange() {
|
||||||
return e -> {
|
return e -> {
|
||||||
if (e.getStateChange() == ItemEvent.SELECTED) {
|
if (e.getStateChange() == ItemEvent.SELECTED) {
|
||||||
|
@ -40,6 +40,8 @@ public class ProjectSettingsComponentState {
|
|||||||
// Experimental configuration
|
// Experimental configuration
|
||||||
protected JCheckBox alwaysFold;
|
protected JCheckBox alwaysFold;
|
||||||
|
|
||||||
|
protected JTextField flavorTemplate;
|
||||||
|
|
||||||
protected ProjectSettingsState getState() {
|
protected ProjectSettingsState getState() {
|
||||||
// Every field needs to provide its state
|
// Every field needs to provide its state
|
||||||
ProjectSettingsState state = new ProjectSettingsState();
|
ProjectSettingsState state = new ProjectSettingsState();
|
||||||
@ -63,6 +65,7 @@ public class ProjectSettingsComponentState {
|
|||||||
state.setAssistance(assistance.isSelected());
|
state.setAssistance(assistance.isSelected());
|
||||||
|
|
||||||
state.setAlwaysFold(alwaysFold.isSelected());
|
state.setAlwaysFold(alwaysFold.isSelected());
|
||||||
|
state.setFlavorTemplate(flavorTemplate.getText());
|
||||||
|
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
@ -88,5 +91,7 @@ public class ProjectSettingsComponentState {
|
|||||||
assistance.setSelected(state.isAssistance());
|
assistance.setSelected(state.isAssistance());
|
||||||
|
|
||||||
alwaysFold.setSelected(state.isAlwaysFold());
|
alwaysFold.setSelected(state.isAlwaysFold());
|
||||||
|
|
||||||
|
flavorTemplate.setText(state.getFlavorTemplate());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,7 @@ public class ProjectSettingsState implements ProjectSettings {
|
|||||||
|
|
||||||
// Experimental configuration
|
// Experimental configuration
|
||||||
@Property private Boolean alwaysFold;
|
@Property private Boolean alwaysFold;
|
||||||
|
@Property private String flavorTemplate;
|
||||||
|
|
||||||
public ProjectSettingsState() {
|
public ProjectSettingsState() {
|
||||||
this(new DefaultPreset());
|
this(new DefaultPreset());
|
||||||
@ -65,6 +66,7 @@ public class ProjectSettingsState implements ProjectSettings {
|
|||||||
this.assistance = defaults.isAssistance();
|
this.assistance = defaults.isAssistance();
|
||||||
|
|
||||||
this.alwaysFold = defaults.isAlwaysFold();
|
this.alwaysFold = defaults.isAlwaysFold();
|
||||||
|
this.flavorTemplate = defaults.getFlavorTemplate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -143,6 +145,11 @@ public class ProjectSettingsState implements ProjectSettings {
|
|||||||
return alwaysFold;
|
return alwaysFold;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getFlavorTemplate() {
|
||||||
|
return this.flavorTemplate;
|
||||||
|
}
|
||||||
|
|
||||||
public void setLocalesDirectory(String localesDirectory) {
|
public void setLocalesDirectory(String localesDirectory) {
|
||||||
this.localesDirectory = localesDirectory;
|
this.localesDirectory = localesDirectory;
|
||||||
}
|
}
|
||||||
@ -202,6 +209,9 @@ public class ProjectSettingsState implements ProjectSettings {
|
|||||||
public void setAlwaysFold(Boolean alwaysFold) {
|
public void setAlwaysFold(Boolean alwaysFold) {
|
||||||
this.alwaysFold = alwaysFold;
|
this.alwaysFold = alwaysFold;
|
||||||
}
|
}
|
||||||
|
public void setFlavorTemplate(String flavorTemplate){
|
||||||
|
this.flavorTemplate = flavorTemplate;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
@ -222,7 +232,8 @@ public class ProjectSettingsState implements ProjectSettings {
|
|||||||
&& Objects.equals(previewLocale, that.previewLocale)
|
&& Objects.equals(previewLocale, that.previewLocale)
|
||||||
&& Objects.equals(nestedKeys, that.nestedKeys)
|
&& Objects.equals(nestedKeys, that.nestedKeys)
|
||||||
&& Objects.equals(assistance, that.assistance)
|
&& Objects.equals(assistance, that.assistance)
|
||||||
&& Objects.equals(alwaysFold, that.alwaysFold);
|
&& Objects.equals(alwaysFold, that.alwaysFold)
|
||||||
|
&& Objects.equals(flavorTemplate,that.flavorTemplate);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -230,7 +241,7 @@ public class ProjectSettingsState implements ProjectSettings {
|
|||||||
return Objects.hash(
|
return Objects.hash(
|
||||||
localesDirectory, folderStrategy, parserStrategy, filePattern, includeSubDirs,
|
localesDirectory, folderStrategy, parserStrategy, filePattern, includeSubDirs,
|
||||||
sorting, namespaceDelimiter, sectionDelimiter, contextDelimiter, pluralDelimiter,
|
sorting, namespaceDelimiter, sectionDelimiter, contextDelimiter, pluralDelimiter,
|
||||||
defaultNamespace, previewLocale, nestedKeys, assistance, alwaysFold
|
defaultNamespace, previewLocale, nestedKeys, assistance, alwaysFold,flavorTemplate
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -252,6 +263,7 @@ public class ProjectSettingsState implements ProjectSettings {
|
|||||||
", nestedKeys=" + nestedKeys +
|
", nestedKeys=" + nestedKeys +
|
||||||
", assistance=" + assistance +
|
", assistance=" + assistance +
|
||||||
", alwaysFold=" + alwaysFold +
|
", alwaysFold=" + alwaysFold +
|
||||||
|
", flavorTemplate=" + flavorTemplate +
|
||||||
'}';
|
'}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -86,4 +86,9 @@ public class ReactI18NextPreset implements ProjectSettings {
|
|||||||
public boolean isAlwaysFold() {
|
public boolean isAlwaysFold() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getFlavorTemplate() {
|
||||||
|
return "$i18n.t";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -85,4 +85,9 @@ public class VueI18nPreset implements ProjectSettings {
|
|||||||
public boolean isAlwaysFold() {
|
public boolean isAlwaysFold() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getFlavorTemplate() {
|
||||||
|
return "$i18n.t";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,6 +60,8 @@ settings.editor.assistance.tooltip=Activates editor support to reference, auto-c
|
|||||||
settings.experimental.title=Experimental Configuration
|
settings.experimental.title=Experimental Configuration
|
||||||
settings.experimental.always-fold.title=Always fold translation keys
|
settings.experimental.always-fold.title=Always fold translation keys
|
||||||
settings.experimental.always-fold.tooltip=Forces the editor to always display the value behind a translation key. The value cannot be unfolded when this function is active.
|
settings.experimental.always-fold.tooltip=Forces the editor to always display the value behind a translation key. The value cannot be unfolded when this function is active.
|
||||||
|
settings.experimental.flavor-template =I18n flavor template
|
||||||
|
settings.experimental.flavor-template-tooltip = Specify How to replace strings with i18n representation.
|
||||||
error.io=An error occurred while processing translation files. \n\
|
error.io=An error occurred while processing translation files. \n\
|
||||||
Config: {0} => {1} ({2}) \n\
|
Config: {0} => {1} ({2}) \n\
|
||||||
Path: {3} \n\
|
Path: {3} \n\
|
||||||
|
Loading…
x
Reference in New Issue
Block a user