yaml_localizations 1.5.0 copy "yaml_localizations: ^1.5.0" to clipboard
yaml_localizations: ^1.5.0 copied to clipboard

A minimal YAML localization package built on LocalizationsDelegate.

example/lib/main.dart

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

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

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      localizationsDelegates: [
        ...GlobalMaterialLocalizations.delegates,
        YamlLocalizationsDelegate(
            path: 'assets/yaml_translations',
            assetBundle: DefaultAssetBundle.of(context)),
      ],
      supportedLocales: const [
        Locale('en', 'GB'),
        Locale('en', 'US'),
        Locale('en'),
        Locale('nb'),
      ],
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      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: const Text('yaml_localizations'),
      ),
      body: Column(
        mainAxisAlignment: MainAxisAlignment.start,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          Text(YamlLocalizations.of(context)?.string('Hi') ?? ''),
          const SizedBox(height: 12),
          Text(YamlLocalizations.of(context)?.string('Text') ?? ''),
          const SizedBox(height: 12),
          Text(YamlLocalizations.of(context)?.string('Long') ?? ''),
        ],
      ),
    );
  }
}
2
likes
150
pub points
25%
popularity

Publisher

verified publisherapptakk.com

A minimal YAML localization package built on LocalizationsDelegate.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter, yaml

More

Packages that depend on yaml_localizations