From d9bc8b198dbee9ec11714348932d3d26db008e82 Mon Sep 17 00:00:00 2001 From: Florin Bratan Date: Thu, 25 Mar 2021 09:42:47 +0100 Subject: [PATCH] Fixed web support --- CHANGELOG.md | 6 ++- .../flutter/generated_plugin_registrant.cc | 2 - .../flutter/generated_plugin_registrant.h | 2 - lib/src/utils/device_locale.dart | 49 ++++++++++--------- lib/src/utils/utils.dart | 6 ++- pubspec.yaml | 5 +- 6 files changed, 37 insertions(+), 33 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 10c205a..d6afd7b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -88,4 +88,8 @@ - Removed flutter_device_locale dependency - The native flutter locale retrieval method is now used - Added support for desktop -- Added examples for windows desktop \ No newline at end of file +- Added examples for windows desktop + +## [2.0.1] + +- Fixed web support \ No newline at end of file diff --git a/example/windows/flutter/generated_plugin_registrant.cc b/example/windows/flutter/generated_plugin_registrant.cc index 8b6d468..4bfa0f3 100644 --- a/example/windows/flutter/generated_plugin_registrant.cc +++ b/example/windows/flutter/generated_plugin_registrant.cc @@ -2,8 +2,6 @@ // Generated file. Do not edit. // -// clang-format off - #include "generated_plugin_registrant.h" diff --git a/example/windows/flutter/generated_plugin_registrant.h b/example/windows/flutter/generated_plugin_registrant.h index dc139d8..9846246 100644 --- a/example/windows/flutter/generated_plugin_registrant.h +++ b/example/windows/flutter/generated_plugin_registrant.h @@ -2,8 +2,6 @@ // Generated file. Do not edit. // -// clang-format off - #ifndef GENERATED_PLUGIN_REGISTRANT_ #define GENERATED_PLUGIN_REGISTRANT_ diff --git a/lib/src/utils/device_locale.dart b/lib/src/utils/device_locale.dart index f0bf566..00bc1a1 100644 --- a/lib/src/utils/device_locale.dart +++ b/lib/src/utils/device_locale.dart @@ -1,32 +1,33 @@ -import 'dart:io'; import 'dart:ui'; - import 'package:flutter/widgets.dart'; +import 'package:universal_io/io.dart'; - Locale getCurrentLocale() - { - return _localeFromString(Platform.localeName); - } +/// Returns the current device locale +Locale getCurrentLocale() +{ + return _localeFromString(Platform.localeName); +} - List getPreferredLocales() - { - final deviceLocales = WidgetsBinding.instance.window.locales; +/// Returns preferred device locales +List getPreferredLocales() +{ + final deviceLocales = WidgetsBinding.instance.window.locales; - return deviceLocales; - } + return deviceLocales; +} - Locale _localeFromString(String code) - { - var separator = code.contains('_') ? '_' : code.contains('-') ? '-' : null; +Locale _localeFromString(String code) +{ + var separator = code.contains('_') ? '_' : code.contains('-') ? '-' : null; - if (separator != null) - { - var parts = code.split(RegExp(separator)); + if (separator != null) + { + var parts = code.split(RegExp(separator)); - return Locale(parts[0], parts[1]); - } - else - { - return Locale(code); - } - } \ No newline at end of file + return Locale(parts[0], parts[1]); + } + else + { + return Locale(code); + } +} \ No newline at end of file diff --git a/lib/src/utils/utils.dart b/lib/src/utils/utils.dart index 56df5e5..bda92c3 100644 --- a/lib/src/utils/utils.dart +++ b/lib/src/utils/utils.dart @@ -2,7 +2,6 @@ import 'dart:ui'; import 'package:flutter/widgets.dart'; import 'package:flutter_translate/flutter_translate.dart'; - typedef LocaleChangedCallback = Future Function(Locale locale); Locale localeFromString(String code, {bool languageCodeOnly = false}) @@ -24,16 +23,19 @@ String localeToString(Locale locale) return locale.countryCode != null ? '${locale.languageCode}_${locale.countryCode}' : locale.languageCode; } +/// Translate the selected key into the currently selected locale String translate(String key, {Map args}) { return Localization.instance.translate(key, args: args); } +/// Translate the selected key into the currently selected locale using pluralization String translatePlural(String key, num value, {Map args}) { return Localization.instance.plural(key, value, args: args); } +/// Change the currently selected locale Future changeLocale(BuildContext context, String localeCode) async { if (localeCode != null) @@ -42,4 +44,4 @@ Future changeLocale(BuildContext context, String localeCode) async LocalizationProvider.of(context).state.onLocaleChanged(); } -} +} \ No newline at end of file diff --git a/pubspec.yaml b/pubspec.yaml index daa829e..4697f43 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_translate description: Flutter Translate is a fully featured localization / internationalization (i18n) library for Flutter. -version: 2.0.0 +version: 2.0.1 homepage: https://leadcode.dev repository: https://github.com/bratan/flutter_translate @@ -10,5 +10,6 @@ environment: dependencies: flutter: sdk: flutter + universal_io: ^2.0.1 -flutter: +flutter: \ No newline at end of file