パッケージ、リポジトリ、アプリカテゴリを検索

パッケージ詳細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 件

ソースリポジトリ

このパッケージを使用しているプロジェクト