-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #76 from mario-bermonti:mario-bermonti/issue75
Translate demographics survey elements into Spanish
- Loading branch information
Showing
6 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_localizations/flutter_localizations.dart'; | ||
import 'package:research_package/research_package.dart'; | ||
|
||
/// default locale | ||
const Locale locale = Locale('es'); | ||
|
||
const List<Locale> supportedLocales = <Locale>[ | ||
Locale('es'), | ||
Locale('en'), | ||
]; | ||
|
||
final List<LocalizationsDelegate> localizationsDelegates = | ||
<LocalizationsDelegate>[ | ||
RPLocalizations.delegate, | ||
GlobalMaterialLocalizations.delegate, | ||
GlobalWidgetsLocalizations.delegate, | ||
GlobalCupertinoLocalizations.delegate, | ||
]; | ||
|
||
/// Resolves the [Locale] to the last one in the list of [supportedLocales] | ||
/// if the [locale] is unsupported. | ||
Locale? resolveLocale(Locale? locale, Iterable<Locale>? supportedLocales) { | ||
if (locale == null || supportedLocales == null) { | ||
return null; | ||
} | ||
for (Locale supportedLocale in supportedLocales) { | ||
if (supportedLocale.languageCode == locale.languageCode) { | ||
return supportedLocale; | ||
} | ||
} | ||
return supportedLocales.last; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:mdigit_span_tasks_ema/src/intl/internationalization.dart'; | ||
|
||
void main() { | ||
group('resolveLocale', () { | ||
test( | ||
"Given valid locale and supported locales, returns the locale.", | ||
() { | ||
const Locale expectedLocale = Locale('en'); | ||
final Iterable<Locale> supportedLocales = <Locale>[ | ||
const Locale('en'), | ||
const Locale('es'), | ||
]; | ||
|
||
final Locale? actualLocale = resolveLocale( | ||
expectedLocale, | ||
supportedLocales, | ||
); | ||
|
||
expect(actualLocale, expectedLocale); | ||
}, | ||
); | ||
}); | ||
test( | ||
"""Given an unsupported locale and valid supported locales, | ||
returns Locale('es').""", | ||
() { | ||
const Locale locale = Locale('fr'); | ||
final Iterable<Locale> supportedLocales = <Locale>[ | ||
const Locale('en'), | ||
const Locale('es'), | ||
]; | ||
|
||
final Locale? actualLocale = resolveLocale( | ||
locale, | ||
supportedLocales, | ||
); | ||
|
||
expect(actualLocale, supportedLocales.last); | ||
}, | ||
); | ||
test( | ||
"Given a null locale and valid supported locales, returns null.", | ||
() { | ||
final Iterable<Locale> supportedLocales = <Locale>[ | ||
const Locale('en'), | ||
const Locale('es'), | ||
]; | ||
|
||
final Locale? actualLocale = resolveLocale( | ||
null, | ||
supportedLocales, | ||
); | ||
|
||
expect(actualLocale, isNull); | ||
}, | ||
); | ||
} |