smart_translate_lints 1.0.2 smart_translate_lints: ^1.0.2 copied to clipboard
Smart Translate Lints is a custom linting plugin for Flutter that helps catch missing translation strings in your code.
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:localization/localization.dart';
import 'locale_keys.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
LocalJsonLocalization.delegate.directories = ['lib/i18n'];
return MaterialApp(
title:
'Flutter Demo', // this example not using locale keys will warn in the IDE
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: const MyHomePage(
title:
'Flutter Demo Home Page'), // this example not using locale keys will warn in the IDE
localizationsDelegates: [
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
LocalJsonLocalization.delegate,
],
supportedLocales: const [
Locale('en', ''),
Locale('ar', ''),
],
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(widget
.title), // this example not using locale keys will warn in the IDE
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text(
'not translated text',
), // this example not using locale keys and not translated will warn in the IDE
Text('translated text'
.i18n()), // this example not using locale keys will warn in the IDE
Text(LocaleKeys.translated_text
.i18n()), // this example using locale keys and translated will not warn in the IDE
],
),
),
);
}
}