minimal_localizations 0.2.0 icon indicating copy to clipboard operation
minimal_localizations: ^0.2.0 copied to clipboard

Minimal localization given a map of translations per language.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:minimal_localizations/minimal_localizations.dart';
import 'package:flutter_localizations/flutter_localizations.dart';

extension LocalizedString on String {
  String tr(BuildContext context) {
    return MinimalLocalizations.of(context).string(this);
  }
}

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

final minimalLocalizationsDelegate = MinimalLocalizationsDelegate({
  'en': {
    'title': 'Localizations',
    'hello': 'Hello',
  },
  'nb-NO': {
    'title': 'Lokaliseringer',
    'hello': 'Hei',
  },
});

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      localizationsDelegates: [
        ...GlobalMaterialLocalizations.delegates,
        minimalLocalizationsDelegate,
      ],
      supportedLocales: minimalLocalizationsDelegate.supportedLocales(),
      home: const MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key}) : super(key: key);

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('title'.tr(context)),
      ),
      body: Center(
        child: Text('hello'.tr(context)),
      ),
    );
  }
}
1
likes
140
pub points
31%
popularity

Publisher

verified publisher iconapptakk.com

Minimal localization given a map of translations per language.

Repository (GitHub)
View/report issues

Documentation

API reference

License

Icon for licenses.MIT (LICENSE)

Dependencies

flutter

More

Packages that depend on minimal_localizations