Instantly see how your translations fit on a real device while you type
Screens on mobile devices are small and it is hard to match the texts for different languages at the first attempt. It is painful to constantly rebuild apps with new texts just to see if the changed text fits into the intended place. Luckily, Localizely offers In-Context Editing for Flutter apps.
You can type translations in Localizely platform and instantly see how given text appears on your device or in a browser. If it is too long for the intended place, if it breaks into multiple lines and similar. Knowing the context in which translations are used and how they fit into the rest of the app will help you to increase the translation quality.
However, we should keep in mind that In-Context Editing is not a replacement for the regular translation method. In fact, it is an extension of the regular way that allows us to be more productive. It is intended only for the development and testing phases as such translation changes only exist while you are connected to the platform.
The most commonly used approach to localize Flutter apps is with the intl package and tools around it. Thus, in the following sections, we will explain how to integrate In-Context Editing into such Flutter projects.
The Flutter Intl is an IDE plugin that generates the necessary boilerplate code for the intl
package. We have already explained how to configure localization with the Flutter Intl plugin. Therefore, we will not spend more words on that. Instead, we will show you how to enable In-Context Editing in such projects.
All code samples used in this guide are available on the GitHub repo.
The first thing we need to do is to add localizely_sdk
dependency.
dependencies:
flutter:
sdk: flutter
flutter_localizations:
sdk: flutter
intl: ^0.17.0
localizely_sdk: ^2.5.0
Once we've added the dependency to the pubspec.yaml
file, run the following command to download it.
flutter pub get
Next, update the flutter_intl
config with the ota_enabled
within the pubspec.yaml
file so that the Flutter Intl plugin can generate necessary metadata.
flutter_intl:
enabled: true
localizely:
ota_enabled: true
The next step is to wrap the root of the app with the LocalizelyInContextEditing
widget. For that purpose, let's update the main.dart
file.
...
import 'package:localizely_sdk/localizely_sdk.dart';
void main() {
runApp(
LocalizelyInContextEditing(
enabled: true, // set to false to disable In-Context Editing for production app builds
child: MyApp(),
),
);
}
...
The last step we need to do is to run the app and connect with Localizely. On app startup, you will see the page that will guide you to connect. Basically, you will need to enter a token from Localizely to establish connection.
To access the token, go to the Translations page of your project on the Localizely platform and click on the button. This will open a dialog with all the necessary data.
Now that we have everything prepared, let's connect.
If everything went well, you should see a message that you are successfully connected.
Note: The localizely_sdk >=2.4.0 <2.5.0
requires an update of min platform versions:
- Android: Required Android SDK 21 or newer (update minSdkVersion
to 21
in the android/app/build.gradle
file).
- iOS: Required iOS 11 or newer and an update of the Info.plist
file with the NSCameraUsageDescription
.
As of version 2.5.0
, these updates are no longer required due to changes in implementation.
Note: The localizely_sdk >=2.4.0 <2.5.0
uses the QR code scanner on mobile apps to connect. This way of connecting is abandoned. In case you are prompted to scan the QR code, please update the localizely_sdk
to the latest available version.
Finally, start translating your content on the Localizely platform, and at the same time, see how it fits on a real device as you type.
Not long ago, Flutter introduced the gen_l10n
tool as a new way of localization. This tool automatically generates necessary localization files during the build phase. We have already explained how to configure localization with the gen_l10n tool. Therefore, we will not spend more words on that. Instead, we will show you how to enable In-Context Editing in such projects.
All code samples used in this guide are available on the GitHub repo.
The first thing we need to do is to add localizely_sdk
dependency.
dependencies:
flutter:
sdk: flutter
flutter_localizations:
sdk: flutter
intl: ^0.17.0
localizely_sdk: ^2.5.0
Once we've added the dependency to the pubspec.yaml
file, run the following command to download it.
flutter pub get
The second thing we need to do is to generate localization files with the localizely_sdk
. To do that, let's run the command shown below.
dart run localizely_sdk:generate
Note: In Flutter 3.22.0, running the command dart run localizely_sdk:generate
may produce false analyzer errors. This issue has been resolved in Flutter 3.22.1. If you need to use 3.22.0 and encounter these errors, running flutter pub get
again should fix the problem.
To automatically run code generation each time your arb files change, you should add build_runner
package to dev_dependencies
and run watch
command.
flutter pub add build_runner -d
flutter pub run build_runner watch
Once we've generated required localization files, let's update localizationsDelegates
and supportedLocales
props of the MaterialApp
widget.
...
import 'package:flutter_gen/gen_l10n/localizely_localizations.dart';
class MyApp extends StatelessWidget {
...
@override
Widget build(BuildContext context) {
return MaterialApp(
...
localizationsDelegates: LocalizelyLocalizations.localizationsDelegates,
supportedLocales: LocalizelyLocalizations.supportedLocales,
...
);
}
}
The next step is to wrap the root of the app with the LocalizelyInContextEditing
widget. For that purpose, let's update the main.dart
file.
...
import 'package:localizely_sdk/localizely_sdk.dart';
void main() {
runApp(
LocalizelyInContextEditing(
enabled: true, // set to false to disable In-Context Editing for production app builds
child: MyApp(),
),
);
}
...
The last step we need to do is to run the app and connect with Localizely. On app startup, you will see the page that will guide you to connect. Basically, you will need to enter a token from Localizely to establish connection.
To access the token, go to the Translations page of your project on the Localizely platform and click on the button. This will open a dialog with all the necessary data.
Now that we have everything prepared, let's connect.
If everything went well, you should see a message that you are successfully connected.
Note: The localizely_sdk >=2.4.0 <2.5.0
requires an update of min platform versions:
- Android: Required Android SDK 21 or newer (update minSdkVersion
to 21
in the android/app/build.gradle
file).
- iOS: Required iOS 11 or newer and an update of the Info.plist
file with the NSCameraUsageDescription
.
As of version 2.5.0
, these updates are no longer required due to changes in implementation.
Note: The localizely_sdk >=2.4.0 <2.5.0
uses the QR code scanner on mobile apps to connect. This way of connecting is abandoned. In case you are prompted to scan the QR code, please update the localizely_sdk
to the latest available version.
Finally, start translating your content on the Localizely platform, and at the same time, see how it fits on a real device as you type.
Previous: Flutter Over-the-air updates
Read next: Project branching
Tired of manually editing translation files?
Our platform streamlines software localization for you.