translate method

void translate(
  1. String languageCode, {
  2. bool save = true,
})

Call this function at where you want to translate the app like by pressing the button or any actions.

Implementation

void translate(
  String languageCode, {
  bool save = true,
}) {
  if (languageCode == _currentLocale?.languageCode) return;
  final countryCode = _getCountryCode(languageCode);
  final scriptCode = _getScriptCode(languageCode);
  if (save) PreferenceUtil.setLocale(languageCode, countryCode, scriptCode);
  _currentLocale = Locale.fromSubtags(
    languageCode: languageCode,
    countryCode: countryCode,
    scriptCode: scriptCode,
  );
  _delegate = FlutterLocalizationDelegate(_currentLocale);
  onTranslatedLanguage?.call(_currentLocale);
}