com.google.gwt.i18n.client.LocaleInfo Java Examples

The following examples show how to use com.google.gwt.i18n.client.LocaleInfo. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GssResourceGenerator.java    From gss.gwt with Apache License 2.0 6 votes vote down vote up
@Override
protected String getCssExpression(TreeLogger logger, ResourceContext context,
    JMethod method) throws UnableToCompleteException {
  CssTree cssTree = cssTreeMap.get(method).tree;

  String standard = printCssTree(cssTree);

  // TODO add configuration properties for swapLtrRtlInUrl, swapLeftRightInUrl and
  // shouldFlipConstantReferences booleans
  RecordingBidiFlipper recordingBidiFlipper =
      new RecordingBidiFlipper(cssTree.getMutatingVisitController(), false, false, true);
  recordingBidiFlipper.runPass();

  if (recordingBidiFlipper.nodeFlipped()) {
    String reversed = printCssTree(cssTree);
    return LocaleInfo.class.getName() + ".getCurrentLocale().isRTL() ? "
        + reversed + " : " + standard;
  } else {
    return standard;
  }
}
 
Example #2
Source File: BlocklyPanel.java    From appinventor-extensions with Apache License 2.0 6 votes vote down vote up
public BlocklyPanel(YaBlocksEditor blocksEditor, String formName, boolean readOnly) {
  super("");
  getElement().addClassName("svg");
  getElement().setId(formName);
  this.formName = formName;
  /* Blockly initialization now occurs in three stages. This is due to the fact that certain
   * Blockly objects rely on SVG methods such as getScreenCTM(), which are not properly
   * initialized and/or null prior to the svg element being attached to the DOM. The first
   * stage of initialization happens here.
   *
   * Stages 2 and 3 can occur in different orders depending on network latency. On a fast
   * connection, the second stage will be loading of the .bky content into the workspace.
   * The third stage will then be rendering of the workspace when the user switches to the
   * Blocks editor. On slow connections, the workspace may render blank until the blocks file
   * has been downloaded from the server.
   */
  initWorkspace(Long.toString(blocksEditor.getProjectId()), readOnly, LocaleInfo.getCurrentLocale().isRTL());
  OdeLog.log("Created BlocklyPanel for " + formName);
}
 
Example #3
Source File: CellBrowser.java    From consulo with Apache License 2.0 6 votes vote down vote up
/**
 * Get the HTML representation of an image.
 *
 * @param res the {@link ImageResource} to render as HTML
 * @return the rendered HTML
 */
private SafeHtml getImageHtml(ImageResource res) {
  // Right-justify image if LTR, left-justify if RTL
  AbstractImagePrototype proto = AbstractImagePrototype.create(res);
  SafeHtml image = proto.getSafeHtml();

  SafeStylesBuilder cssBuilder = new SafeStylesBuilder();
  if (LocaleInfo.getCurrentLocale().isRTL()) {
    cssBuilder.appendTrustedString("left:0px;");
  } else {
    cssBuilder.appendTrustedString("right:0px;");
  }
  cssBuilder.appendTrustedString("width: " + res.getWidth() + "px;");
  cssBuilder.appendTrustedString("height: " + res.getHeight() + "px;");
  return template.imageWrapper(cssBuilder.toSafeStyles(), image);
}
 
Example #4
Source File: CellBrowser.java    From consulo with Apache License 2.0 6 votes vote down vote up
void scrollToEnd() {
  Element elem = getElement();
  targetScrollLeft = elem.getScrollWidth() - elem.getClientWidth();
  if (LocaleInfo.getCurrentLocale().isRTL()) {
    targetScrollLeft *= -1;
  }

  if (isAnimationEnabled()) {
    // Animate the scrolling.
    startScrollLeft = elem.getScrollLeft();
    run(250, elem);
  } else {
    // Scroll instantly.
    onComplete();
  }
}
 
Example #5
Source File: CellBrowser.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
protected void onBrowserEvent2(Event event) {
  super.onBrowserEvent2(event);

  // Handle keyboard navigation between lists.
  String eventType = event.getType();
  if (BrowserEvents.KEYDOWN.equals(eventType) && !isKeyboardNavigationSuppressed()) {
    int keyCode = event.getKeyCode();
    boolean isRtl = LocaleInfo.getCurrentLocale().isRTL();
    keyCode = KeyCodes.maybeSwapArrowKeysForRtl(keyCode, isRtl);
    switch (keyCode) {
      case KeyCodes.KEY_LEFT:
        keyboardNavigateShallow();
        return;
      case KeyCodes.KEY_RIGHT:
        keyboardNavigateDeep();
        return;
    }
  }
}
 
