Jonatas

move internacionalization to extensions

... ... @@ -4,11 +4,15 @@
[![pub package](https://img.shields.io/pub/v/get.svg?label=get&color=blue)](https://pub.dev/packages/get)
![building](https://github.com/jonataslaw/get/workflows/build/badge.svg)
[![Gitter](https://badges.gitter.im/flutter_get/community.svg)](https://gitter.im/flutter_get/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
[![style: effective dart](https://img.shields.io/badge/style-effective_dart-40c4ff.svg)](https://pub.dev/packages/effective_dart)
[![Discord Shield](https://img.shields.io/discord/722900883784073290.svg?logo=discord)](https://discord.com/invite/9Hpt99N)
[![Get on Slack](https://img.shields.io/badge/slack-join-orange.svg)](https://communityinviter.com/apps/getxworkspace/getx)
[![Telegram](https://img.shields.io/badge/chat-on%20Telegram-blue.svg)](https://t.me/joinchat/PhdbJRmsZNpAqSLJL6bH7g)
<a href="https://github.com/Solido/awesome-flutter">
<img alt="Awesome Flutter" src="https://img.shields.io/badge/Awesome-Flutter-blue.svg?longCache=true&style=flat-square" />
<img alt="Awesome Flutter" src="https://img.shields.io/badge/Awesome-Flutter-blue.svg?longCache=true&style=flat-square" />
</a>
<a href="https://www.buymeacoffee.com/jonataslaw" target="_blank"><img src="https://i.imgur.com/aV6DDA7.png" alt="Buy Me A Coffee" style="height: 41px !important;width: 174px !important; box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;-webkit-box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;" > </a>
![](getx.png)
<h3>Lamentamos la inconsistencia en la traducción. El paquete GetX se actualiza con bastante frecuencia y es posible que las traducciones a documentos no sean tan rápidas. Entonces, para que esta documentación aún tenga todo el contenido, dejaré aquí todos los textos nuevos sin traducir (considero que es mejor tener los documentos en inglés que no tenerlos), por lo que si alguien quiere traducir, sería de gran ayuda 😁</h3>
... ...
... ... @@ -4,6 +4,7 @@
[![pub package](https://img.shields.io/pub/v/get.svg?label=get&color=blue)](https://pub.dev/packages/get)
![building](https://github.com/jonataslaw/get/workflows/build/badge.svg)
[![style: effective dart](https://img.shields.io/badge/style-effective_dart-40c4ff.svg)](https://pub.dev/packages/effective_dart)
[![Discord Shield](https://img.shields.io/discord/722900883784073290.svg?logo=discord)](https://discord.com/invite/9Hpt99N)
[![Get on Slack](https://img.shields.io/badge/slack-join-orange.svg)](https://communityinviter.com/apps/getxworkspace/getx)
[![Telegram](https://img.shields.io/badge/chat-on%20Telegram-blue.svg)](https://t.me/joinchat/PhdbJRmsZNpAqSLJL6bH7g)
... ...
... ... @@ -4,12 +4,16 @@
[![pub package](https://img.shields.io/pub/v/get.svg?label=get&color=blue)](https://pub.dev/packages/get)
![building](https://github.com/jonataslaw/get/workflows/build/badge.svg)
[![Gitter](https://badges.gitter.im/flutter_get/community.svg)](https://gitter.im/flutter_get/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
[![style: effective dart](https://img.shields.io/badge/style-effective_dart-40c4ff.svg)](https://pub.dev/packages/effective_dart)
[![Discord Shield](https://img.shields.io/discord/722900883784073290.svg?logo=discord)](https://discord.com/invite/9Hpt99N)
[![Get on Slack](https://img.shields.io/badge/slack-join-orange.svg)](https://communityinviter.com/apps/getxworkspace/getx)
[![Telegram](https://img.shields.io/badge/chat-on%20Telegram-blue.svg)](https://t.me/joinchat/PhdbJRmsZNpAqSLJL6bH7g)
<a href="https://github.com/Solido/awesome-flutter">
<img alt="Awesome Flutter" src="https://img.shields.io/badge/Awesome-Flutter-blue.svg?longCache=true&style=flat-square" />
</a>
<a href="https://www.buymeacoffee.com/jonataslaw" target="_blank"><img src="https://i.imgur.com/aV6DDA7.png" alt="Buy Me A Coffee" style="height: 41px !important;width: 174px !important; box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;-webkit-box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;" > </a>
![](getx.png)
- [Kanały komunikacji i wsparcia:](#kanały-komunikacji-i-wsparcia)
... ...
... ... @@ -4,12 +4,16 @@
[![pub package](https://img.shields.io/pub/v/get.svg?label=get&color=blue)](https://pub.dev/packages/get)
![building](https://github.com/jonataslaw/get/workflows/build/badge.svg)
[![Gitter](https://badges.gitter.im/flutter_get/community.svg)](https://gitter.im/flutter_get/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
[![style: effective dart](https://img.shields.io/badge/style-effective_dart-40c4ff.svg)](https://pub.dev/packages/effective_dart)
[![Discord Shield](https://img.shields.io/discord/722900883784073290.svg?logo=discord)](https://discord.com/invite/9Hpt99N)
[![Get on Slack](https://img.shields.io/badge/slack-join-orange.svg)](https://communityinviter.com/apps/getxworkspace/getx)
[![Telegram](https://img.shields.io/badge/chat-on%20Telegram-blue.svg)](https://t.me/joinchat/PhdbJRmsZNpAqSLJL6bH7g)
<a href="https://github.com/Solido/awesome-flutter">
<img alt="Awesome Flutter" src="https://img.shields.io/badge/Awesome-Flutter-blue.svg?longCache=true&style=flat-square" />
</a>
<a href="https://www.buymeacoffee.com/jonataslaw" target="_blank"><img src="https://i.imgur.com/aV6DDA7.png" alt="Buy Me A Coffee" style="height: 41px !important;width: 174px !important; box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;-webkit-box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;" > </a>
![](getx.png)
<h2> Pedimos desculpas por qualquer parte não traduzida aqui. O GetX é atualizado com muita frequência e as traduções podem não vir ao mesmo tempo. Então, para manter essa documentação pelo menos com tudo que a versão em inglês tem, eu vou deixar todos os textos não-traduzidos aqui (eu considero que é melhor ele estar lá em inglês do que não estar), então se alguém quiser traduzir, seria muito útil 😁</h2>
... ...
... ... @@ -262,52 +262,3 @@ abstract class Translations {
Map<String, Map<String, String>> get keys;
}
extension Trans on String {
String get tr {
// Returns the key if locale is null.
if (Get.locale?.languageCode == null) return this;
// Checks whether the language code and country code are present, and
// whether the key is also present.
if (Get.translations.containsKey(
"${Get.locale.languageCode}_${Get.locale.countryCode}") &&
Get.translations["${Get.locale.languageCode}_${Get.locale.countryCode}"]
.containsKey(this)) {
return Get.translations[
"${Get.locale.languageCode}_${Get.locale.countryCode}"][this];
// Checks if there is a callback language in the absence of the specific
// country, and if it contains that key.
} else if (Get.translations.containsKey(Get.locale.languageCode) &&
Get.translations[Get.locale.languageCode].containsKey(this)) {
return Get.translations[Get.locale.languageCode][this];
// If there is no corresponding language or corresponding key, return
// the key.
} else if (Get.fallbackLocale != null) {
final fallback = Get.fallbackLocale;
final key = "${fallback.languageCode}_${fallback.countryCode}";
if (Get.translations.containsKey(key) &&
Get.translations[key].containsKey(this)) {
return Get.translations[key][this];
}
if (Get.translations.containsKey(fallback.languageCode) &&
Get.translations[fallback.languageCode].containsKey(this)) {
return Get.translations[fallback.languageCode][this];
}
return this;
} else {
return this;
}
}
String trArgs([List<String> args]) {
var key = tr;
if (args != null) {
for (final arg in args) {
key = key.replaceFirst(RegExp(r'%s'), arg.toString());
}
}
return key;
}
}
... ...
... ... @@ -211,12 +211,13 @@ class _GetBuilderState<T extends GetxController> extends State<GetBuilder<T>>
: controller?.addListenerId(widget.id, getUpdate);
}
/// Sample for [GetStateUpdate] when you don't wanna use [GetStateHelper mixin].
// bool _getUpdater() {
// final _mounted = mounted;
// if (_mounted) setState(() {});
// return _mounted;
// }
/// Sample for [GetStateUpdate] when you don't wanna
/// use [GetStateHelper mixin].
/// bool _getUpdater() {
/// final _mounted = mounted;
/// if (_mounted) setState(() {});
/// return _mounted;
/// }
@override
void dispose() {
... ...
... ... @@ -24,7 +24,9 @@ import '../../instance/get_instance.dart';
abstract class GetView<T> extends StatelessWidget {
const GetView({Key key}) : super(key: key);
T get controller => GetInstance().find<T>();
final String tag = null;
T get controller => GetInstance().find<T>(tag: tag);
@override
Widget build(BuildContext context);
... ... @@ -35,6 +37,8 @@ abstract class GetWidget<T> extends StatelessWidget {
final Set<T> _value = <T>{};
final String tag = null;
T get controller {
if (_value.isEmpty) _value.add(GetInstance().find<T>());
return _value.first;
... ...
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
extension ContextExtensionss on BuildContext {
/// The same of [MediaQuery.of(context).size]
Size get mediaQuerySize => MediaQuery.of(this).size;
/// The same of [MediaQuery.of(context).size.height]
/// Note: updates when you rezise your screen (like on a browser or
/// desktop window)
double get height => mediaQuerySize.height;
/// The same of [MediaQuery.of(context).size.width]
/// Note: updates when you rezise your screen (like on a browser or
/// desktop window)
double get width => mediaQuerySize.width;
/// Gives you the power to get a portion of the height.
/// Useful for responsive applications.
///
/// [dividedBy] is for when you want to have a portion of the value you
/// would get like for example: if you want a value that represents a third
/// of the screen you can set it to 3, and you will get a third of the height
///
/// [reducedBy] is a percentage value of how much of the height you want
/// if you for example want 46% of the height, then you reduce it by 56%.
double heightTransformer({double dividedBy = 1, double reducedBy = 0.0}) {
return (mediaQuerySize.height -
((mediaQuerySize.height / 100) * reducedBy)) /
dividedBy;
}
/// Gives you the power to get a portion of the width.
/// Useful for responsive applications.
///
/// [dividedBy] is for when you want to have a portion of the value you
/// would get like for example: if you want a value that represents a third
/// of the screen you can set it to 3, and you will get a third of the width
///
/// [reducedBy] is a percentage value of how much of the width you want
/// if you for example want 46% of the width, then you reduce it by 56%.
double widthTransformer({double dividedBy = 1, double reducedBy = 0.0}) {
return (mediaQuerySize.width - ((mediaQuerySize.width / 100) * reducedBy)) /
dividedBy;
}
/// Divide the height proportionally by the given value
double ratio({
double dividedBy = 1,
double reducedByW = 0.0,
double reducedByH = 0.0,
}) {
return heightTransformer(dividedBy: dividedBy, reducedBy: reducedByH) /
widthTransformer(dividedBy: dividedBy, reducedBy: reducedByW);
}
/// similar to [MediaQuery.of(context).padding]
ThemeData get theme => Theme.of(this);
/// similar to [MediaQuery.of(context).padding]
TextTheme get textTheme => Theme.of(this).textTheme;
/// similar to [MediaQuery.of(context).padding]
EdgeInsets get mediaQueryPadding => MediaQuery.of(this).padding;
/// similar to [MediaQuery.of(context).padding]
MediaQueryData get mediaQuery => MediaQuery.of(this);
/// similar to [MediaQuery.of(context).viewPadding]
EdgeInsets get mediaQueryViewPadding => MediaQuery.of(this).viewPadding;
/// similar to [MediaQuery.of(context).viewInsets]
EdgeInsets get mediaQueryViewInsets => MediaQuery.of(this).viewInsets;
/// similar to [MediaQuery.of(context).orientation]
Orientation get orientation => MediaQuery.of(this).orientation;
/// check if device is on landscape mode
bool get isLandscape => orientation == Orientation.landscape;
/// check if device is on portrait mode
bool get isPortrait => orientation == Orientation.portrait;
/// similar to [MediaQuery.of(this).devicePixelRatio]
double get devicePixelRatio => MediaQuery.of(this).devicePixelRatio;
/// similar to [MediaQuery.of(this).textScaleFactor]
double get textScaleFactor => MediaQuery.of(this).textScaleFactor;
/// get the shortestSide from screen
double get mediaQueryShortestSide => mediaQuerySize.shortestSide;
/// True if width be larger than 800
bool get showNavbar => (width > 800);
/// True if the shortestSide is smaller than 600p
bool get isPhone => (mediaQueryShortestSide < 600);
/// True if the shortestSide is largest than 600p
bool get isSmallTablet => (mediaQueryShortestSide >= 600);
/// True if the shortestSide is largest than 720p
bool get isLargeTablet => (mediaQueryShortestSide >= 720);
/// True if the current device is Tablet
bool get isTablet => isSmallTablet || isLargeTablet;
/// Returns a specific value according to the screen size
/// if the device width is higher than or equal to 1200 return [desktop]
/// value.
/// if the device width is higher than or equal to 600 and less than 1200
/// return [tablet] value.
/// if the device width is less than 300 return [watch] value.
/// in other cases return [mobile] value.
T responsiveValue<T>({
T mobile,
T tablet,
T desktop,
T watch,
}) {
var deviceWidth = mediaQuerySize.shortestSide;
if (kIsWeb) {
deviceWidth = mediaQuerySize.width;
}
if (deviceWidth >= 1200 && desktop != null) return desktop;
if (deviceWidth >= 600 && tablet != null) return tablet;
if (deviceWidth < 300 && watch != null) return watch;
return mobile;
}
}
... ... @@ -2,6 +2,7 @@ export 'context_extensions.dart';
export 'double_extensions.dart';
export 'duration_extensions.dart';
export 'dynamic_extensions.dart';
export 'internacionalization.dart';
export 'num_extensions.dart';
export 'string_extensions.dart';
export 'widget_extensions.dart';
... ...
import '../../core/get_main.dart';
extension Trans on String {
String get tr {
// Returns the key if locale is null.
if (Get.locale?.languageCode == null) return this;
// Checks whether the language code and country code are present, and
// whether the key is also present.
if (Get.translations.containsKey(
"${Get.locale.languageCode}_${Get.locale.countryCode}") &&
Get.translations["${Get.locale.languageCode}_${Get.locale.countryCode}"]
.containsKey(this)) {
return Get.translations[
"${Get.locale.languageCode}_${Get.locale.countryCode}"][this];
// Checks if there is a callback language in the absence of the specific
// country, and if it contains that key.
} else if (Get.translations.containsKey(Get.locale.languageCode) &&
Get.translations[Get.locale.languageCode].containsKey(this)) {
return Get.translations[Get.locale.languageCode][this];
// If there is no corresponding language or corresponding key, return
// the key.
} else if (Get.fallbackLocale != null) {
final fallback = Get.fallbackLocale;
final key = "${fallback.languageCode}_${fallback.countryCode}";
if (Get.translations.containsKey(key) &&
Get.translations[key].containsKey(this)) {
return Get.translations[key][this];
}
if (Get.translations.containsKey(fallback.languageCode) &&
Get.translations[fallback.languageCode].containsKey(this)) {
return Get.translations[fallback.languageCode][this];
}
return this;
} else {
return this;
}
}
String trArgs([List<String> args]) {
var key = tr;
if (args != null) {
for (final arg in args) {
key = key.replaceFirst(RegExp(r'%s'), arg.toString());
}
}
return key;
}
}
... ...