locale_plus
LocalePlus 可讓 Flutter 應用程式輕鬆存取原生裝置的地區設定資料。包含語言、國家代碼、時區與數字格式化偏好。
LocalePlus 可讓 Flutter 應用程式輕鬆存取原生裝置的地區設定資料。包含語言、國家代碼、時區與數字格式化偏好。
{"sdk":"flutter"}>=0.19.0 <0.21.0^2.0.2^2.0.4{"sdk":"flutter"}^1.0.4以下為英文專案原文快照,最新內容請造訪 GitHub。
LocalePlus allows easy access to native device locale data in Flutter apps. Includes language, country code, time zone, and number formatting preferences.
LocalePlus is a Flutter package that allows developers to easily retrieve data from the native device locale settings. With LocalePlus, developers can access information such as the device's language, country code, and time zone, as well as the device's number formatting preferences such as grouping and decimal separator. This makes it easy to build internationalized apps that provide a personalized experience for each user. Whether you're building a financial app that needs to display numbers in the user's local format or a social media app that needs to display timestamps in the user's time zone, LocalePlus has you covered. With a simple and intuitive API, LocalePlus is the perfect tool for any Flutter developer looking to add localization to their app.
The iOS plugin supports both Swift Package Manager and CocoaPods.
with Flutter:
$ flutter pub add locale_plus
This will add a line like this to your package's pubspec.yaml (and run an implicit flutter pub get):
dependencies:
locale_plus: ^2.0.0
This function patches all locales in flutter, so that you can use the decimal seperator and group seperator from numberFormatSymbols after the patch is complete.
The patchNumberSeperators function patches the locales on android and ios.
The shouldPatchForSamsungKeyboard can be enabled, to patch for Samsung keyboards on android phones (they only allow for a . as input).
It is safe to call on MacOS, Windows, Linux and web, but it does not patch the locales.
import 'package:locale_plus/locale_plus.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await PatchAllLocales.patchNumberSeperators(
shouldPatchForSamsungKeyboard: true,
);
runApp(const MyApp());
}
final decimalSeparator = await LocalePlus().isUsingSamsungKeyboard();
final decimalSeparator = await LocalePlus().getDecimalSeparator();
final groupingSeparator = await LocalePlus().getGroupingSeparator();
final regionCode = await LocalePlus().getRegionCode();
final languageCode = await LocalePlus().getLanguageCode();
final secondsFromGMT = await LocalePlus().getSecondsFromGMT();
final is24HourTime = await LocalePlus().is24HourTime();
final amSymbol = await LocalePlus().getAmSymbol();
final pmSymbol = await LocalePlus().getPmSymbol();
final usesMetricSystem = await LocalePlus().usesMetricSystem();
final timeZoneIdentifier = await LocalePlus().getTimeZoneIdentifier();
final firstDayOfWeek = await LocalePlus().getFirstDayOfWeek();
final dateFormatPattern = await LocalePlus().getDateFormatPattern();
Gökberk Bardakçı, Uygar İşiçelik
Bent Engbers, Renat Shakhmatov, Giovanni Lattanzio, Gökhan Çavuş
LocalePlus is available under the MIT license. See the LICENSE file for more info.