weblate_sdk 0.2.1 copy "weblate_sdk: ^0.2.1" to clipboard
weblate_sdk: ^0.2.1 copied to clipboard

Unofficial WebLate SDK. Designed to work with WebLate web-based continuous localization system.

example/lib/main.dart

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

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await WebLateSdk.initialize(
    token: 'your token',
    host: 'your host',
    projectName: 'name of project',
    componentName: 'name of component',
    defaultLanguage: 'en',
    disableCache: false,
    //optional
    cacheLive: const Duration(days: 1),
    //optional
    fallbackJson: 'assets/default.json', //optional
  );
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({
    super.key,
  });

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      supportedLocales: WebLateSdk.supportedLocales,
      localizationsDelegates: [
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
        GlobalCupertinoLocalizations.delegate,
        WebLateSdk.delegate,
      ],
      home: WebLateSdk.isSDKInitialized
          ? const HomeScreen()
          : const InitializationErrorScreen(),
    );
  }
}

class HomeScreen extends StatelessWidget {
  const HomeScreen({
    super.key,
  });

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(context.localizedValueOf('tab_home')),
      ),
      extendBodyBehindAppBar: true,
      body: Center(
        child: Text(
          context.localizedValueOf(
            'test_welcoming',
            format: [
              'John Doe',
            ],
          ),
        ),
      ),
    );
  }
}

class InitializationErrorScreen extends StatelessWidget {
  const InitializationErrorScreen({
    super.key,
  });

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Initialization Error'),
      ),
      body: const Padding(
        padding: EdgeInsets.all(8.0),
        child: Center(
          child: Text(
            'Running app first time?\nPlease check your internet connection and try again.',
            textAlign: TextAlign.center,
          ),
        ),
      ),
    );
  }
}
11
likes
150
points
100
downloads

Publisher

unverified uploader

Weekly Downloads

Unofficial WebLate SDK. Designed to work with WebLate web-based continuous localization system.

Repository (GitHub)
View/report issues

Documentation

API reference

License

Apache-2.0 (license)

Dependencies

connectivity_plus, dio, flutter, flutter_web_plugins, internet_connection_checker_plus, json_annotation, json_serializable, plugin_platform_interface, shared_preferences

More

Packages that depend on weblate_sdk