Exemple #1
0
void input_plaintext_detect_user_language(slice_index si)
{
  TraceFunctionEntry(__func__);
  TraceFunctionParamListEnd();

  UserLanguage = detect_user_language(ReadNextTokStr());

  if (UserLanguage==LanguageCount)
    output_plaintext_input_error_message(NoBegOfProblem, 0);
  else
  {
    output_plaintext_select_language(UserLanguage);
    output_message_initialise_language(UserLanguage);

    pipe_solve_delegate(si);
  }

  TraceFunctionExit(__func__);
  TraceFunctionResultEnd();
}
Exemple #2
0
/*
 * when lang is not NULL converts it to two-character language code
 * othwerise, tries to guess what language user wants from locale settings.
 * returns string of length 2 containig language code (to be freed by caller)
 * or NULL if not detected or unable to convert.
 */
char*
detect_lang(const char *lang)
{
  char *locname, *result, *cvt;

  atexit(codeset_free);
#ifdef HAVE_SETLOCALE
  /* No lang, detect locale, then CODESET, then try to transform it */
  if (!lang) {
    locname = detect_user_language();
    /* HERE: locname is (a) newly allocated (b) NULL */
    codeset = detect_target_charset(locname);
    /* HERE: codeset is (a) newly allocated, different from locname (b) NULL */
    cvt = locale_alias_convert(locname);
    result = strip_locale_name(cvt);
    enca_free(cvt);
    enca_free(locname);
    return result;
  }

  /* We have lang, try it first untransformed, then transformed for CODESET */
  codeset = detect_target_charset(lang);
  locname = locale_alias_convert(lang);
  if (!codeset)
    codeset = detect_target_charset(locname);
  result = strip_locale_name(locname);
  enca_free(locname);
  return result;

#else /* HAVE_SETLOCALE */
  cvt = locale_alias_convert(lang);
  result = strip_locale_name(cvt);
  enca_free(cvt);
  return result;
#endif /* HAVE_SETLOCALE */
}