Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 30 additions & 4 deletions lib/sdk_flutter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,39 @@ export 'src/types.dart';
class DiditSdk {
static Map<String, dynamic> _verificationConfig(DiditConfig? config) {
final resolvedConfig = config?.toMap() ?? <String, dynamic>{};
resolvedConfig.putIfAbsent(
'languageCode',
() => WidgetsBinding.instance.platformDispatcher.locale.languageCode,
);
resolvedConfig.putIfAbsent('languageCode', _deviceLanguageCode);
return resolvedConfig;
}

/// The device locale as the native SDK names it.
///
/// The native SDKs distinguish Simplified and Traditional Chinese and
/// Brazilian Portuguese with their own codes, so the two-letter language
/// alone would send those users to the generic variant.
static String _deviceLanguageCode() {
final locale = WidgetsBinding.instance.platformDispatcher.locale;
final country = locale.countryCode?.toUpperCase();
final script = locale.scriptCode?.toLowerCase();

switch (locale.languageCode) {
case 'zh':
if (script == 'hant' ||
country == 'TW' ||
country == 'HK' ||
country == 'MO') {
return 'zh-TW';
}
if (script == 'hans' || country == 'CN' || country == 'SG') {
return 'zh-CN';
}
return 'zh';
case 'pt':
return country == 'BR' ? 'pt-BR' : 'pt';
default:
return locale.languageCode;
}
}

/// Start identity verification with an existing session token.
///
/// This launches the native Didit verification UI as a full-screen modal.
Expand Down
34 changes: 30 additions & 4 deletions packages/didit_sdk_autodetection/lib/sdk_flutter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,39 @@ export 'src/types.dart';
class DiditSdk {
static Map<String, dynamic> _verificationConfig(DiditConfig? config) {
final resolvedConfig = config?.toMap() ?? <String, dynamic>{};
resolvedConfig.putIfAbsent(
'languageCode',
() => WidgetsBinding.instance.platformDispatcher.locale.languageCode,
);
resolvedConfig.putIfAbsent('languageCode', _deviceLanguageCode);
return resolvedConfig;
}

/// The device locale as the native SDK names it.
///
/// The native SDKs distinguish Simplified and Traditional Chinese and
/// Brazilian Portuguese with their own codes, so the two-letter language
/// alone would send those users to the generic variant.
static String _deviceLanguageCode() {
final locale = WidgetsBinding.instance.platformDispatcher.locale;
final country = locale.countryCode?.toUpperCase();
final script = locale.scriptCode?.toLowerCase();

switch (locale.languageCode) {
case 'zh':
if (script == 'hant' ||
country == 'TW' ||
country == 'HK' ||
country == 'MO') {
return 'zh-TW';
}
if (script == 'hans' || country == 'CN' || country == 'SG') {
return 'zh-CN';
}
return 'zh';
case 'pt':
return country == 'BR' ? 'pt-BR' : 'pt';
default:
return locale.languageCode;
}
}

/// Start identity verification with an existing session token.
///
/// This launches the native Didit verification UI as a full-screen modal.
Expand Down
34 changes: 30 additions & 4 deletions packages/didit_sdk_core/lib/sdk_flutter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,39 @@ export 'src/types.dart';
class DiditSdk {
static Map<String, dynamic> _verificationConfig(DiditConfig? config) {
final resolvedConfig = config?.toMap() ?? <String, dynamic>{};
resolvedConfig.putIfAbsent(
'languageCode',
() => WidgetsBinding.instance.platformDispatcher.locale.languageCode,
);
resolvedConfig.putIfAbsent('languageCode', _deviceLanguageCode);
return resolvedConfig;
}

/// The device locale as the native SDK names it.
///
/// The native SDKs distinguish Simplified and Traditional Chinese and
/// Brazilian Portuguese with their own codes, so the two-letter language
/// alone would send those users to the generic variant.
static String _deviceLanguageCode() {
final locale = WidgetsBinding.instance.platformDispatcher.locale;
final country = locale.countryCode?.toUpperCase();
final script = locale.scriptCode?.toLowerCase();

switch (locale.languageCode) {
case 'zh':
if (script == 'hant' ||
country == 'TW' ||
country == 'HK' ||
country == 'MO') {
return 'zh-TW';
}
if (script == 'hans' || country == 'CN' || country == 'SG') {
return 'zh-CN';
}
return 'zh';
case 'pt':
return country == 'BR' ? 'pt-BR' : 'pt';
default:
return locale.languageCode;
}
}

/// Start identity verification with an existing session token.
///
/// This launches the native Didit verification UI as a full-screen modal.
Expand Down
34 changes: 30 additions & 4 deletions packages/didit_sdk_nfc/lib/sdk_flutter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,39 @@ export 'src/types.dart';
class DiditSdk {
static Map<String, dynamic> _verificationConfig(DiditConfig? config) {
final resolvedConfig = config?.toMap() ?? <String, dynamic>{};
resolvedConfig.putIfAbsent(
'languageCode',
() => WidgetsBinding.instance.platformDispatcher.locale.languageCode,
);
resolvedConfig.putIfAbsent('languageCode', _deviceLanguageCode);
return resolvedConfig;
}

/// The device locale as the native SDK names it.
///
/// The native SDKs distinguish Simplified and Traditional Chinese and
/// Brazilian Portuguese with their own codes, so the two-letter language
/// alone would send those users to the generic variant.
static String _deviceLanguageCode() {
final locale = WidgetsBinding.instance.platformDispatcher.locale;
final country = locale.countryCode?.toUpperCase();
final script = locale.scriptCode?.toLowerCase();

switch (locale.languageCode) {
case 'zh':
if (script == 'hant' ||
country == 'TW' ||
country == 'HK' ||
country == 'MO') {
return 'zh-TW';
}
if (script == 'hans' || country == 'CN' || country == 'SG') {
return 'zh-CN';
}
return 'zh';
case 'pt':
return country == 'BR' ? 'pt-BR' : 'pt';
default:
return locale.languageCode;
}
}

/// Start identity verification with an existing session token.
///
/// This launches the native Didit verification UI as a full-screen modal.
Expand Down
Loading
Loading