Ejemplo n.º 1
0
static void init() {
  
  // Idioma local fijado (Ingles o Español)
  if(!strncmp(i18n_get_system_locale(), spanish_language, 5))
    setlocale(LC_ALL, "es_ES");
  else
    setlocale(LC_ALL, "en_US");
  
  // Inicializacion de las fuentes personalizadas (horas y minutos, y temperatura)
  s_font_temperature = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_TEMPERATURE_21));
  s_font_time = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_TIME_42));
  s_font_date = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_DATE_11));
  
  if(persist_exists(KEY_SAVED_FREQUENCY_UPDATE_WEATHER))
    freq_update_weather = persist_read_int(KEY_SAVED_FREQUENCY_UPDATE_WEATHER);
  else
    freq_update_weather = 60;
  
  // Creacion de la ventana principal y asignacion a un puntero
  s_main_window = window_create();

  // Creacion de handlers para gestionar los elementos en la ventana 
  window_set_window_handlers(s_main_window, (WindowHandlers) {
    .load = main_window_load,
    .unload = main_window_unload
  });
Ejemplo n.º 2
0
void locale_init(void) {
  //hard-coded for testing 
  //const char* locale_str = "de";

  // Detect system locale
  const char* locale_str = i18n_get_system_locale();
  ResHandle locale_handle = NULL;
  int locale_size = 0;

  if (strncmp(locale_str, "fr", 2) == 0) {
    locale_handle = resource_get_handle(RESOURCE_ID_LOCALE_FRENCH);
    locale_size = resource_size(locale_handle);
  } else if (strncmp(locale_str, "es", 2) == 0) {
    locale_handle = resource_get_handle(RESOURCE_ID_LOCALE_SPANISH);
    locale_size = resource_size(locale_handle);
  } else if (strncmp(locale_str, "de", 2) == 0) {
    locale_handle = resource_get_handle(RESOURCE_ID_LOCALE_GERMAN);
    locale_size = resource_size(locale_handle);
  }

  // Fallback to English for unlocalized languages (0 byte files)
  if (locale_size == 0) {
    locale_handle = resource_get_handle(RESOURCE_ID_LOCALE_ENGLISH);
    locale_size = resource_size(locale_handle);
  }

  int resource_offset = 0;
  int locale_entries = 0;
  resource_offset += resource_load_byte_range(locale_handle, resource_offset, 
      (uint8_t*)&locale_entries, sizeof(locale_entries));

  struct locale {
    int32_t hashval;
    int32_t strlen;
  } locale_info;

  int dict_buffer_size = locale_size + 7 * locale_entries; //7 byte header per item
  char *dict_buffer = malloc(dict_buffer_size);
  dict_write_begin(&s_locale_dict, (uint8_t*)dict_buffer, dict_buffer_size);

  for (int i = 0; i < locale_entries; i++) {
    resource_offset += resource_load_byte_range(locale_handle, resource_offset, 
        (uint8_t*)&locale_info, sizeof(struct locale));

    struct Tuplet tupl = {
      .type = TUPLE_CSTRING, 
      .key = locale_info.hashval, 
      .cstring.length = locale_info.strlen};

    tupl.cstring.data = malloc(tupl.cstring.length);

    resource_offset += resource_load_byte_range(locale_handle, 
        resource_offset, (uint8_t*)tupl.cstring.data, tupl.cstring.length);

    dict_write_tuplet(&s_locale_dict, &tupl);
  }

  dict_write_end(&s_locale_dict);
}

char *locale_str(int hashval) { 
  Tuple *tupl = dict_find(&s_locale_dict, hashval);

  if (tupl && tupl->value->cstring) {
    return tupl->value->cstring;
  }
  return "\7"; //return blank character
}