搜索插件、代码仓与 APP 分类

插件详情v2.0.0

locale_plus

LocalePlus 允许在 Flutter 应用中轻松访问原生设备的区域设置数据。包括语言、国家代码、时区和数字格式化偏好。

AndroidiOS
近 30 天下载
6520
喜欢数
33
Pub 分数
140

安装插件

flutter pub add locale_plus

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

LocalePlus 是一个 Flutter 包,可提供对原生设备区域设置信息的无缝访问,包括语言、国家代码、时区和数字格式化偏好。它通过无需复杂设置即可检索系统级区域设置数据,简化了本地化过程。适用于需要准确地区设置以动态呈现内容、显示日期/时间以及格式化货币的应用程序。该包与 Flutter 的国际化框架无缝集成,并支持 Android 和 iOS 平台。

适合场景

  • 基于用户区域的动态界面
  • 显示本地化日期和时间
  • 格式化数字和货币
  • 支持多语言应用
  • 通过区域设置调整应用行为
  • 通过区域设置增强可访问性

主要特点

  • 获取设备原生区域设置数据
  • 支持语言、国家、时区和格式化
  • 简单的 API,设置简单
  • 跨平台(Android 和 iOS)
  • 轻量且无依赖
  • 自动检测用户的首选语言环境

适合对象

  • 需要区域定制的应用程序
  • 国际化应用程序
  • 金融或旅行应用
  • 具有本地化需求的面向用户的应用程序
  • 寻求快速区域设置访问的开发者
  • 使用 Flutter 国际化功能的项目

使用建议

  • 依赖设备系统设置
  • 不处理翻译字符串
  • 仅限读取区域设置数据
  • 无内置回退机制
  • 需要手动处理区域设置更改
  • 单独使用不适合完整的国际化工作流程

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

Locale Plus

LocalePlus allows easy access to native device locale data in Flutter apps. Includes language, country code, time zone, and number formatting preferences.

Table of Content

Overview

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.

Requirements

  • Dart sdk: ">=3.10.0 <4.0.0"
  • Flutter: ">=3.38.0"
  • Android: minSdkVersion 16
  • iOS 13.0+

The iOS plugin supports both Swift Package Manager and CocoaPods.

Installation

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

Usage

Patch the locales with the users' group and decimal seperators

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());
}

Get if the user is using a samsung keyboard

final decimalSeparator = await LocalePlus().isUsingSamsungKeyboard();

Get Decimal & Grouping Separator

final decimalSeparator = await LocalePlus().getDecimalSeparator();
final groupingSeparator = await LocalePlus().getGroupingSeparator();

Get Language & Region Code

final regionCode = await LocalePlus().getRegionCode();
final languageCode = await LocalePlus().getLanguageCode();

Get Seconds from GMT

final secondsFromGMT = await LocalePlus().getSecondsFromGMT();

Is Device Using 24 hour time and Current Locale AM PM Symbols

final is24HourTime = await LocalePlus().is24HourTime();
final amSymbol = await LocalePlus().getAmSymbol();
final pmSymbol = await LocalePlus().getPmSymbol();

Is Device Using Metric System

final usesMetricSystem = await LocalePlus().usesMetricSystem();

Get TimeZone Identifier

final timeZoneIdentifier = await LocalePlus().getTimeZoneIdentifier();

Get First Day Of Week

final firstDayOfWeek = await LocalePlus().getFirstDayOfWeek();

Get Date format pattern

final dateFormatPattern = await LocalePlus().getDateFormatPattern();

Author

Gökberk Bardakçı, Uygar İşiçelik

Contributors

Bent Engbers, Renat Shakhmatov, Giovanni Lattanzio, Gökhan Çavuş

License

LocalePlus is available under the MIT license. See the LICENSE file for more info.

所属分类

依赖

依赖清单 3 项

源码仓库

使用此插件的项目

暂无相关数据。