Giter Site home page Giter Site logo

gokberkbar / locale_plus Goto Github PK

View Code? Open in Web Editor NEW
26.0 2.0 10.0 191 KB

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

Home Page: https://pub.dev/packages/locale_plus

License: MIT License

Java 22.89% Ruby 9.22% Swift 13.54% Objective-C 2.58% Dart 51.77%
dart flutter flutter-package pubdev flutter-android-ios flutter-app locale

locale_plus's Introduction

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.0.0 <4.0.0"
  • Flutter: ">=3.10.0"
  • Android: minSdkVersion 16
  • iOS 9.0+

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: ^1.6.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();

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.

locale_plus's People

Contributors

bentengbers avatar giovannilattanziocrispy avatar gokberkbar avatar gokhancvs avatar shushper avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

locale_plus's Issues

Intl version

When using flutter_localizations this way:

dependencies:
  flutter:
    sdk: flutter
  flutter_localizations: 
    sdk: flutter

And adding locale_plus: ^1.5.0 I get:

Because locale_plus 1.5.0 depends on intl ^0.18.0 and no versions of locale_plus match >1.5.0 <2.0.0, locale_plus ^1.5.0 requires intl ^0.18.0.
[...]
flutter_localizations from sdk depends on intl 0.19.0, custom_fields from path is incompatible with flutter_localizations from sdk.

My question is, would it be breaking if you replaced intl version for any or something like that?

add support for samsung keyboards

We could also create an edge case for samsung keyboards.
Samsung keyboards on android (from what i understand) do not support , as an decimal separator.
This seems to be a long standing issue.
Perhaps we could adjust our decimal separator based on the keyboard used by the user.
Or we could expose a new function called isUsingSamsungKeyboard to expose an api that shows if the user is using a samsung keyboard.
I have found this relevant stackoverflow answer with some useful code.

Add support for android 14 LocalePreferences API

the API exposes stuff like

  • preferred temperature (C/F) (can be extracted on iOS from metric system)
  • 12/24h (already included here)
  • type of calender (persian, islamic, etc..)
  • starting day of week

these should be forwarded to flutter via this package

i might be able to fire a PR soon

New release

Would it be possible to create a new release on pub.dev?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.