Skip to content

Commit

Permalink
refactor(deriv_localizations): added a string for deriv_passkeys package
Browse files Browse the repository at this point in the history
  • Loading branch information
bassam-deriv committed May 13, 2024
1 parent 30fb509 commit 9ccd8db
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,6 @@
"addMorePasskeysButtonText": "Add More Passkeys",
"unableToSetupPasskey": "Unable to setup passkey",
"unableToSetupPasskeyDescription": "We encountered an issue while setting up your passkey. The process might have been interrupted, or the session timed out. Please try again.",
"passkeysOffErrorTitle": "The Passkeys service is unavailable"
"passkeysOffErrorTitle": "The Passkeys service is unavailable",
"never": "Never"
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,18 @@ import 'deriv_auth_localizations_zh.dart';
/// be consistent with the languages listed in the DerivAuthLocalizations.supportedLocales
/// property.
abstract class DerivAuthLocalizations {
DerivAuthLocalizations(String locale) : localeName = intl.Intl.canonicalizedLocale(locale.toString());
DerivAuthLocalizations(String locale)
: localeName = intl.Intl.canonicalizedLocale(locale.toString());

final String localeName;

static DerivAuthLocalizations? of(BuildContext context) {
return Localizations.of<DerivAuthLocalizations>(context, DerivAuthLocalizations);
static DerivAuthLocalizations of(BuildContext context) {
return Localizations.of<DerivAuthLocalizations>(
context, DerivAuthLocalizations)!;
}

static const LocalizationsDelegate<DerivAuthLocalizations> delegate = _DerivAuthLocalizationsDelegate();
static const LocalizationsDelegate<DerivAuthLocalizations> delegate =
_DerivAuthLocalizationsDelegate();

/// A list of this localizations delegate along with the default localizations
/// delegates.
Expand All @@ -95,7 +98,8 @@ abstract class DerivAuthLocalizations {
/// Additional delegates can be added by appending to this list in
/// MaterialApp. This list does not have to be used at all if a custom list
/// of delegates is preferred or required.
static const List<LocalizationsDelegate<dynamic>> localizationsDelegates = <LocalizationsDelegate<dynamic>>[
static const List<LocalizationsDelegate<dynamic>> localizationsDelegates =
<LocalizationsDelegate<dynamic>>[
delegate,
GlobalMaterialLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
Expand Down Expand Up @@ -652,49 +656,83 @@ abstract class DerivAuthLocalizations {
String get labelLanguage;
}

class _DerivAuthLocalizationsDelegate extends LocalizationsDelegate<DerivAuthLocalizations> {
class _DerivAuthLocalizationsDelegate
extends LocalizationsDelegate<DerivAuthLocalizations> {
const _DerivAuthLocalizationsDelegate();

@override
Future<DerivAuthLocalizations> load(Locale locale) {
return SynchronousFuture<DerivAuthLocalizations>(lookupDerivAuthLocalizations(locale));
return SynchronousFuture<DerivAuthLocalizations>(
lookupDerivAuthLocalizations(locale));
}

@override
bool isSupported(Locale locale) => <String>['ar', 'bn', 'de', 'en', 'es', 'fr', 'it', 'ko', 'pl', 'pt', 'ru', 'si', 'sw', 'th', 'tr', 'vi', 'zh'].contains(locale.languageCode);
bool isSupported(Locale locale) => <String>[
'ar',
'bn',
'de',
'en',
'es',
'fr',
'it',
'ko',
'pl',
'pt',
'ru',
'si',
'sw',
'th',
'tr',
'vi',
'zh'
].contains(locale.languageCode);

@override
bool shouldReload(_DerivAuthLocalizationsDelegate old) => false;
}

DerivAuthLocalizations lookupDerivAuthLocalizations(Locale locale) {


// Lookup logic when only language code is specified.
switch (locale.languageCode) {
case 'ar': return DerivAuthLocalizationsAr();
case 'bn': return DerivAuthLocalizationsBn();
case 'de': return DerivAuthLocalizationsDe();
case 'en': return DerivAuthLocalizationsEn();
case 'es': return DerivAuthLocalizationsEs();
case 'fr': return DerivAuthLocalizationsFr();
case 'it': return DerivAuthLocalizationsIt();
case 'ko': return DerivAuthLocalizationsKo();
case 'pl': return DerivAuthLocalizationsPl();
case 'pt': return DerivAuthLocalizationsPt();
case 'ru': return DerivAuthLocalizationsRu();
case 'si': return DerivAuthLocalizationsSi();
case 'sw': return DerivAuthLocalizationsSw();
case 'th': return DerivAuthLocalizationsTh();
case 'tr': return DerivAuthLocalizationsTr();
case 'vi': return DerivAuthLocalizationsVi();
case 'zh': return DerivAuthLocalizationsZh();
case 'ar':
return DerivAuthLocalizationsAr();
case 'bn':
return DerivAuthLocalizationsBn();
case 'de':
return DerivAuthLocalizationsDe();
case 'en':
return DerivAuthLocalizationsEn();
case 'es':
return DerivAuthLocalizationsEs();
case 'fr':
return DerivAuthLocalizationsFr();
case 'it':
return DerivAuthLocalizationsIt();
case 'ko':
return DerivAuthLocalizationsKo();
case 'pl':
return DerivAuthLocalizationsPl();
case 'pt':
return DerivAuthLocalizationsPt();
case 'ru':
return DerivAuthLocalizationsRu();
case 'si':
return DerivAuthLocalizationsSi();
case 'sw':
return DerivAuthLocalizationsSw();
case 'th':
return DerivAuthLocalizationsTh();
case 'tr':
return DerivAuthLocalizationsTr();
case 'vi':
return DerivAuthLocalizationsVi();
case 'zh':
return DerivAuthLocalizationsZh();
}

throw FlutterError(
'DerivAuthLocalizations.delegate failed to load unsupported locale "$locale". This is likely '
'an issue with the localizations generation tool. Please file an issue '
'on GitHub with a reproducible sample app and the gen-l10n configuration '
'that was used.'
);
'DerivAuthLocalizations.delegate failed to load unsupported locale "$locale". This is likely '
'an issue with the localizations generation tool. Please file an issue '
'on GitHub with a reproducible sample app and the gen-l10n configuration '
'that was used.');
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,18 @@ import 'deriv_passkeys_localizations_en.dart';
/// be consistent with the languages listed in the DerivPasskeysLocalizations.supportedLocales
/// property.
abstract class DerivPasskeysLocalizations {
DerivPasskeysLocalizations(String locale) : localeName = intl.Intl.canonicalizedLocale(locale.toString());
DerivPasskeysLocalizations(String locale)
: localeName = intl.Intl.canonicalizedLocale(locale.toString());

final String localeName;

static DerivPasskeysLocalizations? of(BuildContext context) {
return Localizations.of<DerivPasskeysLocalizations>(context, DerivPasskeysLocalizations);
static DerivPasskeysLocalizations of(BuildContext context) {
return Localizations.of<DerivPasskeysLocalizations>(
context, DerivPasskeysLocalizations)!;
}

static const LocalizationsDelegate<DerivPasskeysLocalizations> delegate = _DerivPasskeysLocalizationsDelegate();
static const LocalizationsDelegate<DerivPasskeysLocalizations> delegate =
_DerivPasskeysLocalizationsDelegate();

/// A list of this localizations delegate along with the default localizations
/// delegates.
Expand All @@ -79,17 +82,16 @@ abstract class DerivPasskeysLocalizations {
/// Additional delegates can be added by appending to this list in
/// MaterialApp. This list does not have to be used at all if a custom list
/// of delegates is preferred or required.
static const List<LocalizationsDelegate<dynamic>> localizationsDelegates = <LocalizationsDelegate<dynamic>>[
static const List<LocalizationsDelegate<dynamic>> localizationsDelegates =
<LocalizationsDelegate<dynamic>>[
delegate,
GlobalMaterialLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
];

/// A list of this localizations delegate's supported locales.
static const List<Locale> supportedLocales = <Locale>[
Locale('en')
];
static const List<Locale> supportedLocales = <Locale>[Locale('en')];

/// No description provided for @passkeyCreatedSuccessTitle.
///
Expand Down Expand Up @@ -392,33 +394,34 @@ abstract class DerivPasskeysLocalizations {
String get never;
}

class _DerivPasskeysLocalizationsDelegate extends LocalizationsDelegate<DerivPasskeysLocalizations> {
class _DerivPasskeysLocalizationsDelegate
extends LocalizationsDelegate<DerivPasskeysLocalizations> {
const _DerivPasskeysLocalizationsDelegate();

@override
Future<DerivPasskeysLocalizations> load(Locale locale) {
return SynchronousFuture<DerivPasskeysLocalizations>(lookupDerivPasskeysLocalizations(locale));
return SynchronousFuture<DerivPasskeysLocalizations>(
lookupDerivPasskeysLocalizations(locale));
}

@override
bool isSupported(Locale locale) => <String>['en'].contains(locale.languageCode);
bool isSupported(Locale locale) =>
<String>['en'].contains(locale.languageCode);

@override
bool shouldReload(_DerivPasskeysLocalizationsDelegate old) => false;
}

DerivPasskeysLocalizations lookupDerivPasskeysLocalizations(Locale locale) {


// Lookup logic when only language code is specified.
switch (locale.languageCode) {
case 'en': return DerivPasskeysLocalizationsEn();
case 'en':
return DerivPasskeysLocalizationsEn();
}

throw FlutterError(
'DerivPasskeysLocalizations.delegate failed to load unsupported locale "$locale". This is likely '
'an issue with the localizations generation tool. Please file an issue '
'on GitHub with a reproducible sample app and the gen-l10n configuration '
'that was used.'
);
'DerivPasskeysLocalizations.delegate failed to load unsupported locale "$locale". This is likely '
'an issue with the localizations generation tool. Please file an issue '
'on GitHub with a reproducible sample app and the gen-l10n configuration '
'that was used.');
}

0 comments on commit 9ccd8db

Please sign in to comment.