Skip to content

Commit

Permalink
Merge pull request #235 from JordyHers-org/chore/43-implement-localiz…
Browse files Browse the repository at this point in the history
…ation-i18n-to-project-en-fr-de-ar-tr

Chore/43 implement localization i18n to project en fr de ar tr
  • Loading branch information
JordyHers authored Nov 8, 2023
2 parents 9a3b496 + 8585afe commit d029174
Show file tree
Hide file tree
Showing 12 changed files with 78 additions and 18 deletions.
32 changes: 32 additions & 0 deletions lib/app/features/parent_side/language/language_notififier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:ui';

import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:times_up_flutter/services/shared_preferences.dart';

class LanguageNotifier extends ChangeNotifier {
late String _selectedLanguage = '🇺🇸 English󠁢';
Expand All @@ -11,21 +12,52 @@ class LanguageNotifier extends ChangeNotifier {
Locale get locale => _locale;

List<String> languages = [
'🇺🇸 English󠁢',
'🇫🇷 Français󠁢',
'🇪🇸 Español',
'🇹🇷 Turkish',
'🇩🇪 Deutsch',
];

Future<void> initLocalization() async {
_locale = await CacheService.getLocale();
_setLanguageString();
languages
..insert(languages.indexOf(_selectedLanguage), _selectedLanguage)
..removeWhere((element) => element == _selectedLanguage);
notifyListeners();
}

void selectLanguage(String language) {
languages.insert(languages.indexOf(language), _selectedLanguage);
_selectedLanguage = language;
languages.removeWhere((element) => element == _selectedLanguage);
_locale = setLocale(_selectedLanguage);
CacheService.setLocale(value: _locale);
HapticFeedback.heavyImpact();
notifyListeners();
}

void _setLanguageString() {
switch (_locale.languageCode) {
case 'en':
_selectedLanguage = '🇺🇸 English󠁢';
break;
case 'fr':
_selectedLanguage = '🇫🇷 Français󠁢';
break;
case 'es':
_selectedLanguage = '🇪🇸 Español';
break;
case 'de':
_selectedLanguage = '🇩🇪 Deutsch';
break;
case 'tr':
_selectedLanguage = '🇹🇷 Turkish󠁢';
break;
}
}

Locale setLocale(String selectedLanguage) {
switch (selectedLanguage) {
case '🇫🇷 Français󠁢':
Expand Down
2 changes: 1 addition & 1 deletion lib/app/features/parent_side/language/language_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class _LanguagePageState extends State<LanguagePage> {
delegate: SliverChildListDelegate([
SingleChildScrollView(
child: SizedBox(
height: 2000,
height: 1000,
child: ListView.separated(
itemCount: 4,
itemBuilder: (builder, index) => GestureDetector(
Expand Down
8 changes: 5 additions & 3 deletions lib/app/features/parent_side/setting_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,11 @@ class SettingsPage extends StatelessWidget {
).vTopP(12),
ProfileListItem(
icon: LineAwesomeIcons.language,
onPressed: () => Navigator.of(context).push(MaterialPageRoute<void>(
builder: (context) => LanguagePage.create(context, auth),
)),
onPressed: () => Navigator.of(context).push(
MaterialPageRoute<void>(
builder: (context) => LanguagePage.create(context, auth),
),
),
text: 'Change language',
),
ProfileListItem(
Expand Down
23 changes: 13 additions & 10 deletions lib/l10n/arb/app_de.arb
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
{
"@@locale": "de",
"welcome": "Wilkommen",
"changeTheSettingsHere": "Ändern Sie hier die Einstellungen",
"addNewChildHere": "Fügen Sie hier ein neues Kind hinzu",
"operationFailed": "Operation failed",
"enterThisCode": "Enter this code on the child's device",
"longPressToCopyOrDoubleTapToShare": "Long press to copy or double tap to share",
"enterThisCodeOnChildDevice": "Enter this code on child's device: ",
"sendNotificationToYourChildDevice": "Send notifications to your Child's device",
"copyText" : "Code Copied!"
"@@locale": "de",
"welcome": "Wilkommen",
"hello": "Hallo 👋",
"changeTheSettingsHere": "Ändern Sie hier die Einstellungen",
"addNewChildHere": "Fügen Sie hier ein neues Kind hinzu",
"operationFailed": "Operation failed",
"enterThisCode": "Enter this code on the child's device",
"longPressToCopyOrDoubleTapToShare": "Long press to copy or double tap to share",
"enterThisCodeOnChildDevice": "Enter this code on child's device: ",
"sendNotificationToYourChildDevice": "Send notifications to your Child's device",
"copyText" : "Code Copied!"


}
1 change: 1 addition & 0 deletions lib/l10n/arb/app_en.arb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"@@locale": "en",
"welcome": "Welcome",
"hello": "Hello 👋",
"changeTheSettingsHere": "change the settings here",
"addNewChildHere": "Add a new child here ",
"operationFailed": "Operation failed",
Expand Down
3 changes: 2 additions & 1 deletion lib/l10n/arb/app_es.arb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"@@locale": "es",
"welcome": "Hola !",
"welcome": "Bienvenido !",
"hello": "Hola 👋",
"changeTheSettingsHere": "Cambiar la configuración aquí",
"addNewChildHere": "Añadir un nuevo niño[a] aquí",
"operationFailed": "Operation failed",
Expand Down
1 change: 1 addition & 0 deletions lib/l10n/arb/app_fr.arb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"@@locale": "fr",
"welcome": "Bienvenue",
"hello": "Salut 👋",
"changeTheSettingsHere": "Modifier les paramètres ici",
"addNewChildHere": "Ajoute un enfant ici",
"operationFailed": "Operation failed",
Expand Down
1 change: 1 addition & 0 deletions lib/l10n/arb/app_tr.arb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"@@locale": "tr",
"welcome": "Hoş Geldiniz",
"hello": "Selam 👋",
"changeTheSettingsHere": "Buradaki ayarları değiştir",
"addNewChildHere": "Buraya yeni bir çocuk ekleyin",
"operationFailed": "Operation failed",
Expand Down
2 changes: 1 addition & 1 deletion lib/main_development.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Future<void> main() async {
ChangeNotifierProvider<ThemeNotifier>(
create: (context) => ThemeNotifier()..initThemeMode()),
ChangeNotifierProvider<LanguageNotifier>(
create: (context) => LanguageNotifier()),
create: (context) => LanguageNotifier()..initLocalization(),),
ChangeNotifierProvider<AppInfoService>(
create: (context) => AppInfoService(packageInfo)),
],
Expand Down
14 changes: 14 additions & 0 deletions lib/services/shared_preferences.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:ui';

import 'package:shared_preferences/shared_preferences.dart';

class CacheService {
Expand Down Expand Up @@ -25,6 +27,12 @@ class CacheService {
return darkMode;
}

static Future<Locale> getLocale() async {
final preferences = await SharedPreferences.getInstance();
final status = preferences.getString('locale') ?? 'en';
return Locale(status);
}

static Future<void> setVisitingFlag() async {
final preferences = await SharedPreferences.getInstance();
await preferences.setBool('alreadyVisited', true);
Expand All @@ -51,4 +59,10 @@ class CacheService {
final status = await preferences.setBool('isDarkMode', value);
return status;
}

static Future<bool> setLocale({required Locale value}) async {
final preferences = await SharedPreferences.getInstance();
final locale = await preferences.setString('locale', value.languageCode);
return locale;
}
}
4 changes: 4 additions & 0 deletions lib/theme/theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ class AppTheme {
cardTheme: CardTheme(color: CustomColors.indigoDarker),
iconTheme: IconThemeData(color: CustomColors.indigoLight),
dividerColor: CustomColors.indigoLight,
bottomNavigationBarTheme: BottomNavigationBarThemeData(
selectedItemColor: CustomColors.greenPrimary,
unselectedItemColor: CustomColors.indigoLight,
),
floatingActionButtonTheme: FloatingActionButtonThemeData(
backgroundColor: CustomColors.indigoLight,
foregroundColor: CustomColors.indigoDark,
Expand Down
5 changes: 3 additions & 2 deletions lib/widgets/jh_header.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:times_up_flutter/l10n/l10n.dart';
import 'package:times_up_flutter/theme/theme.dart';
import 'package:times_up_flutter/widgets/jh_display_text.dart';

Expand All @@ -18,7 +19,7 @@ class JHHeader extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
JHDisplayText(
text: 'Hello 👋',
text: AppLocalizations.of(context).hello,
fontSize: fontSize,
maxFontSize: maxFontSize,
style: TextStyle(
Expand All @@ -27,7 +28,7 @@ class JHHeader extends StatelessWidget {
),
),
JHDisplayText(
text: 'Welcome',
text: AppLocalizations.of(context).welcome,
fontSize: fontSize,
maxFontSize: maxFontSize,
style: TextStyle(
Expand Down

0 comments on commit d029174

Please sign in to comment.