From 5ad5f1b82763facacc1453bf87ba50c592f4e3b0 Mon Sep 17 00:00:00 2001 From: Peter Hormanns Date: Thu, 20 Jul 2017 19:17:50 +0200 Subject: [PATCH] fix i18n issue --- .../java/de/hsadmin/rpc/HSAdminSession.java | 3 ++ .../java/de/hsadmin/web/CustomerPanel.java | 13 +++++---- .../de/hsadmin/web/DomainOptionsEditor.java | 7 +++-- .../main/java/de/hsadmin/web/DomainPanel.java | 5 ++-- .../de/hsadmin/web/EMailTargetEditor.java | 20 +++++++------ .../de/hsadmin/web/EntryPointsSelector.java | 3 +- .../java/de/hsadmin/web/FactoryProducer.java | 4 +-- .../de/hsadmin/web/GenericEditorFactory.java | 25 ++++++++++------ .../main/java/de/hsadmin/web/GenericForm.java | 2 +- .../de/hsadmin/web/GenericFormWindow.java | 5 ++-- .../main/java/de/hsadmin/web/HSAdminUI.java | 12 ++++++++ .../java/de/hsadmin/web/HSConfirmBox.java | 2 +- .../java/de/hsadmin/web/HSDateSelect.java | 4 +-- .../de/hsadmin/web/HSPacPrefixedField.java | 4 +-- .../java/de/hsadmin/web/HSPasswordField.java | 4 +-- .../main/java/de/hsadmin/web/HSSelect.java | 4 +-- web/src/main/java/de/hsadmin/web/HSTab.java | 3 +- .../main/java/de/hsadmin/web/HSTextField.java | 4 +-- .../main/java/de/hsadmin/web/HelpWindow.java | 4 +-- web/src/main/java/de/hsadmin/web/I18N.java | 29 ++++++++++--------- .../main/java/de/hsadmin/web/IHSEditor.java | 2 +- .../main/java/de/hsadmin/web/LoginWindow.java | 17 +++++------ .../main/java/de/hsadmin/web/MainPanel.java | 6 ++-- .../main/java/de/hsadmin/web/MainToolbar.java | 2 +- .../main/java/de/hsadmin/web/MainWindow.java | 9 +++++- .../java/de/hsadmin/web/PackagePanel.java | 16 +++++----- .../java/de/hsadmin/web/PanelToolbar.java | 4 +-- .../java/de/hsadmin/web/SubWindowFactory.java | 2 +- .../de/hsadmin/web/UserProfileWindow.java | 4 +-- 29 files changed, 127 insertions(+), 92 deletions(-) diff --git a/web/src/main/java/de/hsadmin/rpc/HSAdminSession.java b/web/src/main/java/de/hsadmin/rpc/HSAdminSession.java index 03e9f5a..7323095 100644 --- a/web/src/main/java/de/hsadmin/rpc/HSAdminSession.java +++ b/web/src/main/java/de/hsadmin/rpc/HSAdminSession.java @@ -1,6 +1,7 @@ package de.hsadmin.rpc; import de.hsadmin.model.TicketService; +import de.hsadmin.web.I18N; public interface HSAdminSession { @@ -12,4 +13,6 @@ public interface HSAdminSession { public String getUser(); + public I18N getI18N(); + } diff --git a/web/src/main/java/de/hsadmin/web/CustomerPanel.java b/web/src/main/java/de/hsadmin/web/CustomerPanel.java index 9104864..5b356a5 100644 --- a/web/src/main/java/de/hsadmin/web/CustomerPanel.java +++ b/web/src/main/java/de/hsadmin/web/CustomerPanel.java @@ -29,31 +29,32 @@ public class CustomerPanel extends CustomComponent implements IHSPanel, Selected @Override public TabSheet createTabs(Object itemId) throws RpcException { + final I18N i18n = session.getI18N(); final TabSheet tabsheet = new TabSheet(); tabsheet.setSizeFull(); tabsheet.addSelectedTabChangeListener(this); tabsheet.addSelectedTabChangeListener(this); - tabsheet.addTab(new GenericForm("customer", session, itemId, "name"), I18N.getText("customer")); + tabsheet.addTab(new GenericForm("customer", session, itemId, "name"), i18n.getText("customer")); final HSTab usersTab = new HSTab("contact", session, "customer", itemId, "email"); usersTab.fillTable(); - tabsheet.addTab(usersTab, I18N.getText("contact")); + tabsheet.addTab(usersTab, i18n.getText("contact")); final HSTab aliasTab = new HSTab("mandat", session, "customer", itemId, "mandatRef"); - tabsheet.addTab(aliasTab, I18N.getText("mandat")); + tabsheet.addTab(aliasTab, i18n.getText("mandat")); final HSTab assetsTab = new HSTab("memberShare", session, "customer", itemId, "id"); assetsTab.getPanelToolbar().setUpdateEnabled(false); assetsTab.getPanelToolbar().setDeleteEnabled(false); - tabsheet.addTab(assetsTab, I18N.getText("memberShare")); + tabsheet.addTab(assetsTab, i18n.getText("memberShare")); final HSTab assetsTab1 = new HSTab("memberAsset", session, "customer", itemId, "id"); assetsTab1.getPanelToolbar().setUpdateEnabled(false); assetsTab1.getPanelToolbar().setDeleteEnabled(false); - tabsheet.addTab(assetsTab1, I18N.getText("memberAsset")); + tabsheet.addTab(assetsTab1, i18n.getText("memberAsset")); final HSTab pacTab = new HSTab("pac", session, "customer", itemId, "name"); - tabsheet.addTab(pacTab, I18N.getText("pac")); + tabsheet.addTab(pacTab, i18n.getText("pac")); return tabsheet; } diff --git a/web/src/main/java/de/hsadmin/web/DomainOptionsEditor.java b/web/src/main/java/de/hsadmin/web/DomainOptionsEditor.java index 7b37388..da1ee21 100644 --- a/web/src/main/java/de/hsadmin/web/DomainOptionsEditor.java +++ b/web/src/main/java/de/hsadmin/web/DomainOptionsEditor.java @@ -27,14 +27,15 @@ public class DomainOptionsEditor extends CustomComponent implements IHSEditor { public DomainOptionsEditor(final PropertyInfo propertyInfo, final HSAdminSession session, final Map whereContext) { this.checkboxes = new HashMap<>(); this.propertyInfo = propertyInfo; - this.setCaption(I18N.getText(propertyInfo.getName())); + final I18N i18n = session.getI18N(); + this.setCaption(i18n.getText(propertyInfo.getName())); layout = new VerticalLayout(); for (String opt : OPTIONS) { - final CheckBox checkBox = new CheckBox(I18N.getText("domainoption." + opt)); + final CheckBox checkBox = new CheckBox(i18n.getText("domainoption." + opt)); checkboxes.put(opt, checkBox); layout.addComponent(checkBox); } - layout.setCaption(I18N.getText(propertyInfo.getName())); + layout.setCaption(i18n.getText(propertyInfo.getName())); setCompositionRoot(layout); } diff --git a/web/src/main/java/de/hsadmin/web/DomainPanel.java b/web/src/main/java/de/hsadmin/web/DomainPanel.java index c352dab..607fecf 100644 --- a/web/src/main/java/de/hsadmin/web/DomainPanel.java +++ b/web/src/main/java/de/hsadmin/web/DomainPanel.java @@ -29,11 +29,12 @@ public class DomainPanel extends CustomComponent implements IHSPanel, SelectedTa @Override public TabSheet createTabs(Object itemId) throws RpcException { + final I18N i18n = session.getI18N(); final TabSheet tabsheet = new TabSheet(); - tabsheet.addTab(new GenericForm("domain", session, itemId, "name"), I18N.getText("domain")); + tabsheet.addTab(new GenericForm("domain", session, itemId, "name"), i18n.getText("domain")); HSTab emailTab = new HSTab("emailaddress", session, "domain", itemId, "id"); emailTab.fillTable(); - tabsheet.addTab(emailTab, I18N.getText("emailaddress")); + tabsheet.addTab(emailTab, i18n.getText("emailaddress")); return tabsheet; } diff --git a/web/src/main/java/de/hsadmin/web/EMailTargetEditor.java b/web/src/main/java/de/hsadmin/web/EMailTargetEditor.java index 150fad9..385dda1 100644 --- a/web/src/main/java/de/hsadmin/web/EMailTargetEditor.java +++ b/web/src/main/java/de/hsadmin/web/EMailTargetEditor.java @@ -38,18 +38,20 @@ public class EMailTargetEditor extends CustomComponent implements IHSEditor, Val private final AbstractOrderedLayout layout; private final List aliases; private final List postboxes; + private final I18N i18n; public EMailTargetEditor(final String action, final PropertyInfo propertyInfo, final HSAdminSession session, final Map whereContext) { + this.i18n = session.getI18N(); this.isEditAble = PanelToolbar.ACTION_EDIT.equals(action) || PanelToolbar.ACTION_NEW.equals(action); this.propertyInfo = propertyInfo; this.validators = new ArrayList<>(); - this.setCaption(I18N.getText(propertyInfo.getName())); + this.setCaption(i18n.getText(propertyInfo.getName())); this.aliases = targetsSelect("emailalias", session, whereContext); this.postboxes = targetsSelect("user", session, whereContext); postboxes.removeAll(aliases); layout = new VerticalLayout(); - layout.setCaption(I18N.getText(propertyInfo.getName())); + layout.setCaption(i18n.getText(propertyInfo.getName())); setCompositionRoot(layout); } @@ -175,7 +177,7 @@ public class EMailTargetEditor extends CustomComponent implements IHSEditor, Val targetTypeSelect.setMultiSelect(false); targetTypeSelect.setNullSelectionAllowed(true); targetTypeSelect.setNullSelectionItemId(" "); - targetTypeSelect.addItems(new Object[] { " ", I18N.getText("emailtarget.email"), I18N.getText("emailtarget.postbox"), I18N.getText("emailtarget.alias") }); + targetTypeSelect.addItems(new Object[] { " ", i18n.getText("emailtarget.email"), i18n.getText("emailtarget.postbox"), i18n.getText("emailtarget.alias") }); targetTypeSelect.setValue(" "); targetTypeSelect.setWidth("6.0em"); addComponent(targetTypeSelect); @@ -184,7 +186,7 @@ public class EMailTargetEditor extends CustomComponent implements IHSEditor, Val AbstractComponent targetField = null; NativeSelect sel = null; if (aliases.contains(target)) { - targetTypeSelect.setValue(I18N.getText("emailtarget.alias")); + targetTypeSelect.setValue(i18n.getText("emailtarget.alias")); sel = new NativeSelect(); sel.addItems(aliases); sel.setValue(target); @@ -193,7 +195,7 @@ public class EMailTargetEditor extends CustomComponent implements IHSEditor, Val targetField = sel; } else { if (postboxes.contains(target)) { - targetTypeSelect.setValue(I18N.getText("emailtarget.postbox")); + targetTypeSelect.setValue(i18n.getText("emailtarget.postbox")); sel = new NativeSelect(); sel.addItems(postboxes); sel.setValue(target); @@ -201,7 +203,7 @@ public class EMailTargetEditor extends CustomComponent implements IHSEditor, Val sel.setEnabled(isEditAble); targetField = sel; } else { - targetTypeSelect.setValue(I18N.getText("emailtarget.email")); + targetTypeSelect.setValue(i18n.getText("emailtarget.email")); targetField = new TextField(); targetField.setEnabled(isEditAble); ((TextField) targetField).setValue(target); @@ -229,16 +231,16 @@ public class EMailTargetEditor extends CustomComponent implements IHSEditor, Val final String newValue = newValueObject.toString(); if (targetRow.getComponentCount() == 1) { AbstractComponent comp = null; - if (I18N.getText("emailtarget.email").equals(newValue)) { + if (i18n.getText("emailtarget.email").equals(newValue)) { final TextField textField = new TextField(); textField.addValueChangeListener(editor); textField.setImmediate(true); textField.setEnabled(isEditAble); comp = textField; } else { - if (I18N.getText("emailtarget.alias").equals(newValue) || I18N.getText("emailtarget.postbox").equals(newValue)) { + if (i18n.getText("emailtarget.alias").equals(newValue) || i18n.getText("emailtarget.postbox").equals(newValue)) { final NativeSelect select = new NativeSelect(); - if (I18N.getText("emailtarget.alias").equals(newValue)) { + if (i18n.getText("emailtarget.alias").equals(newValue)) { select.addItems(aliases); } else { select.addItems(postboxes); diff --git a/web/src/main/java/de/hsadmin/web/EntryPointsSelector.java b/web/src/main/java/de/hsadmin/web/EntryPointsSelector.java index db7918f..c7b6f35 100644 --- a/web/src/main/java/de/hsadmin/web/EntryPointsSelector.java +++ b/web/src/main/java/de/hsadmin/web/EntryPointsSelector.java @@ -24,6 +24,7 @@ import de.hsadmin.rpc.RpcException; public class EntryPointsSelector extends CustomComponent implements ItemClickListener, SelectedTabChangeListener { private static final long serialVersionUID = 1L; + private final MainWindow mainWindow; private Accordion accordion; @@ -45,7 +46,7 @@ public class EntryPointsSelector extends CustomComponent implements ItemClickLis final AbstractEntryPointsFactory entryPointsFactory = FactoryProducer.getEntryPointsFactory(mainWindow, "default"); int tabCount = 0; for(String tabName : entryPointsFactory.getEntryPointNames(role)) { - accordion.addTab(new EntryPoint(this, tabName), I18N.getText(tabName)); + accordion.addTab(new EntryPoint(this, tabName), mainWindow.getI18N().getText(tabName)); tabCount++; } if (tabCount > 0) { diff --git a/web/src/main/java/de/hsadmin/web/FactoryProducer.java b/web/src/main/java/de/hsadmin/web/FactoryProducer.java index 7c52cea..7c4d20e 100644 --- a/web/src/main/java/de/hsadmin/web/FactoryProducer.java +++ b/web/src/main/java/de/hsadmin/web/FactoryProducer.java @@ -13,9 +13,9 @@ public class FactoryProducer { return new SubWindowFactory(); } - public static IEditorFactory getEditorFactory(String choice) + public static IEditorFactory getEditorFactory(I18N i18n, String choice) { - return new GenericEditorFactory(); + return new GenericEditorFactory(i18n); } public static AbstractEntryPointsFactory getEntryPointsFactory(MainWindow window, String choice) { diff --git a/web/src/main/java/de/hsadmin/web/GenericEditorFactory.java b/web/src/main/java/de/hsadmin/web/GenericEditorFactory.java index 3ad2026..724138d 100644 --- a/web/src/main/java/de/hsadmin/web/GenericEditorFactory.java +++ b/web/src/main/java/de/hsadmin/web/GenericEditorFactory.java @@ -21,6 +21,13 @@ import de.hsadmin.rpc.enums.ReadWritePolicy; public class GenericEditorFactory implements IEditorFactory, Serializable { private static final long serialVersionUID = 1L; + + private final I18N i18n; + + public GenericEditorFactory(I18N i18n) { + this.i18n = i18n; + } + @Override public IHSEditor getEditor(final String action, final PropertyInfo propertyInfo, final HSAdminSession session, final Map whereContext) @@ -79,7 +86,7 @@ public class GenericEditorFactory implements IEditorFactory, Serializable { private IHSEditor getMemberShareActionEditor(String action, PropertyInfo propertyInfo, HSAdminSession session, Map whereContext) { final String[] items = new String[] { "SUBSCRIPTION", "UNSUBSCRIPTION" }; - final HSSelect field = new HSSelect(propertyInfo, 0, Arrays.asList(items)); + final HSSelect field = new HSSelect(session.getI18N(), propertyInfo, 0, Arrays.asList(items)); field.setWidth("100%"); field.setEnabled(isWriteAble(propertyInfo, action)); return field; @@ -87,7 +94,7 @@ public class GenericEditorFactory implements IEditorFactory, Serializable { private IHSEditor getMemberAssetActionEditor(String action, PropertyInfo propertyInfo, HSAdminSession session, Map whereContext) { final String[] items = new String[] { "PAYMENT", "PAYBACK", "ADOPTION", "HANDOVER", "LOSS", "CLEARING", "PRESCRIPTION" }; - final HSSelect field = new HSSelect(propertyInfo, 0, Arrays.asList(items)); + final HSSelect field = new HSSelect(session.getI18N(), propertyInfo, 0, Arrays.asList(items)); field.setWidth("100%"); field.setEnabled(isWriteAble(propertyInfo, action)); return field; @@ -136,7 +143,7 @@ public class GenericEditorFactory implements IEditorFactory, Serializable { private IHSEditor getSelectField(final String action, final PropertyInfo propertyInfo, final String... items) { - final HSSelect field = new HSSelect(propertyInfo, 0, Arrays.asList(items)); + final HSSelect field = new HSSelect(i18n, propertyInfo, 0, Arrays.asList(items)); field.setWidth("100%"); field.setEnabled(isWriteAble(propertyInfo, action)); return field; @@ -145,7 +152,7 @@ public class GenericEditorFactory implements IEditorFactory, Serializable { private IHSEditor getPacPrefixedField(final String action, final PropertyInfo propertyInfo, final char delimiter) { - final HSPacPrefixedField field = new HSPacPrefixedField(propertyInfo, delimiter); + final HSPacPrefixedField field = new HSPacPrefixedField(i18n, propertyInfo, delimiter); field.setWidth("100%"); field.setValue("xyz00-"); enableAndValidate(action, propertyInfo, field); @@ -155,7 +162,7 @@ public class GenericEditorFactory implements IEditorFactory, Serializable { private IHSEditor getShellSelect(final String action, final PropertyInfo propertyInfo) { final String[] items = new String[] { "/bin/false", "/bin/bash", "/bin/csh", "/bin/dash", "/bin/ksh", "/bin/tcsh", "/bin/zsh", "/usr/bin/passwd", "/usr/bin/scponly" }; - final HSSelect field = new HSSelect(propertyInfo, 7, Arrays.asList(items)); + final HSSelect field = new HSSelect(i18n, propertyInfo, 7, Arrays.asList(items)); field.setWidth("100%"); field.setEnabled(isWriteAble(propertyInfo, action)); return field; @@ -163,7 +170,7 @@ public class GenericEditorFactory implements IEditorFactory, Serializable { private IHSEditor getDateSelect(final String action, final PropertyInfo propertyInfo) { - final HSDateSelect field = new HSDateSelect(propertyInfo); + final HSDateSelect field = new HSDateSelect(i18n, propertyInfo); field.setWidth("100%"); field.setEnabled(isWriteAble(propertyInfo, action)); return field; @@ -187,7 +194,7 @@ public class GenericEditorFactory implements IEditorFactory, Serializable { // TODO Auto-generated catch block e.printStackTrace(); } - final HSSelect field = new HSSelect(propertyInfo, 0, selectList); + final HSSelect field = new HSSelect(i18n, propertyInfo, 0, selectList); field.setEnabled(isWriteAble(propertyInfo, action)); field.setWidth("100%"); return field; @@ -195,7 +202,7 @@ public class GenericEditorFactory implements IEditorFactory, Serializable { private IHSEditor getPasswordField(final String action, final PropertyInfo propertyInfo) { - final HSPasswordField field = new HSPasswordField(propertyInfo.getName(), "new".equals(action)); + final HSPasswordField field = new HSPasswordField(i18n, propertyInfo.getName(), "new".equals(action)); field.setWidth("100%"); field.setEnabled("new".equals(action) || "edit".equals(action)); return field; @@ -203,7 +210,7 @@ public class GenericEditorFactory implements IEditorFactory, Serializable { private IHSEditor getTextField(final String action, final PropertyInfo propertyInfo) { - final HSTextField field = new HSTextField(propertyInfo); + final HSTextField field = new HSTextField(i18n, propertyInfo); field.setWidth("100%"); enableAndValidate(action, propertyInfo, field); return field; diff --git a/web/src/main/java/de/hsadmin/web/GenericForm.java b/web/src/main/java/de/hsadmin/web/GenericForm.java index de48645..544ef6c 100644 --- a/web/src/main/java/de/hsadmin/web/GenericForm.java +++ b/web/src/main/java/de/hsadmin/web/GenericForm.java @@ -33,7 +33,7 @@ public class GenericForm extends CustomComponent { while (iterator.hasNext()) { final PropertyInfo propertyInfo = iterator.next(); final String inputName = propertyInfo.getName(); - final IEditorFactory editorFactory = FactoryProducer.getEditorFactory(module); + final IEditorFactory editorFactory = FactoryProducer.getEditorFactory(session.getI18N(), module); final IHSEditor field = editorFactory.getEditor("view", propertyInfo); inputFields.put(inputName, field); formLayout.addComponent(field); diff --git a/web/src/main/java/de/hsadmin/web/GenericFormWindow.java b/web/src/main/java/de/hsadmin/web/GenericFormWindow.java index bd95b01..d4718e6 100644 --- a/web/src/main/java/de/hsadmin/web/GenericFormWindow.java +++ b/web/src/main/java/de/hsadmin/web/GenericFormWindow.java @@ -24,7 +24,8 @@ public class GenericFormWindow extends Window implements IHSWindow { public GenericFormWindow(final HSTab parent, final String module, final String action, final HSAdminSession session, final Map whereContext) { - super(I18N.getText(action) + " " + I18N.getText(module)); + super(session.getI18N().getText(action) + " " + session.getI18N().getText(module)); + I18N i18n = session.getI18N(); this.parent = parent; center(); setModal(true); @@ -40,7 +41,7 @@ public class GenericFormWindow extends Window implements IHSWindow { continue; } final String inputName = propertyInfo.getName(); - final IEditorFactory editorFactory = FactoryProducer.getEditorFactory(module); + final IEditorFactory editorFactory = FactoryProducer.getEditorFactory(i18n, module); final IHSEditor field = editorFactory.getEditor(action, propertyInfo, session, whereContext); inputFields.put(inputName, field); contentForm.addComponent(field); diff --git a/web/src/main/java/de/hsadmin/web/HSAdminUI.java b/web/src/main/java/de/hsadmin/web/HSAdminUI.java index 8659fed..7cd2a65 100644 --- a/web/src/main/java/de/hsadmin/web/HSAdminUI.java +++ b/web/src/main/java/de/hsadmin/web/HSAdminUI.java @@ -1,5 +1,7 @@ package de.hsadmin.web; +import java.util.Locale; + import javax.servlet.annotation.WebServlet; import com.vaadin.annotations.Theme; @@ -34,6 +36,16 @@ public class HSAdminUI extends UI { @Override protected void init(VaadinRequest request) { + final String acceptLanguageHeader = request.getHeader("Accept-Language"); + Locale userLocale = Locale.GERMAN; + if (acceptLanguageHeader.startsWith("en")) { + userLocale = Locale.ENGLISH; + } + if (acceptLanguageHeader.startsWith("es")) { + userLocale = new Locale("es_ES"); + } + getUI().setLocale(userLocale); + getSession().setLocale(userLocale); setSizeFull(); layout = new VerticalLayout(); layout.setSizeFull(); diff --git a/web/src/main/java/de/hsadmin/web/HSConfirmBox.java b/web/src/main/java/de/hsadmin/web/HSConfirmBox.java index 813a309..ab9ada8 100644 --- a/web/src/main/java/de/hsadmin/web/HSConfirmBox.java +++ b/web/src/main/java/de/hsadmin/web/HSConfirmBox.java @@ -85,7 +85,7 @@ public class HSConfirmBox extends HorizontalLayout { } } }); - cancelButton = new Button(I18N.getText("cancel")); + cancelButton = new Button(session.getI18N().getText("cancel")); cancelButton.setClickShortcut(KeyCode.ESCAPE); cancelButton.addClickListener(new ClickListener() { diff --git a/web/src/main/java/de/hsadmin/web/HSDateSelect.java b/web/src/main/java/de/hsadmin/web/HSDateSelect.java index 40f85e8..973fe3c 100644 --- a/web/src/main/java/de/hsadmin/web/HSDateSelect.java +++ b/web/src/main/java/de/hsadmin/web/HSDateSelect.java @@ -13,8 +13,8 @@ public class HSDateSelect extends DateField implements IHSEditor { private String field; - public HSDateSelect(PropertyInfo propertyInfo) { - super(I18N.getText(propertyInfo.getResourceId())); + public HSDateSelect(final I18N i18n, PropertyInfo propertyInfo) { + super(i18n.getText(propertyInfo.getResourceId())); field = propertyInfo.getName(); setConverter(StringToDateConverter.class); } diff --git a/web/src/main/java/de/hsadmin/web/HSPacPrefixedField.java b/web/src/main/java/de/hsadmin/web/HSPacPrefixedField.java index ca85996..76644e6 100644 --- a/web/src/main/java/de/hsadmin/web/HSPacPrefixedField.java +++ b/web/src/main/java/de/hsadmin/web/HSPacPrefixedField.java @@ -13,8 +13,8 @@ public class HSPacPrefixedField extends HSTextField implements PacNamePrefixed { private String pacName; - public HSPacPrefixedField(final PropertyInfo propertyInfo, final char delimiter) { - super(propertyInfo); + public HSPacPrefixedField(final I18N i18n, final PropertyInfo propertyInfo, final char delimiter) { + super(i18n, propertyInfo); pacName = "xyz00"; this.delimiter = delimiter; addValidator(new PacNamePrefixValidator(this)); diff --git a/web/src/main/java/de/hsadmin/web/HSPasswordField.java b/web/src/main/java/de/hsadmin/web/HSPasswordField.java index 0460c9b..9f81269 100644 --- a/web/src/main/java/de/hsadmin/web/HSPasswordField.java +++ b/web/src/main/java/de/hsadmin/web/HSPasswordField.java @@ -8,8 +8,8 @@ public class HSPasswordField extends PasswordField implements IHSEditor { private static final long serialVersionUID = 1L; - public HSPasswordField(final String name, final boolean passwordRequired) { - super(I18N.getText(name)); + public HSPasswordField(final I18N i18n, final String name, final boolean passwordRequired) { + super(i18n.getText(name)); addValidator(new PasswordValidator(passwordRequired)); } diff --git a/web/src/main/java/de/hsadmin/web/HSSelect.java b/web/src/main/java/de/hsadmin/web/HSSelect.java index bd775b2..18e3592 100644 --- a/web/src/main/java/de/hsadmin/web/HSSelect.java +++ b/web/src/main/java/de/hsadmin/web/HSSelect.java @@ -13,8 +13,8 @@ public class HSSelect extends NativeSelect implements IHSEditor { private final String propertyName; - public HSSelect(final PropertyInfo propertyInfo, final int defaultIndex, final List values) { - super(I18N.getText(propertyInfo.getResourceId())); + public HSSelect(final I18N i18n, final PropertyInfo propertyInfo, final int defaultIndex, final List values) { + super(i18n.getText(propertyInfo.getResourceId())); this.propertyName = propertyInfo.getName(); super.addItems(values); if (values != null && values.size() > defaultIndex) { diff --git a/web/src/main/java/de/hsadmin/web/HSTab.java b/web/src/main/java/de/hsadmin/web/HSTab.java index adfcc65..3f65413 100644 --- a/web/src/main/java/de/hsadmin/web/HSTab.java +++ b/web/src/main/java/de/hsadmin/web/HSTab.java @@ -10,7 +10,6 @@ import org.apache.xmlrpc.XmlRpcException; import com.vaadin.ui.Alignment; import com.vaadin.ui.CustomComponent; -import com.vaadin.ui.HorizontalLayout; import com.vaadin.ui.Table; import com.vaadin.ui.VerticalLayout; @@ -149,7 +148,7 @@ public class HSTab extends CustomComponent { while (properties.hasNext()) { final PropertyInfo propertyInfo = properties.next(); if (showColumnInTable(propertyInfo)) { - grid.addContainerProperty(I18N.getText(propertyInfo.getModule() + "." + propertyInfo.getName()), String.class, ""); + grid.addContainerProperty(session.getI18N().getText(propertyInfo.getModule() + "." + propertyInfo.getName()), String.class, ""); } } grid.setSelectable(true); diff --git a/web/src/main/java/de/hsadmin/web/HSTextField.java b/web/src/main/java/de/hsadmin/web/HSTextField.java index 6d1f7fd..2297c07 100644 --- a/web/src/main/java/de/hsadmin/web/HSTextField.java +++ b/web/src/main/java/de/hsadmin/web/HSTextField.java @@ -12,8 +12,8 @@ public class HSTextField extends TextField implements IHSEditor { private final String propertyName; - public HSTextField(final PropertyInfo propertyInfo) { - super(I18N.getText(propertyInfo.getResourceId())); + public HSTextField(final I18N i18n, final PropertyInfo propertyInfo) { + super(i18n.getText(propertyInfo.getResourceId())); this.propertyName = propertyInfo.getName(); } diff --git a/web/src/main/java/de/hsadmin/web/HelpWindow.java b/web/src/main/java/de/hsadmin/web/HelpWindow.java index 6d0ad64..e479214 100644 --- a/web/src/main/java/de/hsadmin/web/HelpWindow.java +++ b/web/src/main/java/de/hsadmin/web/HelpWindow.java @@ -14,7 +14,7 @@ public class HelpWindow extends Window { private static final long serialVersionUID = 1L; - public HelpWindow(final String helpTopic) { + public HelpWindow(final I18N i18n, final String helpTopic) { // Create a sub-window and set the content super("Help Window"); setWidth("80%"); @@ -25,7 +25,7 @@ public class HelpWindow extends Window { final VerticalLayout subContent = new VerticalLayout(); subContent.setMargin(true); subContent.setSizeFull(); - final String helpBaseURL = I18N.getText("help.baseurl"); + final String helpBaseURL = i18n.getText("help.baseurl"); final Component helpContent = new BrowserFrame("Help Window", new ExternalResource(helpBaseURL + helpTopic)); helpContent.setSizeFull(); subContent.addComponent(helpContent); diff --git a/web/src/main/java/de/hsadmin/web/I18N.java b/web/src/main/java/de/hsadmin/web/I18N.java index 4aadac6..4c90b6e 100644 --- a/web/src/main/java/de/hsadmin/web/I18N.java +++ b/web/src/main/java/de/hsadmin/web/I18N.java @@ -1,35 +1,38 @@ package de.hsadmin.web; +import java.util.Locale; import java.util.MissingResourceException; import java.util.ResourceBundle; public class I18N { - private static final ResourceBundle TEXTS = ResourceBundle.getBundle("de.hsadmin.web.main"); + private static final String BASE_NAME = "de.hsadmin.web.main"; - /** - * Loads a String resource from the *.properties files. - * - * @param optionallyQualifiedTextProperty - * ID of the resource, optionally qualified module the module name, - * e.g. "customer.name" (preferred) or simply "name" (legacy). - * @return the String resource, e.g. a label or message, usually to be displayed to the user - */ - public static String getText(final String optionallyQualifiedTextProperty) { + public static I18N loc(final Locale locale) { + return new I18N(ResourceBundle.getBundle(BASE_NAME, locale)); + } + + private final ResourceBundle bundle; + + public I18N(final ResourceBundle bundle) { + this.bundle = bundle; + } + + public String getText(final String optionallyQualifiedTextProperty) { String textValue = getTextImpl(optionallyQualifiedTextProperty); return textValue != null ? textValue : "./. " + optionallyQualifiedTextProperty; } - public static String getTextImpl(final String optionallyQualifiedTextProperty) { + private String getTextImpl(final String optionallyQualifiedTextProperty) { try { - return I18N.TEXTS.getString(optionallyQualifiedTextProperty); + return bundle.getString(optionallyQualifiedTextProperty); } catch(MissingResourceException e1) { String[] parts = optionallyQualifiedTextProperty.split(".", 2); if ( parts.length > 1 ) { return getTextImpl(parts[1]); } } - return null; + return null; } } diff --git a/web/src/main/java/de/hsadmin/web/IHSEditor.java b/web/src/main/java/de/hsadmin/web/IHSEditor.java index aaf026b..11c9ce0 100644 --- a/web/src/main/java/de/hsadmin/web/IHSEditor.java +++ b/web/src/main/java/de/hsadmin/web/IHSEditor.java @@ -14,5 +14,5 @@ public interface IHSEditor extends Component { public void addValidator(Validator validator); public boolean isValid(); - + } diff --git a/web/src/main/java/de/hsadmin/web/LoginWindow.java b/web/src/main/java/de/hsadmin/web/LoginWindow.java index f97ab51..6431030 100644 --- a/web/src/main/java/de/hsadmin/web/LoginWindow.java +++ b/web/src/main/java/de/hsadmin/web/LoginWindow.java @@ -4,7 +4,6 @@ import java.util.HashMap; import java.util.Map; import com.vaadin.event.ShortcutAction.KeyCode; -import com.vaadin.server.ExternalResource; import com.vaadin.ui.AbstractTextField; import com.vaadin.ui.Button; import com.vaadin.ui.Button.ClickEvent; @@ -13,7 +12,6 @@ import com.vaadin.ui.Component; import com.vaadin.ui.FormLayout; import com.vaadin.ui.HasComponents; import com.vaadin.ui.Label; -import com.vaadin.ui.Link; import com.vaadin.ui.PasswordField; import com.vaadin.ui.TextField; import com.vaadin.ui.Window; @@ -27,7 +25,8 @@ public class LoginWindow extends Window { private static final long serialVersionUID = 1L; public LoginWindow(final HSAdminUI parent, final TicketService ticketService) { - super(I18N.getText("login.title")); + super(I18N.loc(parent.getSession().getLocale()).getText("login.title")); + final I18N i18n = I18N.loc(parent.getSession().getLocale()); center(); setModal(true); setWidth("480px"); @@ -35,11 +34,11 @@ public class LoginWindow extends Window { final FormLayout subContent = new FormLayout(); subContent.setMargin(true); - final TextField login = new TextField(I18N.getText("user.name")); + final TextField login = new TextField(i18n.getText("user.name")); login.setWidth("100%"); subContent.addComponent(login); login.focus(); - final PasswordField password = new PasswordField(I18N.getText("password")); + final PasswordField password = new PasswordField(i18n.getText("password")); password.setWidth("100%"); subContent.addComponent(password); final Label feedback = new Label(""); @@ -48,7 +47,7 @@ public class LoginWindow extends Window { subContent.addComponent(feedback); feedback.setStyleName(ValoTheme.LABEL_FAILURE); - final Button okButton = new Button(I18N.getText("login.button")); + final Button okButton = new Button(i18n.getText("login.button")); okButton.setStyleName(ValoTheme.BUTTON_PRIMARY); okButton.setClickShortcut(KeyCode.ENTER); okButton.addClickListener(new ClickListener() @@ -74,9 +73,9 @@ public class LoginWindow extends Window { } } try { - final String user = credentials.get(I18N.getText("user.name")); + final String user = credentials.get(i18n.getText("user.name")); final String loginUser = user.length() == 3 ? "hsh00-" + user : user; - final String password = credentials.get(I18N.getText("password")); + final String password = credentials.get(i18n.getText("password")); final String grantingTicket = ticketService.getGrantingTicket(loginUser, password); if (grantingTicket != null && !grantingTicket.isEmpty()) { feedback.setValue("successful login"); @@ -99,8 +98,6 @@ public class LoginWindow extends Window { } }); subContent.addComponent(okButton); - final Link linkToOld = new Link(I18N.getText("main.panel.link_to_old"), new ExternalResource("https://admin.hostsharing.net/hsarweb")); - subContent.addComponent(linkToOld); setContent(subContent); } diff --git a/web/src/main/java/de/hsadmin/web/MainPanel.java b/web/src/main/java/de/hsadmin/web/MainPanel.java index a7fa611..e24c1de 100644 --- a/web/src/main/java/de/hsadmin/web/MainPanel.java +++ b/web/src/main/java/de/hsadmin/web/MainPanel.java @@ -9,9 +9,9 @@ public class MainPanel extends CustomComponent{ private static final long serialVersionUID = -1085100738394404620L; - public MainPanel() { - final String helpBaseURL = I18N.getText("help.baseurl"); - final Component helpContent = new BrowserFrame(I18N.getText("main.panel.title"), new ExternalResource(helpBaseURL + "hsadmin")); + public MainPanel(final I18N i18n) { + final String helpBaseURL = i18n.getText("help.baseurl"); + final Component helpContent = new BrowserFrame(i18n.getText("main.panel.title"), new ExternalResource(helpBaseURL + "hsadmin")); helpContent.setSizeFull(); setCompositionRoot(helpContent); setSizeFull(); diff --git a/web/src/main/java/de/hsadmin/web/MainToolbar.java b/web/src/main/java/de/hsadmin/web/MainToolbar.java index 85458f5..00be961 100644 --- a/web/src/main/java/de/hsadmin/web/MainToolbar.java +++ b/web/src/main/java/de/hsadmin/web/MainToolbar.java @@ -52,7 +52,7 @@ public class MainToolbar extends CustomComponent implements ClickListener { final Button btn = new Button(); btn.setId(name + "-btn"); btn.setIcon(new ThemeResource("../icons/" + icon + "-icon.png")); - btn.setDescription(I18N.getText(name + ".tooltip")); + btn.setDescription(session.getI18N().getText(name + ".tooltip")); btn.setStyleName("borderless"); btn.addClickListener(this); return btn; diff --git a/web/src/main/java/de/hsadmin/web/MainWindow.java b/web/src/main/java/de/hsadmin/web/MainWindow.java index b83263a..c38ad57 100644 --- a/web/src/main/java/de/hsadmin/web/MainWindow.java +++ b/web/src/main/java/de/hsadmin/web/MainWindow.java @@ -31,6 +31,7 @@ public class MainWindow extends CustomComponent implements HSAdminSession { final private TicketService ticketService; final private String grantingTicket; final private String username; + final private I18N i18n; private ModulesManager modulesManager; private AbstractSplitPanel content; @@ -39,6 +40,7 @@ public class MainWindow extends CustomComponent implements HSAdminSession { this.ticketService = ticketService; this.grantingTicket = grantingTicket; this.username = username; + this.i18n = I18N.loc(getUI().getLocale()); setSizeFull(); final Panel mainPanel = new Panel(); @@ -63,7 +65,7 @@ public class MainWindow extends CustomComponent implements HSAdminSession { final EntryPointsSelector entryPoints = new EntryPointsSelector(this); entryPoints.setSizeFull(); content.setFirstComponent(entryPoints); - content.setSecondComponent(new MainPanel()); + content.setSecondComponent(new MainPanel(i18n)); content.setSplitPosition(26.6f); } catch (RpcException | TechnicalException e) { LOG.fatal(e.getLocalizedMessage(), e); @@ -126,4 +128,9 @@ public class MainWindow extends CustomComponent implements HSAdminSession { public String getUser() { return username; } + + @Override + public I18N getI18N() { + return i18n; + } } diff --git a/web/src/main/java/de/hsadmin/web/PackagePanel.java b/web/src/main/java/de/hsadmin/web/PackagePanel.java index 5f92a76..7ac180e 100644 --- a/web/src/main/java/de/hsadmin/web/PackagePanel.java +++ b/web/src/main/java/de/hsadmin/web/PackagePanel.java @@ -31,23 +31,23 @@ public class PackagePanel extends CustomComponent implements IHSPanel, SelectedT { final TabSheet tabsheet = new TabSheet(); tabsheet.addSelectedTabChangeListener(this); - tabsheet.addTab(new GenericForm("pac", session, itemId, "name"), I18N.getText("pac")); + tabsheet.addTab(new GenericForm("pac", session, itemId, "name"), session.getI18N().getText("pac")); final HSTab usersTab = new HSTab("user", session, "pac", itemId, "name"); usersTab.fillTable(); - tabsheet.addTab(usersTab, I18N.getText("user")); + tabsheet.addTab(usersTab, session.getI18N().getText("user")); final HSTab aliasTab = new HSTab("emailalias", session, "pac", itemId, "name"); - tabsheet.addTab(aliasTab, I18N.getText("emailalias")); + tabsheet.addTab(aliasTab, session.getI18N().getText("emailalias")); final HSTab domainTab = new HSTab("domain", session, "pac", itemId, "name"); - tabsheet.addTab(domainTab, I18N.getText("domain")); + tabsheet.addTab(domainTab, session.getI18N().getText("domain")); final HSTab mysqluserTab = new HSTab("mysqluser", session, "pac", itemId, "name"); - tabsheet.addTab(mysqluserTab, I18N.getText("mysqluser")); + tabsheet.addTab(mysqluserTab, session.getI18N().getText("mysqluser")); final HSTab mysqldbTab = new HSTab("mysqldb", session, "pac", itemId, "name"); - tabsheet.addTab(mysqldbTab, I18N.getText("mysqldb")); + tabsheet.addTab(mysqldbTab, session.getI18N().getText("mysqldb")); final HSTab postgresqluserTab = new HSTab("postgresqluser", session, "pac", itemId, "name"); - tabsheet.addTab(postgresqluserTab, I18N.getText("postgresqluser")); + tabsheet.addTab(postgresqluserTab, session.getI18N().getText("postgresqluser")); final HSTab postgresqldbTab = new HSTab("postgresqldb", session, "pac", itemId, "name"); - tabsheet.addTab(postgresqldbTab, I18N.getText("postgresqldb")); + tabsheet.addTab(postgresqldbTab, session.getI18N().getText("postgresqldb")); return tabsheet; } diff --git a/web/src/main/java/de/hsadmin/web/PanelToolbar.java b/web/src/main/java/de/hsadmin/web/PanelToolbar.java index 11f8fac..77e2fb4 100644 --- a/web/src/main/java/de/hsadmin/web/PanelToolbar.java +++ b/web/src/main/java/de/hsadmin/web/PanelToolbar.java @@ -60,7 +60,7 @@ public class PanelToolbar extends HorizontalLayout implements ClickListener { if (image != null) { btn.setIcon(new ThemeResource("../icons/" + image + "-icon.png")); } - btn.setDescription(I18N.getText(tooltip)); + btn.setDescription(session.getI18N().getText(tooltip)); btn.setStyleName("borderless"); btn.addClickListener(this); return btn; @@ -88,7 +88,7 @@ public class PanelToolbar extends HorizontalLayout implements ClickListener { final Object value = parent.getSelection(); if (value == null) { if (ACTION_EDIT.equals(action) || ACTION_DELETE.equals(action)) { - UI.getCurrent().addWindow(new InfoWindow(I18N.getText("emptySelectionMessage") + " " + action)); + UI.getCurrent().addWindow(new InfoWindow(session.getI18N().getText("emptySelectionMessage") + " " + action)); return; } } diff --git a/web/src/main/java/de/hsadmin/web/SubWindowFactory.java b/web/src/main/java/de/hsadmin/web/SubWindowFactory.java index 89092ae..e5f5170 100644 --- a/web/src/main/java/de/hsadmin/web/SubWindowFactory.java +++ b/web/src/main/java/de/hsadmin/web/SubWindowFactory.java @@ -16,7 +16,7 @@ public class SubWindowFactory extends AbstractWindowFactory { return null; } if (action.equalsIgnoreCase("help")) { - return new HelpWindow(parent.getModule()); + return new HelpWindow(session.getI18N(), parent.getModule()); } final Map whereContext = new HashMap<>(); whereContext.put(parent.getSelectPropertyName(), parent.getSelectPropertyValue().toString()); diff --git a/web/src/main/java/de/hsadmin/web/UserProfileWindow.java b/web/src/main/java/de/hsadmin/web/UserProfileWindow.java index cec28f2..0c591d8 100644 --- a/web/src/main/java/de/hsadmin/web/UserProfileWindow.java +++ b/web/src/main/java/de/hsadmin/web/UserProfileWindow.java @@ -28,7 +28,7 @@ public class UserProfileWindow extends Window implements IHSWindow { public UserProfileWindow(final HSAdminSession session, final Map whereContext) { - super(I18N.getText("edit") + " " + I18N.getText("user")); + super(session.getI18N().getText("edit") + " " + session.getI18N().getText("user")); center(); setModal(true); setWidth("640px"); @@ -42,7 +42,7 @@ public class UserProfileWindow extends Window implements IHSWindow { final PropertyInfo propertyInfo = iterator.next(); final String inputName = propertyInfo.getName(); if (visibleFields.contains(inputName)) { - final IEditorFactory editorFactory = FactoryProducer.getEditorFactory("user"); + final IEditorFactory editorFactory = FactoryProducer.getEditorFactory(session.getI18N(), "user"); final IHSEditor field = editorFactory.getEditor(inputName.equals("password") ? "edit" : "view", propertyInfo, session, whereContext); inputFields.put(inputName, field); contentForm.addComponent(field);