https://github.com/smsimone/flutter-ditto
Flutter sdk to integrate Dittowords localizations inside your Flutter app
https://github.com/smsimone/flutter-ditto
ditto dittowords flutter-localizations localizations remote-localization
Last synced: 4 months ago
JSON representation
Flutter sdk to integrate Dittowords localizations inside your Flutter app
- Host: GitHub
- URL: https://github.com/smsimone/flutter-ditto
- Owner: smsimone
- License: gpl-3.0
- Created: 2022-06-08T17:10:29.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2023-01-19T09:26:17.000Z (over 3 years ago)
- Last Synced: 2026-01-11T16:21:14.762Z (5 months ago)
- Topics: ditto, dittowords, flutter-localizations, localizations, remote-localization
- Language: Dart
- Homepage: https://pub.dev/packages/flutter_ditto
- Size: 281 KB
- Stars: 9
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://wakatime.com/badge/user/6de661cc-aaf6-48d1-b19c-3b8aa8990b73/project/e121e3ca-b7f1-4bf2-a1f7-25c659090e38)
# Flutter_ditto
This packages aims to provide a simple integration with Dittowords localizations like it's done on React by [ditto-react](https://www.npmjs.com/package/ditto-react).
> Like my work?
>
> [](https://www.buymeacoffee.com/smsimone)
## TODOS
- [x] OTA updates for the translations
- [x] Translations with plurals
- [x] Translations with variables
## Quick start
To integrate Ditto inside your app you simply have to replace the current `MaterialApp` with `DittoMaterialApp`.
### Separated initialization
You can initialize `DittoStore` separately from `DittoMaterialApp` like
```dart
Future main() async {
WidgetsFlutterBinding.ensureInitialized();
await DittoStore().initialize(
configs: DittoConfigData.base(
projectId: '',
apiKey: '',
),
);
runApp(const MyApp());
}
// ...
class _MyAppState extends State {
@override
Widget build(BuildContext context) {
return DittoMaterialApp(
title: 'Ditto test',
fallbackLocale: const Locale('en'),
home: const MyHomePage(),
);
}
}
```
### Integrated initialization
Here you can let the `DittoMaterialApp` component handle the `DittoStore` initialization simply by giving it the `DittoConfigData`
```dart
//...
class _MyAppState extends State {
@override
Widget build(BuildContext context) {
return DittoMaterialApp(
title: 'Ditto test',
fallbackLocale: const Locale('en'),
home: const MyHomePage(),
configData: DittoConfigData.base(
projectId: '',
apiKey: '',
),
loadingPlaceholder: Container(
color: Theme.of(context).primaryColor,
child: const Center(
child: CircularProgressIndicator(color: Colors.white),
),
),
);
}
}
```
## Translations
As you wrapped your app with `DittoMaterialApp`, you can now translate your texts by using the `String.translate()` extension.
```dart
/// For a simple translation
'simple_key'.translate()
/// For a translation with a variable
'variable_key'.translate({'var_name': 'var_value'})
/// If you want to hide a variable, use `null`
'variable_key'.translate({'var_name': null})
/// For a translation with plurals
'plural_key'.translate({'var_name': 'var_value'}, 2)
```