kurd_localization 2.0.0
kurd_localization: ^2.0.0 copied to clipboard
A Flutter localization package translations and Kurdish support.
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:kurd_localization/kurd_localization.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
Locale _currentLocale = const Locale('ckb');
void _changeLanguage(Locale locale) {
setState(() {
_currentLocale = locale;
});
}
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Kurd Localization Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(
seedColor: const Color(0xFF005b4f), // A nice dark green color
brightness: Brightness.light,
),
useMaterial3: true,
appBarTheme: const AppBarTheme(
centerTitle: true,
elevation: 0,
),
),
localizationsDelegates: [
KurdLocalizationDelegate.fromJson(
JsonAssetLoader(
path: 'assets/languages',
useSingleFile: false,
supportedLocales: const ['en', 'ckb', 'krm', 'ar'],
),
),
...kurdishLocalizations,
GlobalMaterialLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
],
supportedLocales: const [
Locale('en'),
Locale('ckb'),
Locale('krm'),
Locale('ar'),
],
locale: _currentLocale,
home: MyHomePage(
onLanguageChanged: _changeLanguage,
),
);
}
}
class MyHomePage extends StatefulWidget {
final Function(Locale) onLanguageChanged;
const MyHomePage({super.key, required this.onLanguageChanged});
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
String _gender = 'neutral';
void _incrementCounter() {
setState(() {
_counter++;
});
}
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final isRTL = Directionality.of(context) == TextDirection.rtl;
return Scaffold(
appBar: AppBar(
backgroundColor: theme.colorScheme.primaryContainer,
title: Text(
'Kurd Localization',
style: TextStyle(
fontWeight: FontWeight.bold,
color: theme.colorScheme.onPrimaryContainer,
),
),
actions: [
PopupMenuButton<Locale>(
icon: const Icon(Icons.language),
tooltip: 'Change Language',
onSelected: widget.onLanguageChanged,
itemBuilder: (context) => const [
PopupMenuItem(value: Locale('en'), child: Text('English')),
PopupMenuItem(value: Locale('ckb'), child: Text('کوردی (سۆرانی)')),
PopupMenuItem(value: Locale('krm'), child: Text('Kurdî (Kurmancî)')),
PopupMenuItem(value: Locale('ar'), child: Text('العربية')),
],
),
],
),
body: SingleChildScrollView(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
_buildFeatureCard(
context,
title: 'Basic Translation',
icon: Icons.translate,
child: Text(
context.kt('hello', args: {'name': 'Khalis'}),
style: theme.textTheme.titleLarge,
textAlign: TextAlign.center,
),
),
const SizedBox(height: 16),
_buildFeatureCard(
context,
title: 'Pluralization',
icon: Icons.format_list_numbered,
child: Column(
children: [
Text(
context.ktPlural('items', _counter),
style: theme.textTheme.headlineSmall?.copyWith(
fontWeight: FontWeight.bold,
color: theme.colorScheme.primary,
),
),
const SizedBox(height: 16),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton.icon(
onPressed: () {
if (_counter > 0) setState(() => _counter--);
},
icon: const Icon(Icons.remove),
label: const Text('Decrease'),
),
const SizedBox(width: 16),
ElevatedButton.icon(
onPressed: _incrementCounter,
icon: const Icon(Icons.add),
label: const Text('Increase'),
),
],
),
],
),
),
const SizedBox(height: 16),
_buildFeatureCard(
context,
title: 'Gender Support',
icon: Icons.people,
child: Column(
children: [
Text(
context.kt('welcome', gender: _gender, args: {'name': 'Alex'}),
style: theme.textTheme.titleMedium,
textAlign: TextAlign.center,
),
const SizedBox(height: 16),
SegmentedButton<String>(
segments: const [
ButtonSegment(value: 'male', label: Text('Male')),
ButtonSegment(value: 'female', label: Text('Female')),
ButtonSegment(value: 'neutral', label: Text('Neutral')),
],
selected: {_gender},
onSelectionChanged: (Set<String> newSelection) {
setState(() {
_gender = newSelection.first;
});
},
),
],
),
),
const SizedBox(height: 16),
_buildFeatureCard(
context,
title: 'Language Information',
icon: Icons.info_outline,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_buildInfoRow('Current Locale:', context.currentLocale.languageCode),
_buildInfoRow('Is RTL:', isRTL ? 'Yes' : 'No'),
_buildInfoRow('Is Kurdish:', context.isKurdish ? 'Yes' : 'No'),
],
),
),
],
),
),
floatingActionButton: FloatingActionButton.extended(
onPressed: _incrementCounter,
icon: const Icon(Icons.add),
label: const Text('Add Item'),
),
);
}
Widget _buildFeatureCard(
BuildContext context, {
required String title,
required IconData icon,
required Widget child,
}) {
final theme = Theme.of(context);
return Card(
child: Padding(
padding: const EdgeInsets.all(20.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Icon(icon, color: theme.colorScheme.primary),
const SizedBox(width: 12),
Text(
title,
style: theme.textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.bold,
),
),
],
),
const Divider(height: 32),
Center(child: child),
],
),
),
);
}
Widget _buildInfoRow(String label, String value) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 4.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(label, style: const TextStyle(fontWeight: FontWeight.w500)),
Text(value),
],
),
);
}
}