Example #6
Source File: JsLocaleProvider.java    From actor-platform with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public String getCurrentLocale() {
    String locale = LocaleInfo.getCurrentLocale().getLocaleName();
    if (locale == null) {
        Log.d("JsLocaleProvider", "Found Null. Returning En");
        return "En";
    }
    if ("default".equals(locale)) {
        Log.d("JsLocaleProvider", "Found default. Returning En");
        return "En";
    }
    if (locale.length() >= 2) {
        String res = locale.substring(0, 1).toUpperCase() + locale.substring(1, 2).toLowerCase();
        Log.d("JsLocaleProvider", "Found " + res);
        return res;
    }
    Log.d("JsLocaleProvider", "Found unknown: " + locale + ". Returning En.");
    return "En";
}
 
Example #7
Source File: FilterBox.java    From unitime with Apache License 2.0 6 votes vote down vote up
protected void resizeFilterIfNeeded() {
	if (!isAttached()) return;
	ChipPanel last = getLastChipPanel();
	iFilterOpen.setVisible(isEnabled() && !isFilterPopupShowing());
	iFilterClear.setVisible(isEnabled() && (!iFilter.getText().isEmpty() || last != null));
	int buttonWidth = (isFilterPopupShowing() ? iFilterClose : iFilterOpen).getElement().getOffsetWidth() + iFilterClear.getElement().getOffsetWidth() + 8;
	if (last != null) {
		int width = getAbsoluteLeft() + getOffsetWidth() - last.getAbsoluteLeft() - last.getOffsetWidth() - buttonWidth;
		if (LocaleInfo.getCurrentLocale().isRTL())
			width = last.getAbsoluteLeft() - getAbsoluteLeft() - buttonWidth;
		if (width < 100)
			width = getElement().getClientWidth() - buttonWidth;
		iFilter.getElement().getStyle().setWidth(width, Unit.PX);
	} else {
		iFilter.getElement().getStyle().setWidth(getElement().getClientWidth() - buttonWidth, Unit.PX);
	}
	if (isSuggestionsShowing())
		iSuggestionsPopup.moveRelativeTo(this);
	if (isFilterPopupShowing())
		iFilterPopup.moveRelativeTo(this);
}
 
Example #8
Source File: TopPanel.java    From appinventor-extensions with Apache License 2.0 5 votes vote down vote up
@Override
public void execute() {
  final String queryParam = LocaleInfo.getLocaleQueryParam();
  Command savecmd = new SaveAction();
  savecmd.execute();
  if (queryParam != null) {
    UrlBuilder builder = Window.Location.createUrlBuilder().setParameter(
        queryParam, localeName);
    Window.Location.replace(builder.buildString());
  } else {
    // If we are using only cookies, just reload
    Window.Location.reload();
  }
}
 
Example #9
Source File: DockPanel.java    From consulo with Apache License 2.0 5 votes vote down vote up
private boolean shouldAddToLogicalLeftOfTable(DockLayoutConstant widgetDirection) {

    assert (widgetDirection == LINE_START || widgetDirection == LINE_END || widgetDirection == EAST || widgetDirection == WEST);

    // In a bidi-sensitive environment, adding a widget to the logical left
    // column (think DOM order) means that it will be displayed at the start
    // of the line direction for the current layout. This is because HTML
    // tables are bidi-sensitive; the column order switches depending on
    // the line direction.
    if (widgetDirection == LINE_START) {
      return true;
    }

    if (LocaleInfo.getCurrentLocale().isRTL()) {
      // In an RTL layout, the logical left columns will be displayed on the right hand
      // side. When the direction for the widget is EAST, adding the widget to the logical
      // left columns will have the desired effect of displaying the widget on the 'eastern'
      // side of the screen.
      return (widgetDirection == EAST);
    }

    // In an LTR layout, the logical left columns are displayed on the left hand
    // side. When the direction for the widget is WEST, adding the widget to the
    // logical left columns will have the desired effect of displaying the widget on the
    // 'western' side of the screen.
    return (widgetDirection == WEST);
  }
 
