Skip to content

Commit

Permalink
Updated version to 1.2.5
Browse files Browse the repository at this point in the history
  • Loading branch information
bratan committed Oct 14, 2019
1 parent ee34192 commit a0d060f
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@
## [1.2.2]

- Missing localizations now return the full key path.

## [1.2.5]

- Fixed possible exception when adding an extra slash to the ```basePath```
130 changes: 124 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,17 @@ It lets you define translations for your content in different languages and swit
<img src="https://raw.githubusercontent.com/leadcode/flutter_translate/master/assets/gifs/flutter_translate_screen.gif" width="300"/>

## Table of Contents
* [Installation](#installation)
* [Usage](#usage)
- [Installation](#installation)
- [Configuration](#configuration)
- [Usage](#usage)

## Installation

Add this to your package's pubspec.yaml file:

```sh
dependencies:
flutter_translate: ^1.2.2
flutter_translate: ^1.2.5
```

Install packages from the command line (or from your editor):
Expand All @@ -32,10 +33,127 @@ Install packages from the command line (or from your editor):
flutter pub get
```

## Usage
## Configuration

In your Dart code, you can use:
Import flutter_translate:

```sh
```dart
import 'package:flutter_translate/flutter_translate.dart';
```

Place the *json* localization files in a folder of your choice within the project.

By default ```flutter_translate``` will search for localization files in the `assets/i18n` directory in your project's root.

Declare your assets localization directory in ```pubspec.yaml```

```sh
flutter:
assets:
- assets/i18n
```

In the main function create the localization delegate and start the app, wrapping it with LocalizedApp

```dart
void main() async
{
var delegate = await LocalizationDelegate.create(
fallbackLanguage: 'en',
supportedLanguages: ['en', 'es_ES', 'fa']);
runApp(LocalizedApp(delegate, MyApp()));
}
```

If the assets directory for the localization files is different than the default one (```assets/i18n```), you need to specify it:

```dart
void main() async
{
var delegate = await LocalizationDelegate.create(
fallbackLanguage: 'en',
supportedLanguages: ['en', 'es_ES', 'fa'],
basePath: 'assets/i18n/');
runApp(LocalizedApp(delegate, MyApp()));
}
```

Example MyApp:

```dart
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
var localizationDelegate = LocalizedApp.of(context).delegate;
return LocalizationProvider(
state: LocalizationProvider.of(context).state,
child: MaterialApp(
title: 'Flutter Translate Demo',
localizationsDelegates: [
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
localizationDelegate
],
supportedLocales: localizationDelegate.configuration.supportedLocales,
locale: localizationDelegate.currentLocale,
theme: ThemeData(primarySwatch: Colors.blue),
home: MyHomePage(),
),
);
}
}
```

## Usage

Translate a string:

```dart
translate('your.localization.key');
```

Translate with arguments;

```dart
translate('your.localization.key', args: {'argName1': argValue1, 'argName2': argValue2});
```

Translate with pluralization:

```dart
translatePlural('plural.demo', yourNumericValue);
```

JSON:

```json
"plural": {
"demo": {
"0": "Please start pushing the 'plus' button.",
"1": "You have pushed the button one time.",
"else": "You have pushed the button {{value}} times."
}
}
```

Change the language:

```dart
@override
Widget build(BuildContext context) {
...
...
changeLanguage(context, 'en');
...
...
}
```

### You can view the full example here:

[https://github.com/leadcode/flutter_translate/blob/master/example/lib/main.dart](https://github.com/leadcode/flutter_translate/blob/master/example/lib/main.dart)
2 changes: 1 addition & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ description: Example project for the flutter_translate library
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.2.0
version: 1.2.5

environment:
sdk: ">=2.1.0 <3.0.0"
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_translate
description: The internationalization (i18n) library for Flutter. It lets you define translations for your content in different languages and switch between them easily.
version: 1.2.2
version: 1.2.5
author: Leadcode <[email protected]>
homepage: https://github.com/leadcode/flutter_translate

Expand Down

0 comments on commit a0d060f

Please sign in to comment.