All Projects → KingWu → gen_lang

KingWu / gen_lang

Licence: BSD-2-Clause license
gen_lang is a dart library for internationalization. Extracts messages to generate dart files required by Intl, inspired by Intl_translation and Flutter i18n

Programming Languages

dart
5743 projects
ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to gen lang

lang table
lang_table is a dart plugin to generate string files from a source. Use a table to manage all multi-language resources. Inspired by fetch-mobile-localization-from-airtable
Stars: ✭ 17 (-81.91%)
Mutual labels:  dart-library, flutter-plugin, flutter-plugins, flutter-package
barcode.flutter
barcode generate library for Flutter
Stars: ✭ 58 (-38.3%)
Mutual labels:  dart-library, flutter-plugin, flutter-package
Motion-Tab-Bar
A beautiful animated flutter widget package library. The tab bar will attempt to use your current theme out of the box, however you may want to theme it.
Stars: ✭ 237 (+152.13%)
Mutual labels:  dart-library, flutter-plugin, flutter-package
flutter sliding tutorial
User onboarding library with smooth animation of objects and background colors
Stars: ✭ 127 (+35.11%)
Mutual labels:  dart-library, flutter-plugin, flutter-package
flutter ume
UME is an in-app debug kits platform for Flutter. Produced by Flutter Infra team of ByteDance
Stars: ✭ 1,792 (+1806.38%)
Mutual labels:  dart-library, flutter-plugin, flutter-package
flutter-app
Full Feature Todos Flutter Mobile app with fireStore integration.
Stars: ✭ 138 (+46.81%)
Mutual labels:  flutter-plugin, flutter-package
seo renderer
A Flutter Web Plugin to display Text Widget as Html for SEO purpose
Stars: ✭ 103 (+9.57%)
Mutual labels:  flutter-plugin, flutter-package
FlutterLoadingGIFs
Loading indicator GIFs. Material and Cupertino (Android and iOS) loading indicators in assorted sizes. Use as placeholders for loading remote image assets. Demo: https://gallery.codelessly.com/flutterwebsites/loadinggifs/
Stars: ✭ 28 (-70.21%)
Mutual labels:  flutter-plugin, flutter-package
liquid button
Liquify your buttons, web demo at website
Stars: ✭ 18 (-80.85%)
Mutual labels:  flutter-plugin, flutter-package
fancy bar
A fancy yet beautiful animated widget for your Flutter apps
Stars: ✭ 33 (-64.89%)
Mutual labels:  flutter-plugin, flutter-package
simple gesture detector
Easy to use, reliable and lightweight gesture detector for Flutter apps, exposing simple API for basic gestures
Stars: ✭ 26 (-72.34%)
Mutual labels:  flutter-plugin, flutter-package
getwidget-docs
Get Widgets UI library docs.
Stars: ✭ 17 (-81.91%)
Mutual labels:  flutter-plugin, flutter-package
bloc
A predictable state management library that helps implement the BLoC design pattern
Stars: ✭ 12 (-87.23%)
Mutual labels:  dart-library, flutter-package
Free-RASP-Flutter
Flutter library for improving app security and threat monitoring on Android and iOS mobile devices.
Stars: ✭ 62 (-34.04%)
Mutual labels:  flutter-plugin, flutter-package
stop watch timer
This is Stop Watch Timer for flutter plugin.🏃‍♂️
Stars: ✭ 76 (-19.15%)
Mutual labels:  flutter-plugin, flutter-package
flutter flavorizr
A flutter utility to easily create flavors in your flutter application
Stars: ✭ 260 (+176.6%)
Mutual labels:  flutter-plugin, flutter-plugins
flutter wasm
WebAssembly interpreter for Flutter apps.
Stars: ✭ 22 (-76.6%)
Mutual labels:  dart-library, flutter-plugin
open route service
An encapsulation made around openrouteservice API for Dart and Flutter projects. Made for easy generation of Routes and Directions on Maps, Isochrones, Time-Distance Matrix, Pelias Geocoding, POIs, Elevation and routing Optimizations using their amazing API.
Stars: ✭ 20 (-78.72%)
Mutual labels:  dart-library, flutter-package
flutter google maps
A Flutter plugin for integrating Google Maps in iOS, Android and Web applications. It is a wrapper of google_maps_flutter for Mobile and google_maps for Web.
Stars: ✭ 86 (-8.51%)
Mutual labels:  flutter-plugin, flutter-package
flutter easyloading
✨A clean and lightweight loading/toast widget for Flutter, easy to use without context, support iOS、Android and Web
Stars: ✭ 1,021 (+986.17%)
Mutual labels:  flutter-plugin, flutter-package

