text stringlengths 1 372 |
|---|
app for release. |
<topic_end> |
<topic_start> |
learn more |
to learn more about flutter and accessibility, check out |
the following articles written by community members: |
<topic_end> |
<topic_start> |
internationalizing flutter apps |
<topic_end> |
<topic_start> |
what you'll learn |
if your app might be deployed to users who speak another |
language then you’ll need to internationalize it. |
that means you need to write the app in a way that makes |
it possible to localize values like text and layouts |
for each language or locale that the app supports. |
flutter provides widgets and classes that help with |
internationalization and the flutter libraries |
themselves are internationalized. |
this page covers concepts and workflows necessary to |
localize a flutter application using the |
MaterialApp and CupertinoApp classes, |
as most apps are written that way. |
however, applications written using the lower level |
WidgetsApp class can also be internationalized |
using the same classes and logic. |
<topic_end> |
<topic_start> |
introduction to localizations in flutter |
this section provides a tutorial on how to create and |
internationalize a new flutter application, |
along with any additional setup |
that a target platform might require. |
you can find the source code for this example in |
gen_l10n_example. |
<topic_end> |
<topic_start> |
setting up an internationalized app: the flutter_localizations package |
by default, flutter only provides US english localizations. |
to add support for other languages, |
an application must specify additional |
MaterialApp (or CupertinoApp) properties, |
and include a package called flutter_localizations. |
as of december 2023, this package supports 115 languages |
and language variants. |
to begin, start by creating a new flutter application |
in a directory of your choice with the flutter create command. |
to use flutter_localizations, |
add the package as a dependency to your pubspec.yaml file, |
as well as the intl package: |
this creates a pubspec.yml file with the following entries: |
<code_start> |
dependencies: |
flutter: |
sdk: flutter |
flutter_localizations: |
sdk: flutter |
intl: any |
<code_end> |
then import the flutter_localizations library and specify |
localizationsDelegates and supportedLocales for |
your MaterialApp or CupertinoApp: |
<code_start> |
import 'package:flutter_localizations/flutter_localizations.dart'; |
<code_end> |
<code_start> |
return const MaterialApp( |
title: 'localizations sample app', |
localizationsDelegates: [ |
GlobalMaterialLocalizations.delegate, |
GlobalWidgetsLocalizations.delegate, |
GlobalCupertinoLocalizations.delegate, |
], |
supportedLocales: [ |
locale('en'), // english |
locale('es'), // spanish |
], |
home: MyHomePage(), |
); |
<code_end> |
after introducing the flutter_localizations package |
and adding the previous code, |
the material and cupertino |
packages should now be correctly localized in |
one of the 115 supported locales. |
widgets should be adapted to the localized messages, |
along with correct left-to-right or right-to-left layout. |
try switching the target platform’s locale to |
spanish (es) and the messages should be localized. |
apps based on WidgetsApp are similar except that the |
GlobalMaterialLocalizations.delegate isn’t needed. |
the full Locale.fromSubtags constructor is preferred |
as it supports scriptCode, though the locale default |
constructor is still fully valid. |
the elements of the localizationsDelegates list are |
factories that produce collections of localized values. |
GlobalMaterialLocalizations.delegate provides localized |
strings and other values for the material components |
library. GlobalWidgetsLocalizations.delegate |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.