Commit 32d446fa authored by Nugraha, Sigit's avatar Nugraha, Sigit
Browse files

Update multi-language for Instruction

parent 78d9391c
Pipeline #15338 passed with stage
in 2 minutes and 15 seconds
......@@ -385,7 +385,7 @@ public class QuestionnaireEditorView extends VerticalLayout implements View, Tra
I18N.get( "menuItem.ManageInstructions" ),
command ->
{
ManageInterviewerInstructionWindow miiw = new ManageInterviewerInstructionWindow( entityService );
ManageInterviewerInstructionWindow miiw = new ManageInterviewerInstructionWindow( entityService, configurationService );
UI.getCurrent().addWindow( miiw );
} );
......
......@@ -11,6 +11,7 @@ import org.gesis.stardat.entity.DDIElement;
import org.gesis.stardat.entity.Instrument;
import org.gesis.stardat.entity.InterviewerInstruction;
import org.gesis.stardat.helper.TriggerableWindowMaster;
import org.gesis.stardat.service.ConfigurationService;
import org.gesis.stardat.service.EntityCreationService;
import org.gesis.stardat.service.I18N;
import org.gesis.stardat.ui.enumeration.InstructionType;
......@@ -51,7 +52,7 @@ public class InterviewerInstructionForm extends MVerticalLayout
private HashMap<String, String> currentLabels = new HashMap<>();
private List<InterviewerInstruction> currentInstructions = new ArrayList<>();
private final ConfigurationService configService;
private transient EntityCreationService entityService;
private InstructionType instructionType;
......@@ -59,10 +60,12 @@ public class InterviewerInstructionForm extends MVerticalLayout
private MCssLayout mCssButtonLayout = new MCssLayout().withFullWidth().withStyleName("t-a-right");
public InterviewerInstructionForm(
EntityCreationService entityService)
EntityCreationService entityService,
ConfigurationService configService)
{
this.instrument = ((DDIEditor) UI.getCurrent()).getCurrentInstrument();
this.entityService = entityService;
this.configService = configService;
htmlPreview.withContentMode( ContentMode.HTML );
......@@ -174,7 +177,7 @@ public class InterviewerInstructionForm extends MVerticalLayout
if ( instructionGrid.getItem() != null )
{
InstructionWindowTranslate iw = new InstructionWindowTranslate(
instructionGrid.getItem(), this, this.entityService );
instructionGrid.getItem(), this, this.entityService, this.configService );
UI.getCurrent().addWindow( iw );
}
}
......
......@@ -2,6 +2,7 @@ package org.gesis.stardat.ui.view.instruction;
import com.vaadin.ui.ComboBox;
import com.vaadin.ui.Window;
import org.gesis.stardat.service.ConfigurationService;
import org.gesis.stardat.service.EntityCreationService;
import org.gesis.stardat.service.I18N;
import org.gesis.stardat.ui.enumeration.InstructionType;
......@@ -12,10 +13,12 @@ public class ManageInterviewerInstructionWindow extends Window
private static final long serialVersionUID = 4170491295542002073L;
private ComboBox<InstructionType> interviewOptCb = new ComboBox<>( );
private MVerticalLayout verticalLayout = new MVerticalLayout();
private final ConfigurationService configService;
public ManageInterviewerInstructionWindow(EntityCreationService entityService )
public ManageInterviewerInstructionWindow(EntityCreationService entityService, ConfigurationService configService )
{
super( I18N.get("InstructionWindow.caption")); // Set window caption
this.configService = configService;
center();
setWidth( "800px" );
......@@ -26,7 +29,8 @@ public class ManageInterviewerInstructionWindow extends Window
}
private void init(EntityCreationService entityService) {
InterviewerInstructionForm interviewerInstructionForm = new InterviewerInstructionForm( entityService );
InterviewerInstructionForm interviewerInstructionForm = new InterviewerInstructionForm( entityService,
this.configService );
interviewOptCb.setItems( InstructionType.INTERVIEWER, InstructionType.RESPONDENT, InstructionType.PROGRAMMER);
interviewOptCb.setItemCaptionGenerator( interview -> I18N.get(interview.getNotationKey()));
......
......@@ -3,14 +3,16 @@ package org.gesis.stardat.ui.windows;
import com.vaadin.ui.ComboBox;
import com.vaadin.ui.TextArea;
import com.vaadin.ui.TextField;
import org.gesis.stardat.config.Constants;
import org.gesis.stardat.domain.enumeration.Language;
import org.gesis.stardat.entity.DDIElement;
import org.gesis.stardat.entity.InterviewerInstruction;
import org.gesis.stardat.helper.TriggerableWindowMaster;
import org.gesis.stardat.service.ConfigurationService;
import org.gesis.stardat.service.EntityCreationService;
import org.gesis.stardat.service.I18N;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
public class InstructionWindowTranslate extends BaseStoreCancelWindow
......@@ -22,14 +24,16 @@ public class InstructionWindowTranslate extends BaseStoreCancelWindow
private static final long serialVersionUID = -5463182606257793391L;
public static final String GOAL = "editInstruction";
private ComboBox<Language> languageComboBox = new ComboBox<Language>(I18N.get( "checkbox.language" ));
private ComboBox<Language> languageComboBox = new ComboBox<>(I18N.get( "checkbox.language" ));
private TextField nameField;
private TextField nameFieldTranslate;
private TextField nameFieldTranslate = new TextField( I18N.get( windowName + ".name.translate" ) );
private TextArea textField;
private TextArea textFieldTranslate;
private TextArea textFieldTranslate = new TextArea( I18N.get( windowName + ".textField.translate" ) );
private TextArea descriptionField;
private TextArea descriptionFieldTranslate;
private TextArea descriptionFieldTranslate = new TextArea(I18N.get( windowName + ".descriptionField.translate" ) );
private final ConfigurationService configService;
private InterviewerInstruction instruction;
......@@ -38,11 +42,13 @@ public class InstructionWindowTranslate extends BaseStoreCancelWindow
private EntityCreationService entityService;
public InstructionWindowTranslate( InterviewerInstruction instruction,
TriggerableWindowMaster interviewerInstructionForm, EntityCreationService entityService )
TriggerableWindowMaster interviewerInstructionForm, EntityCreationService entityService,
ConfigurationService configService)
{
super( "InstructionWindow" );
setWidth( "1024px" );
setHeight( "800px" );
this.configService = configService;
this.instruction = instruction;
this.master = interviewerInstructionForm;
......@@ -55,10 +61,28 @@ public class InstructionWindowTranslate extends BaseStoreCancelWindow
{
setCaption( I18N.get("InstructionWindowTranslate.title"));
languageComboBox.setItems(Language.ENGLISH);
final String sourceLanguage = instruction.getLanguage();
final ArrayList<String> translatedLanguages = instruction.getAvailableLanguages();
final List<Language> enableLanguagesByIso3 = configService.getEnableLanguagesByIso3();
enableLanguagesByIso3.remove(Language.getByIso3(sourceLanguage));
languageComboBox.setCaption(I18N.get( "checkbox.language" ));
languageComboBox.setItemCaptionGenerator( l -> translatedLanguages.contains( l.getIso3() ) ? l.getFormatted() + " - translated" : l.getFormatted() );
languageComboBox.setWidth("240px");
languageComboBox.setItems(enableLanguagesByIso3);
languageComboBox.setTextInputAllowed( false );
languageComboBox.setSelectedItem(Language.ENGLISH);
languageComboBox.setEmptySelectionAllowed( false );
if(!enableLanguagesByIso3.isEmpty()){
languageComboBox.setSelectedItem(enableLanguagesByIso3.get(0));
updateFormLabels( enableLanguagesByIso3.get(0).getIso3());
fillComponents( enableLanguagesByIso3.get(0).getIso3() );
}
languageComboBox.addSelectionListener(event -> {
updateFormLabels( event.getValue().getIso());
fillComponents( event.getValue().getIso3() );
});
getContentLayout().addComponent(languageComboBox);
......@@ -67,7 +91,6 @@ public class InstructionWindowTranslate extends BaseStoreCancelWindow
nameField.setReadOnly( true );
getContentLayout().addComponent( nameField );
nameFieldTranslate = new TextField( "Name (en)" );
getContentLayout().addComponent( nameFieldTranslate );
textField = new TextArea( I18N.get( windowName + ".textField" ) );
......@@ -75,7 +98,6 @@ public class InstructionWindowTranslate extends BaseStoreCancelWindow
textField.setReadOnly( true );
getContentLayout().addComponent( textField );
textFieldTranslate = new TextArea( I18N.get( windowName + ".textField" + ".translate" ) );
getContentLayout().addComponent( textFieldTranslate );
descriptionField = new TextArea(I18N.get( windowName + ".descriptionField" ) );
......@@ -83,28 +105,31 @@ public class InstructionWindowTranslate extends BaseStoreCancelWindow
descriptionField.setReadOnly( true );
getContentLayout().addComponent( descriptionField );
descriptionFieldTranslate = new TextArea(I18N.get( windowName + ".descriptionField"+".translate" ) );
getContentLayout().addComponent( descriptionFieldTranslate );
languageComboBox.addSelectionListener(event -> {
nameFieldTranslate.setCaption("Name "+ "("+languageComboBox.getSelectedItem().get().getIso()+")");
textFieldTranslate.setCaption("Anweisung "+ "("+languageComboBox.getSelectedItem().get().getIso()+")");
descriptionFieldTranslate.setCaption("Beschreibung "+ "("+languageComboBox.getSelectedItem().get().getIso()+")");
});
}
private void updateFormLabels( String langIso ) {
nameFieldTranslate.setCaption(I18N.get("InstructionWindow.textField.name") + " ("+langIso +")");
textFieldTranslate.setCaption(I18N.get("InstructionWindow.textField.translate") + " ("+langIso+")");
descriptionFieldTranslate.setCaption(I18N.get("InstructionWindow.descriptionField.translate") + " ("+langIso+")");
}
private void fillComponents( String langIso3 )
{
final String SOURCE_LANG = instruction.getLanguage();
instruction.setLanguage( Constants.ENGLISH_LANGUAGE );
instruction.setLanguage( langIso3 );
nameFieldTranslate.setValue( instruction.getLabel() );
textFieldTranslate.setValue( instruction.getInstruction() );
descriptionFieldTranslate.setValue( instruction.getDescription() );
instruction.setLanguage( SOURCE_LANG );
}
@Override
protected boolean store()
{
final String SOURCE_LANG = instruction.getLanguage();
instruction.setLanguage( Constants.ENGLISH_LANGUAGE );
instruction.setLanguage( languageComboBox.getValue().getIso3() );
instruction.setLabel( nameFieldTranslate.getValue() );
instruction.setInstruction( textFieldTranslate.getValue() );
instruction.setDescription( descriptionFieldTranslate.getValue() );
......
......@@ -506,6 +506,7 @@ InstructionWindow.comment = Bearbeitungsgrund
InstructionWindowTranslate.title = Intervieweranweisung übersetzen
InstructionWindow.textField.translate = Anweisung (en)
InstructionWindow.descriptionField.translate = Beschreibung (en)
InstructionWindow.textField.name = Name
InstructionWindow.comment.translate = Bearbeitungsgrund (en)
InstructionWindowProgramming.title = Programmieranweisung bearbeiten
......
......@@ -494,9 +494,10 @@ InstructionWindow.textField = Instruction
InstructionWindow.descriptionField = Description
InstructionWindow.comment = Edit reason
InstructionWindowTranslate.title = Translate interview-instruction
InstructionWindow.textField.translate = Instruction (en)
InstructionWindow.descriptionField.translate = Description (en)
InstructionWindow.comment.translate = Edit reason (en)
InstructionWindow.textField.name = Name
InstructionWindow.textField.translate = Instruction
InstructionWindow.descriptionField.translate = Description
InstructionWindow.comment.translate = Edit reason
InstructionWindowProgramming.title = Edit Programming-instruction
InstructionWindowProgramming.store = Save Instruction
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment