of static method

Retrieves the appropriate CallKitClientLocalizations instance.

This method provides a convenient way to get localizations with intelligent fallback logic:

  1. If DefaultLanguage is set to Chinese, returns Chinese localizations
  2. If DefaultLanguage is set to English, returns English localizations
  3. If context is provided, attempts to get localizations from the widget tree
  4. Falls back to system locale or defaults to English

The context parameter is optional. If provided, the method will attempt to retrieve localizations from the widget tree first.

Returns a CallKitClientLocalizations instance, never null (defaults to English if all other methods fail).

Example:

// With context
final localizations = S.of(context);

// Without context (uses default language or system locale)
final localizations = S.of();

Implementation

static CallKitClientLocalizations of([BuildContext? context]) {
  CallKitClientLocalizations? localizations;
  if (DefaultLanguage.defaultLanguage == languageZh) {
    return CallKitClientLocalizationsZh();
  }
  if (DefaultLanguage.defaultLanguage == languageEn) {
    return CallKitClientLocalizationsEn();
  }
  if (context != null) {
    localizations = CallKitClientLocalizations.of(context);
  }
  if (localizations == null) {
    var local = PlatformDispatcher.instance.locale;
    try {
      localizations = lookupCallKitClientLocalizations(local);
    } catch (e) {
      localizations = CallKitClientLocalizationsEn();
    }
  }
  return localizations;
}