slang-i18n / slang

Type-safe i18n for Dart and Flutter
https://pub.dev/packages/slang
MIT License
474 stars 39 forks source link

Add a getter for if a language is RTL #134

Closed adil192 closed 1 year ago

adil192 commented 1 year ago

Motivation

I was implementing

and I needed to find out if the current language was right-to-left. This is the code I used:

import 'package:intl/intl.dart' as intl;

final rtl = intl.Bidi.isRtlLanguage(
  LocaleSettings.currentLocale.languageTag
);

Developer Experience Add a getter to AppLocale so that the developer can just use e.g.

final rtl = LocaleSettings.currentLocale.isRtl;
Tienisto commented 1 year ago

Slang has no knowledge about locales (en-US is as valid as xy-XY).

So isRtl will be just a delegate to your given intl method.

The problem is that slang should not depend on intl unless it is really necessary.

A clean solution is to write your own extension method for AppLocale.

extension AppLocaleExt on AppLocale {
  bool get isRtl {
    // intl call
  }
}
adil192 commented 1 year ago

Ah okay, for some reason I just assumed that slang was already depending on intl Thanks for your consideration