multilingual etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster
multilingual etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster

Multilingual Application Development with Flutter

 

Hello everyone! Today I wanted to talk to you about multilingual applications. Now our applications are not only addressed to a single language; we aim to reach many users from different countries and languages. This brings us to the localisation process. So how do we implement a multilingual application with Flutter? Let’s take a look step by step.

1. What is Localisation? Why is it important?

Localisation is the process of adapting the application to different cultures and geographies, rather than just translating the language. In other words, in addition to changing the language of the application, we need to adjust regional features such as date formats, currency, numbers according to that language. We can say that it is to make users feel ‘at home’.

2. Basic Steps to Making a Multilingual Application in Flutter

Although the process of making a multilingual application in Flutter may seem scary, it is actually quite systematic. Let’s analyse the steps together.

Step 1: Include the flutter_localizations Package in the Project

Firstly, to take advantage of Flutter’s localisation support, we need to add the flutter_localizations package to our project. This package provides the basic tools to serve content in different languages.

We add the following lines to the pubspec.yaml file:

dependencies:
flutter:
sdk: flutter
flutter_localizations:
sdk: flutter

This small but important step paves the way for the application to work in different languages.

Step 2: Identify the languages we support

Now it is time to specify which languages the application will support. We define these languages using the localizationsDelegates and supportedLocales parameters in the MaterialApp widget.

import 'package:flutter_localizations/flutter_localizations.dart';
MaterialApp(
localizationsDelegates: [
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
],
supportedLocales: [
Locale('en', 'US'), // English
Locale('es', 'ES'), // Spanish
],
home: MyHomePage(),
);

That’s it! Now our application supports English and Spanish languages. Of course, we can add more languages to this list.

Step 3: Manage Translations: With the help of the intl Package

One of the most popular packages when it comes to localisation in Flutter is intl. This package offers an excellent solution for managing text in different languages. By creating .arb files and storing language translations in these files, we can define separate content for each language.

For example, we can create intl_en.arb files for English andintl_tr.arb files for Turkish.

An example .arb file might look like this:

{
"appTitle": "My Multilingual App",
"welcomeMessage": "Welcome!",
"@welcomeMessage": {
"description": "Welcome message displayed on the home page"
}
}

We can easily use these translations in our code.

Step 4: Dynamic Language Switching within the Application

If we want to dynamically change the language of the application according to the user, we can add a language selector. When the user selects the desired language through this selector, the language of the application changes instantly.

Here is a simple language selector widget:

DropdownButton<Locale>(
value: _selectedLocale,
onChanged: (Locale? newLocale) {
setState(() {
_selectedLocale = newLocale!;
MyApp.setLocale(context, newLocale);
});
},
items: [
DropdownMenuItem(
child: Text("English"),
value: Locale('en', 'US'),
),
DropdownMenuItem(
child: Text("Español"),
value: Locale('es', 'ES'),
),
],
);

In this way, we can offer the user the flexibility to change the language. We can also save this setting with SharedPreferences and ensure that the preferred language is automatically selected when the application is reopened.

3. Tips for Localisation

Let’s talk a little bit about the tips:

  • Care in Translations: We need to make language translations accurately and clearly. If possible, it may make more sense to use professional translation services rather than machine translations.
  • UI Tests: It is very important to test how the application looks in different languages. In some languages, texts can be lengthened and this can cause problems in design.
  • Cultural Differences: It is necessary to pay attention not only to language but also to cultural differences. We should consider issues such as date format and currency.

4. Dynamic Content Localisation

If our application provides dynamic content (for example, if it pulls data via API), we may need to localise this data as well. Depending on the language chosen by the user, we can show the data pulled from the API in different languages.

Future<void> fetchLocalizedContent(Locale locale) async {
final response = await http.get(Uri.parse('https://api.example.com/content?lang=${locale.languageCode}'));
// Process returned data and display it in the UI
}

In this way, not only static content but also dynamic content of the application is presented in a localised way.

I hope you found this article useful! If you appreciate the information provided, you have the option to support me by Buying Me A Coffee! Your gesture would be greatly appreciated!


Developing multilingual applications with Flutter provides a great advantage in addressing a wide range of users and personalising the user experience. Flutter’s built-in localisation tools and intl package make this process much easier. As a developer, managing the localisation process correctly is an important step for the success of the application.

By following these steps, we are ready to develop a multilingual Flutter application! For more information and resources, here is a link to Flutter’s localisation documentation.

Good luck to you!

Selin.

Flutter ile Çok Dilli Uygulama Geliştirme

 

Herkese merhaba! Bugün sizinle çok dilli uygulamalar hakkında konuşmak istedim. Artık uygulamalarımız sadece tek bir dile hitap etmekle kalmıyor; farklı ülkelerden, farklı dillerden birçok kullanıcıya ulaşmayı hedefliyoruz. Bu da bizi yerelleştirme (localization) sürecine getiriyor. Peki Flutter ile çok dilli bir uygulamayı nasıl hayata geçiririz? Adım adım göz atalım.

1. Yerelleştirme Nedir? Neden Önemlidir?

Yerelleştirme, uygulamanın sadece dili çevirmekten öte, farklı kültürlere ve coğrafyalara uygun hale getirilmesi sürecidir. Yani, uygulamanın dilini değiştirmekle birlikte tarih formatları, para birimi, sayılar gibi bölgesel özellikleri de o dile göre ayarlamamız gerekiyor. Kullanıcıların kendilerini “evde” hissetmesini sağlamak diyebiliriz.

2. Flutter’da Çok Dilli Uygulama Yapmanın Temel Adımları

