搜尋套件、儲存庫與 APP 分類

套件詳情v0.9.1

devicelocale

一個可用於提取裝置上目前定義的區域設定的 Flutter 套件,並將目前的區域設定設為清單中的第一個。

AndroidiOSWebmacOSLinux
近 30 天下載
12.6萬
喜歡數
151
Pub 分數
150

安裝套件

flutter pub add devicelocale

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

devicelocale 套件是 Flutter 的一個實用工具,可取得使用者裝置上設定的地區清單,目前系統地區會排在第一順位。它支援多個平台,包括 Android、iOS、Web、macOS 與 Linux,非常適合需要本地化感知行為的應用程式。透過存取原生裝置設定,讓應用程式能動態適應使用者偏好,無需手動設定。此套件輕量且可順暢整合至國際化工作流程中。

適用情境

  • 多語言應用程式中的動態語言檢測
  • 啟動時自動選擇使用者首選語言
  • 支援基於設備設定的應用程式本地化
  • 建構區域感知特徵
  • 同步 UI 語言與系統偏好設定

主要特色

  • 返回設備定義的區域設定,目前區域設定在前
  • 跨平台支援,適用於主要作業系統
  • 用於檢索區域設定列表的簡單 API
  • 與 Flutter 的本地化框架整合
  • 輕量且無依賴

適合對象

  • 面向全球受眾的應用
  • 在地化密集型應用
  • 使用 Flutter 的 intl 包的開發者
  • 需要自動區域設定回退的項目
  • 實施響應式國際化

使用建議

  • 依賴設備的原生設定
  • 不處理自定義區域設定覆蓋
  • 如果未設定區域設定,可能會傳回空清單
  • 某些系統需要特定平台的權限
  • 僅限讀取,無法修改裝置地區設定

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

devicelocale

Gets the device locale data, independent of the app locale settings.

Usage

import 'package:devicelocale/devicelocale.dart';

then

List languages = await Devicelocale.preferredLanguages;
String locale = await Devicelocale.currentLocale;

this should return a list of the preferred/current language locales setup on the device, with the current one being the first in the list or just the currently set device locale.

Android specific implementation (no-op on other platforms if supported)

Added per-app language preferences for Android (https://developer.android.com/about/versions/13/features/app-languages#kotlin) You can check if your current device is supported isLanguagePerAppSettingSupported And after checking if your device is supported you can set the per-app language preference with setLanguagePerApp(Locale) this will return true if success

Note for Linux

Since GNU/Linux and POSIX doesn't provide a standard API for getting the preferred languages, Devicelocale.preferredLanguages always returns the current locale.

Swift Package Manager (iOS / macOS)

Both CocoaPods and Swift Package Manager are supported; Flutter ≥ 3.44 uses SwiftPM automatically. To verify SwiftPM locally on Xcode 26+, clone the repository into a directory matching the pubspec name, otherwise the example app build fails with a SwiftPM identity-mismatch error (pub.dev users are unaffected):

git clone https://github.com/magnatronus/flutter-devicelocale.git devicelocale

Updates

Sept 2023

merged pull request for compatibility with AGP 8

Feb 2023

Added 2 new functions for this iOS issue

  • defaultLocale
  • defaultAsLocale
July 2022

Added support for per-app language preferences on Android (https://developer.android.com/about/versions/13/features/app-languages#kotlin) You can now set the per-app language if you have an in app language picker. Updated the demo app

May 2022

Merged pull requests

Oct 2021

Updated the code and APIs used by Flutter for an Android plugin - this was the source of the Deprecated API warning in the Android build.

July 2021

Add beta support for Linux

March 2021

Added test support for web

Updated for null safety

Jul 2020 Locale update v0.3.1

This is an update from a received request, where prior to 0.3.1 the 2 methods:

  • preferredLanguages
  • currentLocale

returned string values.

There are now 2 equivilent methods

  • preferredLanguagesAsLocales
  • currentAsLocale

that now also return a Locale object rather than a string.

releases
  • March 2021 1.0.0 Updated to null safety

  • July 2020 0.3.0 Updated Android to support Android Embedding V2

  • Apr 2020 0.2.3 Updated Android code from contributions from @ened

  • Mar 2020 0.2.2 Updated iOS so that if detected locale is null then it is not included in return value

  • Sep 2019 0.2.0 Updated Android following feedback from https://github.com/huzhirento . Fallback to the currentLocale when attempting to get a list of locales fro Android 7 and below as the getLocales() call is a feature of API 24 and failed for Android 7 and below.

Getting Started

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

所屬分類

依賴

依賴清單 1 項

原始碼儲存庫

使用此套件的專案