Coder Social home page Coder Social logo

magnatronus / polylingual-package Goto Github PK

View Code? Open in Web Editor NEW
4.0 1.0 2.0 64 KB

A Flutter package for creating multi language apps

License: Apache License 2.0

Java 3.57% Ruby 21.67% Objective-C 7.39% Dart 67.37%
flutter package plug-in locale translate language

polylingual-package's Introduction

polylingual

PolyLingual is a plug-in that provides a means of storing and updating String translations for a Flutter app. These translations are defined and updated using a simple JSON file similar to the one below.

{
    "en": {
        "greeting": "Hello, how are you?",
        "welcome": "you're welcome, my friend",
        "thankyou": "thank you very much",
        "good": "very well",
        "about": "Information"

    },
    "es": {
        "greeting": "¿Hola como estas?",
        "welcome": "de nada amiga",
        "thankyou": "muchas gracias",
        "good": "muy bien",
        "about": "Información"

    }
}

How PolyLingual Works

The first thing you MUST do is initialise PolyLingual with a default Translation map (or load the existing one). This is done in main() before the main widget is loaded to make sure we have all the strings available.

void main() async {

  // set our required default(fallback) language and initialise PolyLingual
  PolyLingual.defaultLanguageCode = "es";
  await PolyLingual.initialise("res/strings.json");


  // run your app here
  runApp(DemoApp());
  
}

You also need to do the following to the project pubspec.yaml file

  flutter_localizations:
    sdk: flutter 

as well as define and add an initial translation string file as an asset (see example for more details)

  assets:
  #  - images/a_dot_burr.jpeg
  #  - images/a_dot_ham.jpeg
    - res/strings.json

Then, whenever you need to display a localised string somewhere just use

PolyLingual.of(context).string("greeting")

where 'greeting' is a key in the translation file (take a look at the example strings.json file for the correct format).

Updating the Translation Map

You can also update the app translation map using a new translation file in case you need to update an existing string or correct a typo. In the example this is hard coded, but your app could have check for updates button that would download the new file and auto update the translations.

iOS

Please note that for iOS you will also need to add any supported languages to the Runner info.plist file. Read here for more info

Getting Started

Take a look at the example project to see how to use PolyLingual to create a multi language app that can be updated simply by providng an updated JSON file.

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

polylingual-package's People

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 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.