diff --git a/assets/translations/en-US.json b/assets/translations/en-US.json index 6e6f10c..b239b4b 100644 --- a/assets/translations/en-US.json +++ b/assets/translations/en-US.json @@ -79,5 +79,8 @@ "quiz_description_label": "Short Description", "quiz_subject_label": "Subject", "make_quiz_public": "Make Quiz Public", - "save_quiz": "Save Quiz" + "save_quiz": "Save Quiz", + + "select_language": "Select Language", + "change_language": "Change Language" } diff --git a/assets/translations/id-ID.json b/assets/translations/id-ID.json index 6bb4eb6..345ee7d 100644 --- a/assets/translations/id-ID.json +++ b/assets/translations/id-ID.json @@ -2,7 +2,7 @@ "greeting_time": "Selamat Siang", "greeting_user": "Halo {user}", "create_room": "Buat Ruangan", - "join_room": "Gabung Ruangan", + "join_room": "Gabung Ruang", "create_quiz": "Buat Kuis", "ready_new_challenge": "Siap untuk tantangan baru?", "search_or_select_category": "Cari atau pilih berdasarkan kategori", @@ -79,5 +79,8 @@ "quiz_description_label": "Deskripsi Singkat", "quiz_subject_label": "Mata Pelajaran", "make_quiz_public": "Jadikan Kuis Publik", - "save_quiz": "Simpan Kuis" + "save_quiz": "Simpan Kuis", + + "select_language": "Pilih Bahasa", + "change_language": "Ganti Bahasa" } diff --git a/lib/app/app.dart b/lib/app/app.dart index 1e707e3..9c22969 100644 --- a/lib/app/app.dart +++ b/lib/app/app.dart @@ -1,6 +1,6 @@ import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; -import 'package:get/get_navigation/src/root/get_material_app.dart'; +import 'package:get/get.dart'; import 'package:quiz_app/app/bindings/initial_bindings.dart'; import 'package:quiz_app/app/routes/app_pages.dart'; @@ -10,11 +10,11 @@ class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return GetMaterialApp( - localizationsDelegates: context.localizationDelegates, - debugShowCheckedModeBanner: false, - supportedLocales: context.supportedLocales, - locale: context.locale, title: 'Quiz App', + locale: Get.locale ?? context.locale, // 🔁 This ensures GetX reacts to locale changes + fallbackLocale: const Locale('en', 'US'), + localizationsDelegates: context.localizationDelegates, + supportedLocales: context.supportedLocales, initialBinding: InitialBindings(), initialRoute: AppRoutes.splashScreen, getPages: AppPages.routes, diff --git a/lib/feature/profile/controller/profile_controller.dart b/lib/feature/profile/controller/profile_controller.dart index 52f29f0..3fe93d7 100644 --- a/lib/feature/profile/controller/profile_controller.dart +++ b/lib/feature/profile/controller/profile_controller.dart @@ -1,3 +1,6 @@ +import 'dart:ui'; +import 'package:easy_localization/easy_localization.dart'; +import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:quiz_app/app/routes/app_pages.dart'; import 'package:quiz_app/core/utils/logger.dart'; @@ -38,4 +41,10 @@ class ProfileController extends GetxController { void editProfile() { logC.i("Edit profile pressed"); } + + void changeLanguage(BuildContext context, String languageCode, String countryCode) async { + final locale = Locale(languageCode, countryCode); + await context.setLocale(locale); + Get.updateLocale(locale); + } } diff --git a/lib/feature/profile/view/profile_view.dart b/lib/feature/profile/view/profile_view.dart index 748bc70..ee948db 100644 --- a/lib/feature/profile/view/profile_view.dart +++ b/lib/feature/profile/view/profile_view.dart @@ -37,6 +37,12 @@ class ProfileView extends GetView { controller.editProfile, ), const SizedBox(height: 12), + _buildActionButton( + context.tr("change_language"), + Icons.language, + () => _showLanguageDialog(context), + ), + const SizedBox(height: 12), _buildActionButton( context.tr("logout"), Icons.logout, @@ -126,4 +132,34 @@ class ProfileView extends GetView { ), ); } + + void _showLanguageDialog(BuildContext context) { + showDialog( + context: context, + builder: (_) => AlertDialog( + title: Text(context.tr("select_language")), + content: Column( + mainAxisSize: MainAxisSize.min, + children: [ + ListTile( + leading: const Icon(Icons.language), + title: const Text("English"), + onTap: () { + controller.changeLanguage(context, 'en', 'US'); + Navigator.of(context).pop(); + }, + ), + ListTile( + leading: const Icon(Icons.language), + title: const Text("Bahasa Indonesia"), + onTap: () { + controller.changeLanguage(context, 'id', "ID"); + Navigator.of(context).pop(); + }, + ), + ], + ), + ), + ); + } } diff --git a/lib/main.dart b/lib/main.dart index 1ecc580..2f584e3 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -16,7 +16,6 @@ void main() { ]); WidgetsFlutterBinding.ensureInitialized(); - await EasyLocalization.ensureInitialized(); runApp( @@ -24,9 +23,11 @@ void main() { supportedLocales: [ Locale('en', 'US'), Locale('id', 'ID'), + Locale('ms', 'MY'), ], path: 'assets/translations', fallbackLocale: Locale('en', 'US'), + useOnlyLangCode: false, child: MyApp(), ), );