Giter Club home page Giter Club logo

phrase-flutter-sdk's Introduction

Phrase Strings OTA for Flutter

Library for Phrase Strings over-the-air translations.

Installation

Important: this library depends on 0.17.0 version of Flutter's intl library. Please follow this guide to add localizations support to your app.

Add the phrase dependency to your pubspec.yaml:

dependencies:
  phrase: ^1.0.5
  ...
  intl: ^0.17.0
  flutter_localizations:
    sdk: flutter
  ...

flutter:
  generate: true
  ...

Just like intl library, phrase uses code generation to process your ARB files.

To keep it up-to-date, just run this command:

$ flutter pub run phrase

or if you're using build_runner:

$ flutter pub run build_runner watch

Usage

Initialize Phrase Strings in your main.dart file:

import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:flutter_gen/gen_l10n/phrase_localizations.dart';
import 'package:phrase/phrase.dart';

void main() {
  Phrase.setup("[DISTRIBUTION_ID]", "[ENVIRONMENT_ID]");
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      //..
      localizationsDelegates: PhraseLocalizations.localizationsDelegates,
      supportedLocales: PhraseLocalizations.supportedLocales,
    );
  }
}

That's it! You can access your messages just like you did before:

Text(AppLocalizations.of(context)!.helloWorld);

But now your app will check for updated translations in Phrase regularly and download them in the background.

Customization

Update behavior

By default, Phrase Strings will update OTA translations every time the app launches.

You can disable this behavior:

Phrase.setup("[DISTRIBUTION_ID]", "[ENVIRONMENT_ID]", checkForUpdates: false);

and trigger updates manually:

Phrase.updateTranslations(context).then((_) => print("Done!"));

Api host

By default phrase uses european host. But we can set it to use the US api host if needed. To do so, we just have to set it up during initial setup:

Phrase.setup("[DISTRIBUTION_ID]", "[ENVIRONMENT_ID]", host: PhraseHost.us);

Custom app version

The SDK will use the app version by default to return a release which matches the release constraints for the min and max version. The app version has to use semantic versioning otherwise no translation update will be returned. In case your app does not use semantic versioning it is possible to manually override the app version:

Phrase.setup("[DISTRIBUTION_ID]", "[ENVIRONMENT_ID]", customAppVersion: "1.2.3");

phrase-flutter-sdk's People

Contributors

kiruel avatar docstun avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.