gen_lang

gen_lang is a dart library for internationalization. Extracts messages to generate dart files required by Intl.

Now, three steps for internationalization

  1. Preparing Json files
  2. Run gen_lang
  3. Use it in coding

Installation

Add these libraries into pubspec.yaml

dependencies: 
    flutter_localizations: 
        sdk: flutter 
dev_dependencies:
    gen_lang: 0.1.3

Usage

pub run gen_lang:generate

A below table shown all supported arguments:

Argument Description
--source-dir A source folder contains all string json files (defaults to "res/string")
--output-dir A output folder stores all generated files (defaults to "lib/generated")
--template-locale Use string_{template-locale}.json as a template to search KEY. If string_en does not exist, this script will use the first string json file as a template (defaults to "en")

Source of Json Files

By default, the json files are required to locate at res/string. Using --source-dir argument can change the default source path. These files must be named in this pattern string_{Locale}.json

Example of the files,

|--- lib 
|--- res 
     |--- string 
         |--- string_en.json 
         |--- string_zh_TW.json 
         |--- string_ja.json 

Supported Message Type

Simple message

Define a json key and message without parameters

{ 
    "simpleMessage": "This is a simple Message"
}

Message with parameters

Define a message with parameters. Use ${parameterName} in a message.

{
    "messageWithParams": "Hi ${yourName}, Welcome you!"
}

Plural messages with parameters

Define messages in a plural form. ${how many} is a reserved parameter in a plural message. This parameters support integer only. For Intl, Intl.plural() supports these plural keyword including 'Zero', 'One', 'Two', 'Few', 'Many' and 'Other'. Define a json key into this pattern {jsonKey} {pluralKeyword}. For 'Other', need to define 'POther' for the plural keyword.

Example

{ 
    "pluralMessageZero": "Hi ${interviewerName}, I have no working experience.", 
    "pluralMessageOne": "Hi ${interviewerName}, I have one year working experience.", 
    "pluralMessageTwo": "Hi ${interviewerName}, I have two years of working experience.", 
    "pluralMessageFew": "Hi ${interviewerName}, I have few years of working experience.", 
    "pluralMessageMany": "Hi ${interviewerName}, I worked for a long time.", 
    "pluralMessagePOther": "Hi ${interviewerName}, I have ${howMany} years of working experience."
}

To know plural rules more, please read Intl's plural rules source code.

Gender message with parameters

Define a message in gender form. ${targetGender} is a reserved parameter in a gender message. This parameters support string value with 'male', female' and 'other'. For Intl, Intl.gender() supports these keyword including 'Male', 'Female' and 'Other'. Define a json key into this pattern {jsonKey} {genderKeyword}. For 'Other', need to define 'GOther' for the gender keyword.

Example

{ 
    "genderMessageMale": "Hi ${name}, He is boy.", 
    "genderMessageFemale": "Hi ${name}, She is girl", 
    "genderMessageGOther": "Hi ${name}, he/she is boy/girl." 
}

Usage of i18n.dart

The script will generate two files into the output folder including i18n.dart and messages_all.dart. Import i18n.dart into your source code. Then finish internationalization tasks.

Example

import 'package:gen_lang_example/generated/i18n.dart';

...

MaterialApp(
      localizationsDelegates: [
        S.delegate,
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate
      ],
      supportedLocales: S.delegate.supportedLocales,
      
      ...
      ...

        S.of(context).simpleMessage; // Simple Message 
        S.of(context).messageWithParams('developer'); // Message with parameters
        S.of(context).pluralMessage(10, 'King Wu'); // Plural Message with parameters
        S.of(context).genderMessage('male', 'King Wu'); // Gender Message with parameters

Running Script in Example

Go into example folder. Run the command

cd example
pub run gen_lang:generate

Then will generate i18n.dart and messages_all.dart

Powered By

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].