Skip to main content

How add a new language into Flutter app?

Estimated 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();

    Add Language Case

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 common.dart file.

  2. Locate the languageList() method.

  3. Add a new entry for the added language in the format:

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

    Update Common Base

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!