KiviCare (TM) Pharma Addon- Documentation
KiviCare (TM) Pharma Addon

How add a new language into Flutter app?

đź•’ Estimated Reading: 1 Minutes
đź“‚ Location:
User Guide → How to Add a New Language into Flutter App?

– – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –

This guide helps you add a new language into your Flutter app by creating a new localization Dart file and updating related components.

– – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –

✅Step 1 – Open Your Project

Open your Flutter project using your preferred development IDE (e.g., Android Studio, VS Code).

✅ Step 2 – Generate Language Dart File

1. Navigate to: lib → locale folder.

2. Create a new Dart file for the language you want to add.
For example, to add German, create a file named:

language_de.dart

3. Inside the file, define a class with the language name and add translated strings.
Example:

class LanguageDe {
// Add key-value pairs for all translated strings
}

đź’ˇ TIP:
Follow the naming pattern:
language_<languageCode>.dart
Example:

  • English: language_en.dart
  • Spanish: language_es.dart
  • French: language_fr.dart

✅ Step 3 – Update App Localizations

1. Open the app_localizations.dart file.

2. Inside a switch statement, add the following code to handle the new language:

case 'de':
return LanguageDe();

✅ Step 4 – Add Flag Image

1. Go to the assets → flags folder.

2. Add the respective flag image.
Example for German:

ic_de.png

✅ Step 5 – Update Common Base

1. Open the utils → common_base.dart file.

2. Locate the languageList() method.

3. Add a new LanguageDataModel entry like this:

LanguageDataModel(
id: 2,
name: 'German',
languageCode: 'de',
fullLanguageCode: 'de-DE',
flag: 'assets/flags/ic_de.png',
),

– – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –

🔍 Additional Info

Make sure you use the correct ISO 639-1 language code in both languageCode and fullLanguageCode.

If you are unsure about the language code, use the resource below to find it:

đź”— Click here to get language codes

✅ That’s it! You’ve successfully added a new language to your Flutter application.

/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / // /

stimated reading: 1 minutes

Step 1 – Open Your Project


Open your project in your preferred development IDE.

Step 2 – Generate Language Dart File

  1. Navigate to the lib → locale folder.
  2. Create a new Dart file for your new language. For example, if you want to add German, create a file with name language_de.dart.
  3. Inside language_de.dart, define a class name LanguageDe and translate all strings into German.

TIP

You can follow the convention of naming them as language_languageCode.dart, where languageCode represents the ISO 639-1 language code for the language.

For example:

English: language_en.dart, Spanish: language_es.dart, French: language_fr.dart

Step 3 – Update App Localizations

  1. Open the app_localizations.dart file.
  2. Inside a switch statement, add the following code to handle the new language:
case 'de':
return LanguageDe();

Step 4 – Add Flag Image

  1. Go to the assets → flags folder.
  2. Add a new language flag image. For example, for French, name the image file as ic_de.png.

Step 5 – Update Common Base

  1. Open the utils → common_base.dart file.
  2. Locate the languageList() method.
  3. Add a new entry for the added language in the format:
LanguageDataModel(
id: 2,
name: 'German',
languageCode: 'de',
fullLanguageCode: 'de-DE',
flag: 'assets/flags/ic_de.png',
),

INFO

Ensure to use the correct language code in both languageCode and fullLanguageCode. If you don’t know what’s language code for your preferred language please do visit this site for getting language code – Click Me!