Example #10
Source File: WebClient.java    From incubator-retired-wave with Apache License 2.0 5 votes vote down vote up
private void setupLocaleSelect() {
  final SelectElement select = (SelectElement) Document.get().getElementById("lang");
  String currentLocale = LocaleInfo.getCurrentLocale().getLocaleName();
  String[] localeNames = LocaleInfo.getAvailableLocaleNames();
  for (String locale : localeNames) {
    if (!DEFAULT_LOCALE.equals(locale)) {
      String displayName = LocaleInfo.getLocaleNativeDisplayName(locale);
      OptionElement option = Document.get().createOptionElement();
      option.setValue(locale);
      option.setText(displayName);
      select.add(option, null);
      if (locale.equals(currentLocale)) {
        select.setSelectedIndex(select.getLength() - 1);
      }
    }
  }
  EventDispatcherPanel.of(select).registerChangeHandler(null, new WaveChangeHandler() {

    @Override
    public boolean onChange(ChangeEvent event, Element context) {
      UrlBuilder builder = Location.createUrlBuilder().setParameter(
              "locale", select.getValue());
      Window.Location.replace(builder.buildString());
      localeService.storeLocale(select.getValue());
      return true;
    }
  });
}
 
Example #11
Source File: NumberFormat.java    From jts with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static NumberFormat getFormat(String pattern) {
    NumberFormat nf = new NumberFormat();
	
    NumberConstants nc = LocaleInfo.getCurrentLocale().getNumberConstants();
    
    nf.mFormat = com.google.gwt.i18n.client.NumberFormat.getFormat(pattern);
    nf.mGrouping = nc.groupingSeparator();
    nf.mDecimal = nc.decimalSeparator();
    
    return nf;
}
 
Example #12
Source File: WebClient.java    From swellrt with Apache License 2.0 5 votes vote down vote up
private void setupLocaleSelect() {
  final SelectElement select = (SelectElement) Document.get().getElementById("lang");
  String currentLocale = LocaleInfo.getCurrentLocale().getLocaleName();
  String[] localeNames = LocaleInfo.getAvailableLocaleNames();
  for (String locale : localeNames) {
    if (!DEFAULT_LOCALE.equals(locale)) {
      String displayName = LocaleInfo.getLocaleNativeDisplayName(locale);
      OptionElement option = Document.get().createOptionElement();
      option.setValue(locale);
      option.setText(displayName);
      select.add(option, null);
      if (locale.equals(currentLocale)) {
        select.setSelectedIndex(select.getLength() - 1);
      }
    }
  }
  EventDispatcherPanel.of(select).registerChangeHandler(null, new WaveChangeHandler() {

    @Override
    public boolean onChange(ChangeEvent event, Element context) {
      UrlBuilder builder = Location.createUrlBuilder().setParameter(
              "locale", select.getValue());
      Window.Location.replace(builder.buildString());
      localeService.storeLocale(select.getValue());
      return true;
    }
  });
}
 
Example #13
Source File: W3wTool.java    From geowe-core with GNU General Public License v3.0 5 votes vote down vote up
public String getLocale() {
	String locale = LocaleInfo.getCurrentLocale().getLocaleName();
	if ("default".equals(locale)) {
		locale = "en";
	}
	return locale;
}
 
Example #14
Source File: DemoGwtWebApp.java    From demo-gwt-springboot with Apache License 2.0 5 votes vote down vote up
private void setupBootbox() {
	if (LocaleInfo.getCurrentLocale().getLocaleName().equals(LOCALE)) {
		logger.info(
				"Locale: " + LocaleInfo.getCurrentLocale().getLocaleName());
		Bootbox.setLocale(BootboxLocale.DE);
	}
}
 
Example #15
Source File: TopPanel.java    From appinventor-extensions with Apache License 2.0 5 votes vote down vote up
private String getDisplayName(String localeName){
  String nativeName=LocaleInfo.getLocaleNativeDisplayName(localeName);
  try {
    return LANGUAGES.get(localeName);
  } catch (MissingResourceException e) {
    return nativeName;
  }
}
 
