Introduce right to left language support
authormbaudier <mbaudier@europe.weserstr.mbaudier.netiket.eu>
Mon, 25 Jun 2018 20:50:22 +0000 (22:50 +0200)
committermbaudier <mbaudier@europe.weserstr.mbaudier.netiket.eu>
Mon, 25 Jun 2018 20:50:22 +0000 (22:50 +0200)
org.argeo.cms.e4/src/org/argeo/cms/e4/handlers/LocaleAddon.java
org.argeo.cms/OSGI-INF/l10n/bundle_ar.properties [new file with mode: 0644]

index 8582f60b3bbdefea19e2b5af9a1bd9d8492f864e..94140a614deca3156947c19212ddbfc3914026fa 100644 (file)
@@ -1,6 +1,7 @@
 package org.argeo.cms.e4.handlers;
 
 import java.security.AccessController;
+import java.util.List;
 import java.util.Locale;
 import java.util.Set;
 
@@ -9,16 +10,42 @@ import javax.security.auth.Subject;
 
 import org.argeo.eclipse.ui.specific.UiContext;
 import org.eclipse.e4.core.services.nls.ILocaleChangeService;
+import org.eclipse.e4.ui.model.application.MApplication;
+import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
+import org.eclipse.e4.ui.workbench.modeling.EModelService;
+import org.eclipse.e4.ui.workbench.modeling.ElementMatcher;
+import org.eclipse.swt.SWT;
 
+/** Integrate workbench with the locale provided at log in. */
 public class LocaleAddon {
+       private final static String STYLE_OVERRIDE = "styleOverride";
+
+       // Right to left languages
+       private final static String ARABIC = "ar";
+       private final static String HEBREW = "he";
+
        @PostConstruct
-       public void init(ILocaleChangeService localeChangeService) {
+       public void init(ILocaleChangeService localeChangeService, EModelService modelService, MApplication application) {
                Subject subject = Subject.getSubject(AccessController.getContext());
                Set<Locale> locales = subject.getPublicCredentials(Locale.class);
                if (!locales.isEmpty()) {
                        Locale locale = locales.iterator().next();
                        localeChangeService.changeApplicationLocale(locale);
                        UiContext.setLocale(locale);
+
+                       if (locale.getLanguage().equals(ARABIC) || locale.getLanguage().equals(HEBREW)) {
+                               List<MWindow> windows = modelService.findElements(application, MWindow.class, EModelService.ANYWHERE,
+                                               new ElementMatcher(null, null, (String) null));
+                               for (MWindow window : windows) {
+                                       String currentStyle = window.getPersistedState().get(STYLE_OVERRIDE);
+                                       int style = 0;
+                                       if (currentStyle != null) {
+                                               style = Integer.parseInt(currentStyle);
+                                       }
+                                       style = style | SWT.RIGHT_TO_LEFT;
+                                       window.getPersistedState().put(STYLE_OVERRIDE, Integer.toString(style));
+                               }
+                       }
                }
        }
 }
diff --git a/org.argeo.cms/OSGI-INF/l10n/bundle_ar.properties b/org.argeo.cms/OSGI-INF/l10n/bundle_ar.properties
new file mode 100644 (file)
index 0000000..2036e0f
--- /dev/null
@@ -0,0 +1,19 @@
+username=\u0645\u0633\u062A\u062E\u062F\u0645
+password=\u0643\u0644\u0645\u0629 \u0627\u0644\u0645\u0631\u0648\u0631
+logout=sign out
+login=sign in
+register=register
+
+changePassword=Change password
+currentPassword=Current password
+newPassword=New password
+repeatNewPassword=Repeat new password
+passwordChanged=Password changed
+
+close=Close
+cancel=Cancel
+ok=Ok
+
+wizardBack=Back
+wizardNext=Next
+wizardFinish=Finish