weblate_sdk 0.0.10 copy "weblate_sdk: ^0.0.10" to clipboard
weblate_sdk: ^0.0.10 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: 'your project name',
    componentName: 'your component name',
    defaultLanguage: 'en',
    //optional
    disableCache: false,
    //optional
    cacheLive: const Duration(days: 1),
    //optional
    fallbackJson: 'assets/default.json',
  );
  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('tabHome')),
      ),
      body: Center(
        child: Text(context.localizedValueOf('lets_go')),
      ),
    );
  }
}

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
0
pub points
53%
popularity

Publisher

unverified uploader

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

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

dio, flutter, flutter_web_plugins, hive, hive_flutter, plugin_platform_interface, shared_preferences

More

Packages that depend on weblate_sdk