Example #16
Source File: UniTimeTableHeader.java    From unitime with Apache License 2.0 4 votes vote down vote up
public static HorizontalAlignmentConstant getDefaultHorizontalAlignment() {
	if (LocaleInfo.getCurrentLocale().isRTL())
		return HasHorizontalAlignment.ALIGN_RIGHT;
	return HasHorizontalAlignment.ALIGN_LEFT;
}
 
Example #17
Source File: JsFacade.java    From actor-platform with GNU Affero General Public License v3.0 4 votes vote down vote up
@UsedByApp
public void init(JsConfig config) {

    provider = (JsFileSystemProvider) Storage.getFileSystemRuntime();

    String clientName = IdentityUtils.getClientName();
    String uniqueId = IdentityUtils.getUniqueId();

    ConfigurationBuilder configuration = new ConfigurationBuilder();
    configuration.setApiConfiguration(new ApiConfiguration(APP_NAME, APP_ID, APP_KEY, clientName, uniqueId));
    configuration.setPhoneBookProvider(new JsPhoneBookProvider());
    configuration.setNotificationProvider(new JsNotificationsProvider());
    configuration.setCallsProvider(new JsCallsProvider());

    // Setting locale
    String locale = LocaleInfo.getCurrentLocale().getLocaleName();
    if (locale.equals("default")) {
        Log.d(TAG, "Default locale found");
        configuration.addPreferredLanguage("en");
    } else {
        Log.d(TAG, "Locale found:" + locale);
        configuration.addPreferredLanguage(locale.toLowerCase());
    }

    // Setting timezone
    int offset = new Date().getTimezoneOffset();
    String timeZone = TimeZone.createTimeZone(offset).getID();
    Log.d(TAG, "TimeZone found:" + timeZone + " for delta " + offset);
    configuration.setTimeZone(timeZone);

    // LocaleInfo.getCurrentLocale().getLocaleName()

    // Is Web application
    configuration.setPlatformType(PlatformType.WEB);

    // Device Category
    // Only Desktop is supported for JS library
    configuration.setDeviceCategory(DeviceCategory.DESKTOP);

    // Adding endpoints
    for (String endpoint : config.getEndpoints()) {
        configuration.addEndpoint(endpoint);
    }

    if (config.getLogHandler() != null) {
        final JsLogCallback callback = config.getLogHandler();
        JsLogProvider.setLogCallback(new JsLogProvider.LogCallback() {
            @Override
            public void log(String tag, String level, String message) {
                callback.log(tag, level, message);
            }
        });
    }

    messenger = new JsMessenger(configuration.build());

    Log.d(TAG, "JsMessenger created");
}
 
Example #18
Source File: DockPanel.java    From consulo with Apache License 2.0 4 votes vote down vote up
private boolean shouldAddToLogicalRightOfTable(DockLayoutConstant widgetDirection) {

    // See comments for shouldAddToLogicalLeftOfTable for clarification

    assert (widgetDirection == LINE_START || widgetDirection == LINE_END || widgetDirection == EAST || widgetDirection == WEST);

    if (widgetDirection == LINE_END) {
      return true;
    }

    if (LocaleInfo.getCurrentLocale().isRTL()) {
      return (widgetDirection == WEST);
    }

    return (widgetDirection == EAST);
  }
 
Example #19
Source File: LanguagesDataSource.java    From proarc with GNU General Public License v3.0 4 votes vote down vote up
public static String activeLocale() {
    String locale = LocaleInfo.getCurrentLocale().getLocaleName();
    return locale == null || "default".equals(locale)
            ? "en" : locale;
}
 
