private static void setTitle(
      RemoteViews rv, Context context, String settingLang, Date currentDate) {
    // save current Lang
    Resources res = context.getResources();
    Configuration conf = res.getConfiguration();
    String currentLang = conf.locale.getLanguage();

    String titleText;
    // get title by setting lang. Use context lang, so synchronize it
    //noinspection SynchronizationOnLocalVariableOrMethodParameter
    synchronized (context) {
      Log.d(TAG, "currentLang:" + currentLang + " settingLang:" + settingLang);

      boolean isLangChaged = false;
      if (!settingLang.equals(currentLang)) {
        LocalizationUtils.setLocate(context, settingLang);
        isLangChaged = true;
      }
      titleText = createTitleText(context, currentDate);
      if (isLangChaged) {
        LocalizationUtils.setLocate(context, currentLang);
      }
    }

    rv.setTextViewText(R.id.titleTextView, titleText);
  }
  /**
   * Build localized (based on context!!!!) the page title for today, such as "March 21" or "21
   * Июля"
   *
   * @param context
   * @return
   */
  private static String createTitleText(Context context, Date date) {
    return LocalizationUtils.createLocalizedTitle(context, date);

    /*
            // Find current month and day
            Calendar calendar = new GregorianCalendar();
            calendar.setTime(date);
            int monthDay = calendar.get(Calendar.DAY_OF_MONTH);
            int month = calendar.get(Calendar.MONTH);

            Resources res = context.getResources();
            Configuration conf = res.getConfiguration();
            String lang = conf.locale.getLanguage();
            String[] monthNames = res.getStringArray(R.array.month_names);

            StringBuilder titleText = new StringBuilder();
            titleText.append(res.getString(R.string.title));
            if ("ru".equals(lang)) {
                titleText.append(" ");
                titleText.append(calendar.get(Calendar.DAY_OF_MONTH));
                titleText.append(" ");
                titleText.append(monthNames[month]);
            } else {
                titleText.append(" ");
                titleText.append(monthNames[month]);
                titleText.append(" ");
                titleText.append(monthDay);
            }



            return titleText.toString();
    */
  }
Beispiel #3
0
 public String getPageTitle() {
   String productTitle = getMessages().getMessage("product.name");
   String pageTitle = LocalizationUtils.getMessage(getPage().getMessages(), "title", null);
   if (pageTitle == null) {
     return productTitle;
   }
   return String.format("%s::%s", productTitle, pageTitle);
 }
Beispiel #4
0
 @Test
 public void testGetLocalizedElement() {
   // This should be independent of the actual build locale.
   LocalizedString[] elements = new LocalizedString[3];
   elements[0] = new LocalizedString("Hello World", "en");
   elements[1] = new LocalizedString("你好世界", "cn");
   elements[2] = new LocalizedString("Nom de plume!", "fr");
   LocalizedString testMatch = new LocalizedString("Nom de plume!", "fr");
   String[] locales = {"es", "fr", "en"};
   LocalizedString bestMatch = LocalizationUtils.getLocalizedElement(elements, locales);
   assertTrue(
       "Localized element best match returned correctly",
       bestMatch.getValue().equals(testMatch.getValue()));
 }
Beispiel #5
0
  @Test
  public void testProcessElementsByDefaultLocales() {
    // This will hopefully be independent of the real locale where the test
    // is run
    // Determine the "real" locales.
    GlobalizationPreferences prefs = new GlobalizationPreferences();
    ArrayList<ULocale> locales = (ArrayList<ULocale>) prefs.getLocales();
    assertNotNull("Locales array is not null", locales);

    // Set up a dummy list of strings. Last one will be the
    // correct one.
    LocalizedString[] elements = new LocalizedString[4];
    elements[0] = new LocalizedString("Hollow World", locales.get(0).toLanguageTag());
    elements[1] = new LocalizedString("Hello World", "xx-xx");
    elements[2] = new LocalizedString("你好世界", "xy-xx");
    elements[3] = new LocalizedString("Nom de plume!", "xz-xx");

    // Sort and test
    LocalizedString[] sortedElements = LocalizationUtils.processElementsByDefaultLocales(elements);
    assertNotNull("Sorted elements list is not null", sortedElements);
    assertTrue(
        "First element of processed list has expected value",
        sortedElements[0].getLang().equals(locales.get(0).toLanguageTag()));
  }
Beispiel #6
0
 @Test
 public void testIsValidLanguageTag() {
   boolean nullValue = LocalizationUtils.isValidLanguageTag(null);
   assertFalse("Null value handled properly", nullValue);
 }