lazy_loc 0.0.6
lazy_loc: ^0.0.6 copied to clipboard
LazyLoc is a lightweight localization package for Flutter that automates translation file management and provides a simple `.tr()` extension for string translation.
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:lazy_loc/lazy_loc.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'LazyLoc Demo',
// 1. Register supported locales
supportedLocales: const [
Locale('ko'), // Korean
Locale('en'), // English
],
// 2. Register delegates (this is the connection!)
localizationsDelegates: const [
lazyLocDelegate, // Our custom delegate
// Flutter default widget delegates
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
home: const MyHomePage(),
);
}
}
class MyHomePage extends StatelessWidget {
const MyHomePage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('app_title'.tr()),
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'hello'.tr(),
style: Theme.of(context).textTheme.headlineMedium,
),
const SizedBox(height: 16),
Text('world'.tr(), style: Theme.of(context).textTheme.bodyLarge),
const SizedBox(height: 16),
Text(
'welcome_message'.tr(),
style: Theme.of(context).textTheme.bodyMedium,
),
],
),
),
);
}
}