Go4Food Go4Food Docs v1.0.0
Step 7 · Languages

Languages & Right-to-Left

The admin panel decides which languages people can pick; the translated texts live in a file per language inside each app. Arabic flips the phone apps right-to-left.

10 min + translating

Go4Food ships with five languages in every app and website: English, Hindi, Arabic, French and Portuguese. Two parts work together, and both are needed:

PartWhereDecides
Language listAdmin panel → SettingsLanguages (saved in the Firestore languages collection)Which languages people can pick, and the default one. Changes show without a new build.
Translation fileslib/lang/app_<code>.dart in each projectThe actual words on every screen. Changes need a new build.

Adding a language in the panel is not enough

If you add, say, German (de) in the admin panel but the apps have no app_de.dart, people can pick German and still see English. Add the language in the panel and add its file to each app.

Turn languages on or off#

Open Languages#

Admin panel → SettingsLanguages. The table lists each language with its Name, Code, Status and Default.

Add a language#

Click + Add Language. Pick it under Language * from the built-in list of about 30 languages; the Code * is filled in for you (for example de). Set Status to Active and click Save.

Choose the default#

Switch on Default for the language new users should start with. Only one language can be the default.

Hide one#

Set a language's Status to Inactive. The apps only list active languages.

The code must match the file

The Code in the panel is how the apps find the translation file: code fr uses app_fr.dart and the 'fr' entry in localization_service.dart. Keep them exactly the same, in lower case.

How people pick a language#

  • Phone apps: a language screen appears on the very first start, with the default language selected. Later they change it under Language in the profile menu (customer and restaurant apps) or the side menu (driver app).
  • Customer website and restaurant panel: the language button in the top bar.
  • Admin panel: the language drop-down in the top bar (it shows English in the screenshots).

The choice is remembered on the device. Restaurant names, food names, offers and other texts that people type in are shown as typed; only the app's own texts are translated.

Where the translation files are#

ProjectTranslation filesRegistered in
Customer appcustomer/lib/lang/customer/lib/services/localization_service.dart
Restaurant apprestaurant/lib/lang/restaurant/lib/services/localization_service.dart
Driver appdriver/lib/lang/driver/lib/services/localization_service.dart
Admin paneladmin_panel/lib/app/lang/admin_panel/lib/app/services/localization_service.dart
Customer websitecustomer_web/lib/lang/customer_web/lib/services/localization_service.dart
Restaurant panelrestaurant_web/lib/lang/restaurant_web/lib/services/localization_service.dart

Each folder has app_en.dart, app_hi.dart, app_ar.dart, app_fr.dart and app_pt.dart. (The driver app also has app_es.dart for Spanish, switched off in its localization_service.dart.)

Change a translation#

Each file is a list of key → text pairs. The key on the left is what the app looks up (usually the English text); the text on the right is what people see.

customer/lib/lang/app_ar.dart
const Map<String, String> lnAr = {
  "Read more": "اقرأ المزيد",
  "Read less": "اقرأ أقل",
  // ...
};

Change only the right side. Never change the left side, or the app no longer finds that text. A key that is missing from a language shows in English. Some values contain a placeholder such as @time or @minutes: keep it, the app fills it in. Rebuild the app or website afterwards.

Add a new language#

Do this in each of the six projects. The example adds German (de).

Copy the English file#

Copy app_en.dart to app_de.dart in the same folder. Rename the map inside, for example const Map<String, String> deDE = {, and translate the right side of every line.

Register it#

In that project's localization_service.dart, add the import, the locale and the map:

customer/lib/services/localization_service.dart
import 'package:customer/lang/app_de.dart';
...
  static final locales = [
    const Locale('en'),
    ...
    const Locale('de'),
  ];
...
  Map<String, Map<String, String>> get keys => {
        'en': enUS,
        ...
        'de': deDE,
      };

Use the project's own package name in the import (restaurant, driver, admin_panel, customer_web, restaurant_web).

Phone apps: add the locale to main.dart#

In customer, restaurant and driver, also add Locale('de') to the supportedLocales list in lib/main.dart. This makes Flutter's own texts (date pickers, menus) and the text direction follow the language.

Add it in the admin panel and rebuild#

Add German under SettingsLanguages with code de, set it Active, then build and publish the apps and websites again.

Right-to-left (Arabic and similar)#

In the three phone apps, choosing Arabic mirrors the whole layout: text, icons, lists and back arrows run from right to left. This comes from Flutter itself, for every language listed in supportedLocales that is written right to left. For a new right-to-left language such as Urdu (ur) or Persian (fa), adding the locale as above is enough.

Admin panel and websites

The admin panel, the restaurant panel and the customer website show the Arabic texts, but their layout stays left-to-right.

The admin panel also stores a direction (ltr or rtl) with each language it adds, taken from its built-in language list. The apps decide the direction from the language code, as described above.