Getx: transliterations with arguments or plural transliterations

Created on 14 Jul 2020  路  9Comments  路  Source: jonataslaw/getx

How can I translate with args or multiple args and plural !!?
last thing how can import locales files as jsone files I looking for it in documentation and I can't found it,
please any one have any source , inform me

enhancement

All 9 comments

is use flutter_translate and flutter_localizations normal with GetX ! or it's wrong way ?

Hi, for now Getx only supports translations and translations with arguments (there is an example of use in the package examples).
In the future, when I have time, or when a collaborator can do this, we will have support for plurals and generos, but for the time being this is not yet possible (only if you can do it for arguments).
You can use other internationalization packages with GetX, without problems. GetX's internationalization was written in about 20 lines of code (because the framework base is already solid and allowed this) to have a simple and light internationalization solution, because the current ones are being a problem in flutter_web due to the size of file, but you can use them smoothly, and especially if you need an internationalization feature that GetX doesn't have.

thanks for your great effort, last one do you have any full internationalization example that have handle locale from storage after I choose locale and reset app !?

To reset the application you just need to call Get.changeLocale(newLocale) and GetX will do everything for you.

I just have the standard example using Map:
https://pub.dev/packages/get/example

If you want to use local json, just read it and make it a map in your void main asynchronously, and use Get.put(translations) to be able to access it in your GetMaterialApp:
translationKeys: Get.find()

To reset the application you just need to call Get.changeLocale(newLocale) and GetX will do everything for you.

I just have the standard example using Map:

https://pub.dev/packages/get/example

If you want to use local json, just read it and make it a map in your void main asynchronously, and use Get.put(translations) to be able to access it in your GetMaterialApp:

translationKeys: Get.find()

Thank you

I'm trying now to load locales files from assets and convert them to map but I'm facing one issues
After load assets json file and convert it to map it's Map<String,dynamic> butMap<String, Map<String, String>> get keys =>' only acceptsMap` how to throw it,

 @override
  void onInit() async {

    //loop on loale codes
    for (final localeFile in localeService.languages) {
      //loaf file from assets
      String localeFileString =
          await rootBundle.loadString("assets/i18n/${localeFile['code']}.json");
      //convert string to map
      Map<String, dynamic> localeFileMap = jsonDecode(localeFileString);

      //add map to locales map
      translateJsonFiles.addAll({"${localeFile['code']}": localeFileMap});
    }

    super.onInit();
  }

class AppTranslations extends Translations {
  @override
  Map<String, Map<String, String>> get keys =>
      LocalesController.to.translateJsonFiles;
}

Error

type '_InternalLinkedHashMap<String, Map<String, dynamic>>' is not a subtype of type 'Map<String, Map<String, String>>'

and is there any way to change direction of app if user set a language with rtl ?

@niypoo regarding direction of app, today I made a PR, you can follow this issue

We already have this feature in the last version, so I'm closing this

Was this page helpful?
0 / 5 - 0 ratings

Related issues

R-Praveen picture R-Praveen  路  4Comments

ChiwanAhn picture ChiwanAhn  路  4Comments

ad-on-is picture ad-on-is  路  3Comments

wailashraf71 picture wailashraf71  路  4Comments

Denilson-source picture Denilson-source  路  3Comments