lib/settings.js
async function setLocale (sim, opts, localeConfig = {}, safari = false) {
  if (!opts.language && !opts.locale && !opts.calendarFormat) {
    logger.debug('No reason to set locale');
    return {
      _updated: false,
    };
  }

  // we need the simulator to have its directories in place
  if (await sim.isFresh()) {
    await launchAndQuitSimulator(sim, safari);
  }

  logger.debug('Setting locale information');
  localeConfig = {
    language: opts.language || localeConfig.language,
    locale: opts.locale || localeConfig.locale,
    calendarFormat: opts.calendarFormat || localeConfig.calendarFormat,
    _updated: false,
  };

  try {
    let updated = await sim.updateLocale(opts.language, opts.locale, opts.calendarFormat);
    if (updated) {
      localeConfig._updated = true;
    }
  } catch (e) {
    logger.errorAndThrow(`Appium was unable to set locale info: ${e}`);
  }

  return localeConfig;
}
async function setLocale (sim, opts, localeConfig = {}, safari = false) {
  if (!opts.language && !opts.locale && !opts.calendarFormat) {
    logger.debug('No reason to set locale');
    return {
      _updated: false,
    };
  }

  // we need the simulator to have its directories in place
  if (await sim.isFresh()) {
    await launchAndQuitSimulator(sim, safari);
  }

  logger.debug('Setting locale information');
  localeConfig = {
    language: opts.language || localeConfig.language,
    locale: opts.locale || localeConfig.locale,
    calendarFormat: opts.calendarFormat || localeConfig.calendarFormat,
    _updated: false,
  };

  try {
    let updated = await sim.updateLocale(opts.language, opts.locale, opts.calendarFormat);
    if (updated) {
      localeConfig._updated = true;
    }
  } catch (e) {
    logger.errorAndThrow(`Appium was unable to set locale info: ${e}`);
  }

  return localeConfig;
}
async function setLocale ( sim , opts , localeConfig = { } , safari = false ) { if ( ! opts . language && ! opts . locale && ! opts . calendarFormat ) { logger . debug ( 'No reason to set locale' ) ; return { _updated : false , } ; } // we need the simulator to have its directories in place if ( await sim . isFresh ( ) ) { await launchAndQuitSimulator ( sim , safari ) ; } logger . debug ( 'Setting locale information' ) ; localeConfig = { language : opts . language || localeConfig . language , locale : opts . locale || localeConfig . locale , calendarFormat : opts . calendarFormat || localeConfig . calendarFormat , _updated : false , } ; try { let updated = await sim . updateLocale ( opts . language , opts . locale , opts . calendarFormat ) ; if ( updated ) { localeConfig . _updated = true ; } } catch ( e ) { logger . errorAndThrow ( ` ${ e } ` ) ; } return localeConfig ; }
pass in the simulator so that other systems that use the function can supply whatever they have
pass in the simulator so that other systems that use the function can supply whatever they have