Streamit TV - Documentation

How to add a new app language into flutter app?

Step 1 – Generate Language Dart File

  • Navigate to the lib → locale folder.
  • Create a new Dart file for your new language. For example, if you want to add spanish create a file with name “language_es.dart”.
  • Inside “language_es.dart”, define a class name LanguageEs and translate all strings into Spanish.

NOTE

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 2 – Update App Localizations

  • Open the “app_localizations.dart” file. it will be inside locale directory.
  • Inside a switch statement, add the following code to handle the new language:
   case 'es':
return LanguageEs();

Step 3 – Add Flag

  • Go to the assets → flags folder. Add a new language flag image. For example, for spanish, name the image file as ic_Spanish.png. If you have installed Assets generator plugin then no need to perform next step.
  • Go to lib → generated → assets.dart and add constant for image file
  • find “assets/flags” then add line below
static const String flagsIcEs = 'assets/flags/ic_es.png';

Step 4 – Update languageList() in Constants

  • Open the lib → utils → common_base.dart file.
  • Locate the languageList() method.
  • Add a new entry for the added language in the format:
LanguageDataModel
(
id: 4,
name: locale.value.Spanish,
languageCode: 'es',
fullLanguageCode: 'es-Es',
flag: Assets.flagsIcEs,
),

IMPORTANT

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 here!