Skip to content

Commit

Permalink
Fixed web support
Browse files Browse the repository at this point in the history
  • Loading branch information
bratan committed Mar 25, 2021
1 parent 1caf61c commit d9bc8b1
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 33 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
- Added examples for windows desktop

## [2.0.1]

- Fixed web support
2 changes: 0 additions & 2 deletions example/windows/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// Generated file. Do not edit.
//

// clang-format off

#include "generated_plugin_registrant.h"


Expand Down
2 changes: 0 additions & 2 deletions example/windows/flutter/generated_plugin_registrant.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// Generated file. Do not edit.
//

// clang-format off

#ifndef GENERATED_PLUGIN_REGISTRANT_
#define GENERATED_PLUGIN_REGISTRANT_

Expand Down
49 changes: 25 additions & 24 deletions lib/src/utils/device_locale.dart
Original file line number Diff line number Diff line change
@@ -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<Locale> getPreferredLocales()
{
final deviceLocales = WidgetsBinding.instance.window.locales;
/// Returns preferred device locales
List<Locale> 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);
}
}
return Locale(parts[0], parts[1]);
}
else
{
return Locale(code);
}
}
6 changes: 4 additions & 2 deletions lib/src/utils/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand All @@ -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<String, dynamic> 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<String, dynamic> args})
{
return Localization.instance.plural(key, value, args: args);
}

/// Change the currently selected locale
Future changeLocale(BuildContext context, String localeCode) async
{
if (localeCode != null)
Expand All @@ -42,4 +44,4 @@ Future changeLocale(BuildContext context, String localeCode) async

LocalizationProvider.of(context).state.onLocaleChanged();
}
}
}
5 changes: 3 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -10,5 +10,6 @@ environment:
dependencies:
flutter:
sdk: flutter
universal_io: ^2.0.1

flutter:
flutter:

0 comments on commit d9bc8b1

Please sign in to comment.