Home > database >  Need to apply localisation for the API data in flutter
Need to apply localisation for the API data in flutter

Time:01-03

I'm working on flutter application that one should support localisation for multiple languages. I used to create .arb file for the localisation but for the API data i couldn't apply arb files ?

CodePudding user response:

Here two ways make localization.

  1. Use ARB (Application Resource Bundle) files
  1. manage from API

manage from Api

make API post method they past language code. they return all arb file data from the backend side.

and then store data in the local database and display all places you want display.

CodePudding user response:

in Get Package you can extend the translations class and assign that class object to GetMaterialApp translations property, You just need to get your Language Map files from API and pass to overrided keys function. For more please check doc https://pub.dev/packages/get#translations

API Response like

 res= {
            'en': {
              'SEARCH_FOR_SERVICES_AND_PROFESSIONALS':
                  'Search for services and professionals',
              'MEMBERSHIP': 'Membership',
              'PURCHASE': 'Purchase',
              'GET_STARTED': 'Get started',
              }
          }

 GetMaterialApp(
        title: Constants.appName,
        translations: Localization(res), //Localization class

and localization class

class Localization extends Translations {
  // final Map<String, Map<String, String>>? res;
  // Localization(this.res);
  @override
  Map<String, Map<String, String>> get keys => res
  • Related