Flutter’da çok dilli uygulama yapma süreci korkutucu gibi görünse de, aslında oldukça sistematik ilerliyor. Hadi birlikte adımları inceleyelim.

Adım 1: flutter_localizations Paketini Projeye Dahil Edelim

Öncelikle, Flutter’ın sunduğu yerelleştirme desteğinden yararlanmak için flutter_localizations paketini projemize eklememiz gerekiyor. Bu paket, farklı dillerde içerik sunabilmek için gerekli temel araçları sağlıyor.

pubspec.yaml dosyasına şu satırları ekliyoruz:

dependencies:
flutter:
sdk: flutter
flutter_localizations:
sdk: flutter

Bu küçük ama önemli adım, uygulamanın farklı dillerde çalışabilmesinin önünü açıyor.

Adım 2: Desteklediğimiz Dilleri Belirleyelim

Şimdi sırada uygulamanın hangi dilleri destekleyeceğini belirtmek var. MaterialApp widget'ında localizationsDelegates ve supportedLocales parametrelerini kullanarak bu dilleri tanımlıyoruz.

import 'package:flutter_localizations/flutter_localizations.dart';

MaterialApp(
localizationsDelegates: [
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
],
supportedLocales: [
Locale('en', 'US'), // İngilizce
Locale('tr', 'TR'), // Türkçe
],
home: MyHomePage(),
);

İşte bu kadar! Artık uygulamamız, İngilizce ve Türkçe dillerini destekliyor. Tabii bu listeye daha fazla dil ekleyebiliriz.

Adım 3: Çevirileri Yönetelim: intl Paketi Yardımıyla

Flutter’da yerelleştirme denilince akla gelen en popüler paketlerden biri intl. Bu paket, farklı dillerdeki metinleri yönetmek için mükemmel bir çözüm sunuyor. .arb dosyaları oluşturup bu dosyalarda dil çevirilerini saklayarak her dil için ayrı içerikler tanımlayabiliyoruz.

Örneğin, İngilizce için intl_en.arb, Türkçe için intl_tr.arb dosyaları oluşturabiliriz.

Örnek bir .arb dosyası şu şekilde olabilir:

{
"appTitle": "Benim Çok Dilli Uygulamam",
"welcomeMessage": "Hoş geldiniz!",
"@welcomeMessage": {
"description": "Ana sayfada gösterilen karşılama mesajı"
}
}

Bu çevirileri kodumuzda rahatça kullanabiliriz.

Adım 4: Uygulama İçinde Dinamik Dil Değişimi

Uygulamanın dilini kullanıcıya göre dinamik olarak değiştirmek istiyorsak, bir dil seçici ekleyebiliriz. Kullanıcı, bu seçici aracılığıyla istediği dili seçtiğinde, uygulamanın dili anında değişir.

İşte basit bir dil seçici widget:

DropdownButton<Locale>(
value: _selectedLocale,
onChanged: (Locale? newLocale) {
setState(() {
_selectedLocale = newLocale!;
MyApp.setLocale(context, newLocale);
});
},
items: [
DropdownMenuItem(
child: Text("English"),
value: Locale('en', 'US'),
),
DropdownMenuItem(
child: Text("Türkçe"),
value: Locale('tr', 'TR'),
),
],
);

Bu şekilde kullanıcıya dil değiştirme esnekliği sunabiliriz. Ayrıca bu ayarı SharedPreferences ile kaydedip uygulama yeniden açıldığında tercih edilen dilin otomatik olarak seçili gelmesini sağlayabiliriz.

3. Yerelleştirme için İpuçları

Biraz da işin püf noktalarından bahsedelim:

  • Çevirilerde Dikkat: Dil çevirilerini mutlaka doğru ve anlaşılır şekilde yapmamız gerek. Makine çevirilerinden ziyade, mümkünse profesyonel çeviri hizmeti kullanmak daha mantıklı olabilir.
  • UI Testleri: Farklı dillerde uygulamanın nasıl göründüğünü test etmek oldukça önemli. Bazı dillerde metinler uzayabilir ve bu da tasarımda sorunlara yol açabilir.
  • Kültürel Farklılıklar: Sadece dil değil, aynı zamanda kültürel farklılıklara da dikkat etmek gerek. Tarih formatı, para birimi gibi konuları göz önünde bulundurmalıyız.

4. Dinamik İçerik Yerelleştirme

Eğer uygulamamız dinamik içerikler sunuyorsa (örneğin API üzerinden veri çekiyorsa), bu verileri de yerelleştirmemiz gerekebilir. Kullanıcının seçtiği dile göre API’den çekilen veriyi farklı dillerde gösterebiliriz.

Future<void> fetchLocalizedContent(Locale locale) async {
final response = await http.get(Uri.parse('https://api.example.com/content?lang=${locale.languageCode}'));
// Dönen verileri işleyin ve UI'da gösterin
}

Bu sayede uygulamanın sadece statik içerik değil, dinamik içerikleri de yerelleştirilmiş şekilde sunulmuş olur.

Flutter ile çok dilli uygulama geliştirmek, geniş bir kullanıcı kitlesine hitap etmek ve kullanıcı deneyimini kişiselleştirmek açısından büyük avantaj sağlar. Flutter’ın yerleşik yerelleştirme araçları ve intl paketi ile bu süreci oldukça kolaylaştırabiliyoruz. Geliştirici olarak, yerelleştirme sürecini doğru yönetmek, uygulamanın başarısı için önemli bir adım.

Bu adımları takip ederek, çok dilli bir Flutter uygulaması geliştirmeye hazırız! Daha fazla bilgi ve kaynaklar için Flutter’ın yerelleştirme dokümantasyonuna göz atabilmek için linki buraya bırakıyorum.

Kolay gelsin!

Selin.