diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/content/MainPage.java b/src/main/java/ch/ethz/seb/sebserver/gui/content/MainPage.java index 009a67fd..3260232d 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/content/MainPage.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/content/MainPage.java @@ -25,6 +25,7 @@ import org.springframework.stereotype.Component; import ch.ethz.seb.sebserver.gbl.profile.GuiProfile; import ch.ethz.seb.sebserver.gui.content.activity.ActivitiesPane; import ch.ethz.seb.sebserver.gui.service.i18n.LocTextKey; +import ch.ethz.seb.sebserver.gui.service.i18n.PolyglotPageService; import ch.ethz.seb.sebserver.gui.service.page.PageContext; import ch.ethz.seb.sebserver.gui.service.page.PageService; import ch.ethz.seb.sebserver.gui.service.page.TemplateComposer; @@ -52,13 +53,16 @@ public class MainPage implements TemplateComposer { private static final int[] OPENED_SASH_WEIGHTS = new int[] { 0, 100, 0 }; private final WidgetFactory widgetFactory; + private final PolyglotPageService polyglotPageService; private final PageService pageStateService; public MainPage( final WidgetFactory widgetFactory, + final PolyglotPageService polyglotPageService, final PageService pageStateService) { this.widgetFactory = widgetFactory; + this.polyglotPageService = polyglotPageService; this.pageStateService = pageStateService; } @@ -105,7 +109,7 @@ public class MainPage implements TemplateComposer { mainSash.setWeights(DEFAULT_SASH_WEIGHTS); ib.setData("fullScreen", false); ib.setImage(WidgetFactory.ImageIcon.MAXIMIZE.getImage(ib.getDisplay())); - this.widgetFactory.injectI18n( + this.polyglotPageService.injectI18n( ib, null, new LocTextKey("sebserver.mainpage.maximize.tooltip")); @@ -113,7 +117,7 @@ public class MainPage implements TemplateComposer { mainSash.setWeights(OPENED_SASH_WEIGHTS); ib.setData("fullScreen", true); ib.setImage(WidgetFactory.ImageIcon.MINIMIZE.getImage(ib.getDisplay())); - this.widgetFactory.injectI18n( + this.polyglotPageService.injectI18n( ib, null, new LocTextKey("sebserver.mainpage.minimize.tooltip")); diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/i18n/PolyglotPageService.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/i18n/PolyglotPageService.java index aa0efeac..be2d72ab 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/i18n/PolyglotPageService.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/i18n/PolyglotPageService.java @@ -10,7 +10,20 @@ package ch.ethz.seb.sebserver.gui.service.i18n; import java.util.Locale; +import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.TabFolder; +import org.eclipse.swt.widgets.TabItem; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableColumn; +import org.eclipse.swt.widgets.TableItem; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.swt.widgets.TreeItem; + +import ch.ethz.seb.sebserver.gui.service.page.PageContext; +import ch.ethz.seb.sebserver.gui.widget.ImageUpload; public interface PolyglotPageService { @@ -36,4 +49,32 @@ public interface PolyglotPageService { * @param locale the Locale to set */ void setPageLocale(Composite root, Locale locale); + void injectI18n(ImageUpload imageUpload, LocTextKey locTextKey); + + void injectI18n(Label label, LocTextKey locTextKey); + + void injectI18n(Label label, LocTextKey locTextKey, LocTextKey locToolTipKey); + + void injectI18n(Group group, LocTextKey locTextKey, LocTextKey locTooltipKey); + + void injectI18n(Button button, LocTextKey locTextKey); + + void injectI18n(Button button, LocTextKey locTextKey, LocTextKey locToolTipKey); + + void injectI18n(Tree tree); + + void injectI18n(TreeItem treeItem, LocTextKey locTextKey); + + void injectI18n(Table table); + + void injectI18n(TabFolder tabFolder); + + void injectI18n(TableColumn tableColumn, LocTextKey locTextKey, LocTextKey locTooltipKey); + + void injectI18n(TableItem tableItem, LocTextKey... locTextKey); + + void injectI18n(TabItem tabItem, LocTextKey locTextKey, LocTextKey locTooltipKey); + + void createLanguageSelector(PageContext composerCtx); + } \ No newline at end of file diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/i18n/impl/PolyglotPageServiceImpl.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/i18n/impl/PolyglotPageServiceImpl.java index 6d8c46eb..2234b605 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/i18n/impl/PolyglotPageServiceImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/i18n/impl/PolyglotPageServiceImpl.java @@ -11,15 +11,31 @@ package ch.ethz.seb.sebserver.gui.service.i18n.impl; import java.util.Locale; import java.util.function.Consumer; +import org.apache.commons.lang3.StringUtils; +import org.eclipse.rap.rwt.RWT; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.TabFolder; +import org.eclipse.swt.widgets.TabItem; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableColumn; +import org.eclipse.swt.widgets.TableItem; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.swt.widgets.TreeItem; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; import ch.ethz.seb.sebserver.gbl.profile.GuiProfile; import ch.ethz.seb.sebserver.gui.service.i18n.I18nSupport; +import ch.ethz.seb.sebserver.gui.service.i18n.LocTextKey; import ch.ethz.seb.sebserver.gui.service.i18n.PolyglotPageService; import ch.ethz.seb.sebserver.gui.service.page.ComposerService; +import ch.ethz.seb.sebserver.gui.service.page.PageContext; +import ch.ethz.seb.sebserver.gui.widget.ImageUpload; /** Service that supports page language change on the fly */ @Lazy @@ -55,4 +71,222 @@ public final class PolyglotPageServiceImpl implements PolyglotPageService { root.layout(true, true); } + @Override + public void injectI18n(final ImageUpload imageUpload, final LocTextKey locTextKey) { + final Consumer imageUploadFunction = iu -> { + if (locTextKey != null) { + iu.setSelectionText(this.i18nSupport.getText(locTextKey)); + } + }; + imageUpload.setData(POLYGLOT_WIDGET_FUNCTION_KEY, imageUploadFunction); + imageUploadFunction.accept(imageUpload); + } + + @Override + public void injectI18n(final Label label, final LocTextKey locTextKey) { + injectI18n(label, locTextKey, null); + } + + @Override + public void injectI18n(final Label label, final LocTextKey locTextKey, final LocTextKey locToolTipKey) { + final Consumer