zooper_flutter_localization

Creator: coderz1093

Last updated:

0 purchases

zooper_flutter_localization Image
zooper_flutter_localization Images
Add to Cart

Description:

zooper flutter localization

zooper_flutter_localization #
A simple localization library which aims to have multiple localization files.
This lib is aimed to work with get_it or injectable,
but it should works for any other framework.
Example #
This example aims to use this package with injectable, but you should be able to implement it with any other framework, or even without
Importing #
Add this line to your pubspec.yaml:
zooper_flutter_localization: <latest>
copied to clipboard
and inside your dart class:
import 'package:zooper_flutter_localization/zooper_flutter_localization.dart';
copied to clipboard
Registering with injectable #
If you want to register a localizer for a specific View (better use ViewModels if you use the MVVM Pattern),
you can define a Module with injectable:
import 'package:injectable/injectable.dart';
import 'package:zooper_flutter_localization/zooper_flutter_localization.dart';

@module
abstract class LocalizationModule {
LocalizationService get localizationService;

// Register a named localization
@preResolve
@Named('Titles')
Future<ZooperLocalizer> titlesLocalizations(LocalizationService localizationService) =>
localizationService.loadAsync('assets/localizations/titles.csv');

// Register an other named localization
@preResolve
@Named('Errors')
Future<ZooperLocalizer> errorsLocalizations(LocalizationService localizationService) =>
localizationService.loadAsync('assets/localizations/errors.csv');

// Register an unnamed localization but with an explicit type
@preResolve
Future<ZooperLocalizer<MainViewModel>> viewModelLocalizations(LocalizationService localizationService) =>
localizationService.loadAsync('assets/localizations/errors.csv');
}
copied to clipboard
This registers a ZooperLocalizer and loads the translations from the defined file.
Then you can inject it easily:
class TestView {
final ZooperLocalizer<TestViewModel> _localizer;

TestView(this._localizer);
}
copied to clipboard
or
class TestView {
final ZooperLocalizer _localizer;

TestView(@Named('YourName') this._localizer);
}
copied to clipboard
Accessing a translation #
This can be done in multiple ways. Easist is this:
_localizer['Hello'];
copied to clipboard
but you can do also:
_localizer.getLocalization('Hello');
copied to clipboard
or with a specific locale:
_localizer.getLocalizationByLocale('Hello', Locale('de', 'DE'))
copied to clipboard

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.