skip to Main Content

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 ?

2

Answers


  1. 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.

    Login or Signup to reply.
  2. 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
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search