Localization GetX

 import "package:flutter/material.dart";

import "package:get/get.dart";
import "package:getx_state_management/Ripples_Code/languages.dart";

void main() {
runApp(const MyApp());
}

class MyApp extends StatelessWidget {
const MyApp({super.key});

@override
Widget build(BuildContext context) {
return GetMaterialApp(
title: "Localization",
debugShowCheckedModeBanner: false,
locale: const Locale("en", "US"),
translations: Languages(),
fallbackLocale: const Locale("en", "US"),
theme: ThemeData(
primarySwatch: Colors.grey,
),
home: const HomeScreen(),
);
}
}

class HomeScreen extends StatefulWidget {
const HomeScreen({super.key});

@override
State<HomeScreen> createState() {
return HomeScreenState();
}
}

class HomeScreenState extends State<HomeScreen> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text(
"GetX Localization",
style: TextStyle(fontWeight: FontWeight.bold),
),
centerTitle: true,
backgroundColor: Colors.grey,
),
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
ListTile(
title: Text(
"message".tr,
style:
const TextStyle(fontWeight: FontWeight.bold, fontSize: 20.0),
),
subtitle: Text("name".tr),
),
const SizedBox(height: 30.0),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(
onPressed: () {
Get.updateLocale(
const Locale("en", "US"),
);
},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.blue,
),
child: const Text(
"English",
style: TextStyle(
fontWeight: FontWeight.bold, color: Colors.white),
),
),
const SizedBox(width: 20.0),
ElevatedButton(
onPressed: () {
Get.updateLocale(
const Locale("ur", "PK"),
);
},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.blue,
),
child: const Text(
"Urdu",
style: TextStyle(
fontWeight: FontWeight.bold, color: Colors.white),
),
),
const SizedBox(width: 20.0),
ElevatedButton(
onPressed: () {
Get.updateLocale(
const Locale("gu", "GJ"),
);
},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.blue,
),
child: const Text(
"Gujarati",
style: TextStyle(
fontWeight: FontWeight.bold, color: Colors.white),
),
),
const SizedBox(width: 20.0),
ElevatedButton(
onPressed: () {
Get.updateLocale(
const Locale("hi", "HI"),
);
},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.blue,
),
child: const Text(
"Hindi",
style: TextStyle(
fontWeight: FontWeight.bold, color: Colors.white),
),
),
const SizedBox(width: 20.0),
ElevatedButton(
onPressed: () {
Get.updateLocale(
const Locale("pu", "PU"),
);
},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.blue,
),
child: const Text(
"Punjabi",
style: TextStyle(
fontWeight: FontWeight.bold, color: Colors.white),
),
),
const SizedBox(width: 20.0),
ElevatedButton(
onPressed: () {
Get.updateLocale(
const Locale("ml", "ML"),
);
},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.blue,
),
child: const Text(
"Malayalam",
style: TextStyle(
fontWeight: FontWeight.bold, color: Colors.white),
),
),
const SizedBox(width: 20.0),
ElevatedButton(
onPressed: () {
Get.updateLocale(
const Locale("si", "SI"),
);
},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.blue,
),
child: const Text(
"Sindhi",
style: TextStyle(
fontWeight: FontWeight.bold, color: Colors.white),
),
),
],
),
const SizedBox(height: 50.0),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(
onPressed: () {
Get.updateLocale(
const Locale("tm", "TM"),
);
},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.blue,
),
child: const Text(
"Tamil",
style: TextStyle(
fontWeight: FontWeight.bold, color: Colors.white),
),
),
const SizedBox(width: 20.0),
ElevatedButton(
onPressed: () {
Get.updateLocale(
const Locale("gr", "GR"),
);
},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.blue,
),
child: const Text(
"German",
style: TextStyle(
fontWeight: FontWeight.bold, color: Colors.white),
),
),
const SizedBox(width: 20.0),
ElevatedButton(
onPressed: () {
Get.updateLocale(
const Locale("fr", "FR"),
);
},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.blue,
),
child: const Text(
"French",
style: TextStyle(
fontWeight: FontWeight.bold, color: Colors.white),
),
),
const SizedBox(width: 20.0),
ElevatedButton(
onPressed: () {
Get.updateLocale(
const Locale("jp", "JP"),
);
},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.blue,
),
child: const Text(
"Japanese",
style: TextStyle(
fontWeight: FontWeight.bold, color: Colors.white),
),
),
const SizedBox(width: 20.0),
ElevatedButton(
onPressed: () {
Get.updateLocale(
const Locale("rs", "RS"),
);
},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.blue,
),
child: const Text(
"Russian",
style: TextStyle(
fontWeight: FontWeight.bold, color: Colors.white),
),
),
],
),
],
),
);
}
}
import "package:get/get.dart";

class Languages extends Translations
{
@override
Map<String, Map<String, String>> get keys => {
"en_US" : {
"message" : "What is your name ?",
"name" : "Sachin Pilot"
},

"ur_PK" : {
"message" : "آپ کا نام کیا ہے ؟",
"name" : "سچن پائلٹ"
},

"gu_GJ" : {
"message" : "તમારું નામ શું છે ?",
"name" : "સચિન પાયલટ"
},

"hi_HI" : {
"message" : "आपका क्या नाम है ?",
"name" : "सचिन पायलट"
},

"pu_PU" : {
"message" : "ਤੁਹਾਡਾ ਨਾਮ ਕੀ ਹੈ ?",
"name" : "ਸਚਿਨ ਪਾਇਲਟ"
},

"ml_ML" : {
"message" : "എന്താണ് നിന്റെ പേര് ?",
"name" : "സച്ചിൻ പൈലറ്റ്"
},

"si_SI" : {
"message" : "توهان جو نالو ڇا آهي ؟",
"name" : "سچن پائلٽ"
},

"tm_TM" : {
"message" : "உங்கள் பெயர் என்ன ?",
"name" : "சச்சின் பைலட்"
},

"gr_GR" : {
"message" : "Wie heißt du ?",
"name" : "Sachin-Pilot"
},

"fr_FR" : {
"message" : "Quel est ton nom ?",
"name" : "Pilote Sachin"
},

"jp_JP" : {
"message" : "あなたの名前は何ですか ?",
"name" : "サチンパイロット"
},

"rs_RS" : {
"message" : "Как вас зовут ?",
"name" : "Сачин Пилот"
},
};
}

Comments

Popular posts from this blog

Pagination with Bloc Pattern in Flutter

Pagination First Practical in Flutter

ExpansionPanel with ExpansionPanelList with Complete Collapse Operation in Flutter