Example #20
Source File: SuggestionsContainer.java    From cuba with Apache License 2.0 4 votes vote down vote up
@Override
public void onBrowserEvent(Event event) {
    if (getElement() == DOM.eventGetTarget(event)) {
        return;
    }

    SuggestionItem item = findItem(DOM.eventGetTarget(event));
    switch (DOM.eventGetType(event)) {
        case Event.ONMOUSEDOWN: {
            if (BrowserInfo.get().isIE()) {
                suggestionFieldWidget.iePreventBlur = true;
            }
            break;
        }

        case Event.ONCLICK: {
            if (event.getButton() == NativeEvent.BUTTON_LEFT) {
                performItemCommand(item);
            }
            break;
        }

        case Event.ONMOUSEOVER: {
            if (item != null) {
                selectItem(item);
            }
            break;
        }

        case Event.ONKEYDOWN: {
            int keyCode = KeyCodes.maybeSwapArrowKeysForRtl(
                    event.getKeyCode(),
                    LocaleInfo.getCurrentLocale().isRTL()
            );

            switch (keyCode) {
                case KeyCodes.KEY_UP:
                    selectPrevItem();
                    preventEvent(event);
                    break;
                case KeyCodes.KEY_DOWN:
                    selectNextItem();
                    preventEvent(event);
                    break;
                case KeyCodes.KEY_ESCAPE:
                    selectItem(null);
                    preventEvent(event);
                    break;
                case KeyCodes.KEY_TAB:
                    selectItem(null);
                    break;
                case KeyCodes.KEY_ENTER:
                    performItemCommand(item);
                    preventEvent(event);
                    break;
            }
            break;
        }
    }
    super.onBrowserEvent(event);
}
 
Example #21
Source File: CellBrowser.java    From consulo with Apache License 2.0 4 votes vote down vote up
protected <T> CellBrowser(Builder<T> builder) {
  super(builder.viewModel);
  if (template == null) {
    template = GWT.create(Template.class);
  }
  Resources resources = builder.resources();
  this.style = resources.cellBrowserStyle();
  this.style.ensureInjected();
  this.cellListResources = new CellListResourcesImpl(resources);
  this.loadingIndicator = builder.loadingIndicator;
  this.pagerFactory = builder.pagerFactory;
  this.pageSize = builder.pageSize;
  initWidget(new SplitLayoutPanel());
  getElement().getStyle().setOverflow(Overflow.AUTO);
  setStyleName(this.style.cellBrowserWidget());

  // Initialize the open and close images strings.
  ImageResource treeOpen = resources.cellBrowserOpen();
  ImageResource treeClosed = resources.cellBrowserClosed();
  openImageHtml = getImageHtml(treeOpen);
  closedImageHtml = getImageHtml(treeClosed);
  imageWidth = Math.max(treeOpen.getWidth(), treeClosed.getWidth());
  minWidth = imageWidth + 20;

  // Add a placeholder to maintain the scroll width.
  scrollLock = Document.get().createDivElement();
  scrollLock.getStyle().setPosition(Position.ABSOLUTE);
  scrollLock.getStyle().setVisibility(Visibility.HIDDEN);
  scrollLock.getStyle().setZIndex(-32767);
  scrollLock.getStyle().setTop(0, Unit.PX);
  if (LocaleInfo.getCurrentLocale().isRTL()) {
    scrollLock.getStyle().setRight(0, Unit.PX);
  } else {
    scrollLock.getStyle().setLeft(0, Unit.PX);
  }
  scrollLock.getStyle().setHeight(1, Unit.PX);
  scrollLock.getStyle().setWidth(1, Unit.PX);
  getElement().appendChild(scrollLock);

  // Associate the first view with the rootValue.
  appendTreeNode(getNodeInfo(builder.rootValue), builder.rootValue);

  // Catch scroll events.
  sinkEvents(Event.ONSCROLL);
}
 
Example #22
Source File: MonthNames.java    From gwtbootstrap3-extras with Apache License 2.0 4 votes vote down vote up
public void localize() {
    localize(LocaleInfo.getCurrentLocale().getDateTimeFormatInfo().monthsFull(),
            LocaleInfo.getCurrentLocale().getDateTimeFormatInfo().monthsShort());
}
 
Example #23
Source File: DayNames.java    From gwtbootstrap3-extras with Apache License 2.0 4 votes vote down vote up
public void localize() {
    localized(LocaleInfo.getCurrentLocale().getDateTimeFormatInfo().weekdaysFull(),
            LocaleInfo.getCurrentLocale().getDateTimeFormatInfo().weekdaysShort());
}
 
Example #24
Source File: PropertiesManager.java    From SensorWebClient with GNU General Public License v2.0 4 votes vote down vote up
private void setCurrentLanguage() {
	LocaleInfo currentLocale = LocaleInfo.getCurrentLocale();
	String localeName = currentLocale.getLocaleName();
	PropertiesManager.language = localeName.substring(0, 2);
}