smsimone / flutter-ditto

Flutter sdk to integrate Dittowords localizations inside your Flutter app

Home Page:https://pub.dev/packages/flutter_ditto

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

wakatime

Flutter_ditto

This packages aims to provide a simple integration with Dittowords localizations like it's done on React by ditto-react.

Like my work?

"Buy Me A Coffee"

TODOS

  • OTA updates for the translations
  • Translations with plurals
  • Translations with variables

Quick start

To integrate Ditto inside your app you simply have to replace the current MaterialApp with DittoMaterialApp.

Separated initialization

You can initialize DittoStore separately from DittoMaterialApp like

Future<void> main() async {
    WidgetsFlutterBinding.ensureInitialized();

    await DittoStore().initialize(
        configs: DittoConfigData.base(
        projectId: '<YOUR_PROJECT_ID>',
        apiKey: '<YOUR_API_KEY>',
        ),
    );

    runApp(const MyApp());
}

// ...

class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return DittoMaterialApp(
      title: 'Ditto test',
      fallbackLocale: const Locale('en'),
      home: const MyHomePage(),
    );
  }
}

Integrated initialization

Here you can let the DittoMaterialApp component handle the DittoStore initialization simply by giving it the DittoConfigData

//...

class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return DittoMaterialApp(
      title: 'Ditto test',
      fallbackLocale: const Locale('en'),
      home: const MyHomePage(),
      configData: DittoConfigData.base(
        projectId: '<YOUR_PROJECT_ID>',
        apiKey: '<YOUR_API_KEY>',
      ),
      loadingPlaceholder: Container(
        color: Theme.of(context).primaryColor,
        child: const Center(
          child: CircularProgressIndicator(color: Colors.white),
        ),
      ),
    );
  }
}

Translations

As you wrapped your app with DittoMaterialApp, you can now translate your texts by using the String.translate() extension.

/// For a simple translation
'simple_key'.translate()

/// For a translation with a variable
'variable_key'.translate({'var_name': 'var_value'})
/// If you want to hide a variable, use `null`
'variable_key'.translate({'var_name': null})

/// For a translation with plurals
'plural_key'.translate({'var_name': 'var_value'}, 2)

About

Flutter sdk to integrate Dittowords localizations inside your Flutter app

https://pub.dev/packages/flutter_ditto

License:GNU General Public License v3.0


Languages

Language:Dart 94.4%Language:Ruby 3.5%Language:Swift 1.8%Language:Kotlin 0.2%Language:Objective-C 0.0%Language:Shell 0.0%