Jonatas

move internacionalization to extensions

@@ -4,11 +4,15 @@ @@ -4,11 +4,15 @@
4 4
5 [![pub package](https://img.shields.io/pub/v/get.svg?label=get&color=blue)](https://pub.dev/packages/get) 5 [![pub package](https://img.shields.io/pub/v/get.svg?label=get&color=blue)](https://pub.dev/packages/get)
6 ![building](https://github.com/jonataslaw/get/workflows/build/badge.svg) 6 ![building](https://github.com/jonataslaw/get/workflows/build/badge.svg)
7 -[![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) 7 +[![style: effective dart](https://img.shields.io/badge/style-effective_dart-40c4ff.svg)](https://pub.dev/packages/effective_dart)
  8 +[![Discord Shield](https://img.shields.io/discord/722900883784073290.svg?logo=discord)](https://discord.com/invite/9Hpt99N)
  9 +[![Get on Slack](https://img.shields.io/badge/slack-join-orange.svg)](https://communityinviter.com/apps/getxworkspace/getx)
  10 +[![Telegram](https://img.shields.io/badge/chat-on%20Telegram-blue.svg)](https://t.me/joinchat/PhdbJRmsZNpAqSLJL6bH7g)
8 <a href="https://github.com/Solido/awesome-flutter"> 11 <a href="https://github.com/Solido/awesome-flutter">
9 -<img alt="Awesome Flutter" src="https://img.shields.io/badge/Awesome-Flutter-blue.svg?longCache=true&style=flat-square" /> 12 + <img alt="Awesome Flutter" src="https://img.shields.io/badge/Awesome-Flutter-blue.svg?longCache=true&style=flat-square" />
10 </a> 13 </a>
11 <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> 14 <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>
  15 +
12 ![](getx.png) 16 ![](getx.png)
13 17
14 <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> 18 <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 @@ @@ -4,6 +4,7 @@
4 4
5 [![pub package](https://img.shields.io/pub/v/get.svg?label=get&color=blue)](https://pub.dev/packages/get) 5 [![pub package](https://img.shields.io/pub/v/get.svg?label=get&color=blue)](https://pub.dev/packages/get)
6 ![building](https://github.com/jonataslaw/get/workflows/build/badge.svg) 6 ![building](https://github.com/jonataslaw/get/workflows/build/badge.svg)
  7 +[![style: effective dart](https://img.shields.io/badge/style-effective_dart-40c4ff.svg)](https://pub.dev/packages/effective_dart)
7 [![Discord Shield](https://img.shields.io/discord/722900883784073290.svg?logo=discord)](https://discord.com/invite/9Hpt99N) 8 [![Discord Shield](https://img.shields.io/discord/722900883784073290.svg?logo=discord)](https://discord.com/invite/9Hpt99N)
8 [![Get on Slack](https://img.shields.io/badge/slack-join-orange.svg)](https://communityinviter.com/apps/getxworkspace/getx) 9 [![Get on Slack](https://img.shields.io/badge/slack-join-orange.svg)](https://communityinviter.com/apps/getxworkspace/getx)
9 [![Telegram](https://img.shields.io/badge/chat-on%20Telegram-blue.svg)](https://t.me/joinchat/PhdbJRmsZNpAqSLJL6bH7g) 10 [![Telegram](https://img.shields.io/badge/chat-on%20Telegram-blue.svg)](https://t.me/joinchat/PhdbJRmsZNpAqSLJL6bH7g)
@@ -4,12 +4,16 @@ @@ -4,12 +4,16 @@
4 4
5 [![pub package](https://img.shields.io/pub/v/get.svg?label=get&color=blue)](https://pub.dev/packages/get) 5 [![pub package](https://img.shields.io/pub/v/get.svg?label=get&color=blue)](https://pub.dev/packages/get)
6 ![building](https://github.com/jonataslaw/get/workflows/build/badge.svg) 6 ![building](https://github.com/jonataslaw/get/workflows/build/badge.svg)
7 -[![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) 7 +[![style: effective dart](https://img.shields.io/badge/style-effective_dart-40c4ff.svg)](https://pub.dev/packages/effective_dart)
  8 +[![Discord Shield](https://img.shields.io/discord/722900883784073290.svg?logo=discord)](https://discord.com/invite/9Hpt99N)
  9 +[![Get on Slack](https://img.shields.io/badge/slack-join-orange.svg)](https://communityinviter.com/apps/getxworkspace/getx)
  10 +[![Telegram](https://img.shields.io/badge/chat-on%20Telegram-blue.svg)](https://t.me/joinchat/PhdbJRmsZNpAqSLJL6bH7g)
8 <a href="https://github.com/Solido/awesome-flutter"> 11 <a href="https://github.com/Solido/awesome-flutter">
9 <img alt="Awesome Flutter" src="https://img.shields.io/badge/Awesome-Flutter-blue.svg?longCache=true&style=flat-square" /> 12 <img alt="Awesome Flutter" src="https://img.shields.io/badge/Awesome-Flutter-blue.svg?longCache=true&style=flat-square" />
10 </a> 13 </a>
11 <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> 14 <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>
12 15
  16 +
13 ![](getx.png) 17 ![](getx.png)
14 18
15 - [Kanały komunikacji i wsparcia:](#kanały-komunikacji-i-wsparcia) 19 - [Kanały komunikacji i wsparcia:](#kanały-komunikacji-i-wsparcia)
@@ -4,12 +4,16 @@ @@ -4,12 +4,16 @@
4 4
5 [![pub package](https://img.shields.io/pub/v/get.svg?label=get&color=blue)](https://pub.dev/packages/get) 5 [![pub package](https://img.shields.io/pub/v/get.svg?label=get&color=blue)](https://pub.dev/packages/get)
6 ![building](https://github.com/jonataslaw/get/workflows/build/badge.svg) 6 ![building](https://github.com/jonataslaw/get/workflows/build/badge.svg)
7 -[![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) 7 +[![style: effective dart](https://img.shields.io/badge/style-effective_dart-40c4ff.svg)](https://pub.dev/packages/effective_dart)
  8 +[![Discord Shield](https://img.shields.io/discord/722900883784073290.svg?logo=discord)](https://discord.com/invite/9Hpt99N)
  9 +[![Get on Slack](https://img.shields.io/badge/slack-join-orange.svg)](https://communityinviter.com/apps/getxworkspace/getx)
  10 +[![Telegram](https://img.shields.io/badge/chat-on%20Telegram-blue.svg)](https://t.me/joinchat/PhdbJRmsZNpAqSLJL6bH7g)
8 <a href="https://github.com/Solido/awesome-flutter"> 11 <a href="https://github.com/Solido/awesome-flutter">
9 <img alt="Awesome Flutter" src="https://img.shields.io/badge/Awesome-Flutter-blue.svg?longCache=true&style=flat-square" /> 12 <img alt="Awesome Flutter" src="https://img.shields.io/badge/Awesome-Flutter-blue.svg?longCache=true&style=flat-square" />
10 </a> 13 </a>
11 <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> 14 <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>
12 15
  16 +
13 ![](getx.png) 17 ![](getx.png)
14 18
15 <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> 19 <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 { @@ -262,52 +262,3 @@ abstract class Translations {
262 Map<String, Map<String, String>> get keys; 262 Map<String, Map<String, String>> get keys;
263 } 263 }
264 264
265 -extension Trans on String {  
266 - String get tr {  
267 - // Returns the key if locale is null.  
268 - if (Get.locale?.languageCode == null) return this;  
269 -  
270 - // Checks whether the language code and country code are present, and  
271 - // whether the key is also present.  
272 - if (Get.translations.containsKey(  
273 - "${Get.locale.languageCode}_${Get.locale.countryCode}") &&  
274 - Get.translations["${Get.locale.languageCode}_${Get.locale.countryCode}"]  
275 - .containsKey(this)) {  
276 - return Get.translations[  
277 - "${Get.locale.languageCode}_${Get.locale.countryCode}"][this];  
278 -  
279 - // Checks if there is a callback language in the absence of the specific  
280 - // country, and if it contains that key.  
281 - } else if (Get.translations.containsKey(Get.locale.languageCode) &&  
282 - Get.translations[Get.locale.languageCode].containsKey(this)) {  
283 - return Get.translations[Get.locale.languageCode][this];  
284 - // If there is no corresponding language or corresponding key, return  
285 - // the key.  
286 - } else if (Get.fallbackLocale != null) {  
287 - final fallback = Get.fallbackLocale;  
288 - final key = "${fallback.languageCode}_${fallback.countryCode}";  
289 -  
290 - if (Get.translations.containsKey(key) &&  
291 - Get.translations[key].containsKey(this)) {  
292 - return Get.translations[key][this];  
293 - }  
294 - if (Get.translations.containsKey(fallback.languageCode) &&  
295 - Get.translations[fallback.languageCode].containsKey(this)) {  
296 - return Get.translations[fallback.languageCode][this];  
297 - }  
298 - return this;  
299 - } else {  
300 - return this;  
301 - }  
302 - }  
303 -  
304 - String trArgs([List<String> args]) {  
305 - var key = tr;  
306 - if (args != null) {  
307 - for (final arg in args) {  
308 - key = key.replaceFirst(RegExp(r'%s'), arg.toString());  
309 - }  
310 - }  
311 - return key;  
312 - }  
313 -}  
@@ -211,12 +211,13 @@ class _GetBuilderState<T extends GetxController> extends State<GetBuilder<T>> @@ -211,12 +211,13 @@ class _GetBuilderState<T extends GetxController> extends State<GetBuilder<T>>
211 : controller?.addListenerId(widget.id, getUpdate); 211 : controller?.addListenerId(widget.id, getUpdate);
212 } 212 }
213 213
214 - /// Sample for [GetStateUpdate] when you don't wanna use [GetStateHelper mixin].  
215 -// bool _getUpdater() {  
216 -// final _mounted = mounted;  
217 -// if (_mounted) setState(() {});  
218 -// return _mounted;  
219 -// } 214 + /// Sample for [GetStateUpdate] when you don't wanna
  215 + /// use [GetStateHelper mixin].
  216 + /// bool _getUpdater() {
  217 + /// final _mounted = mounted;
  218 + /// if (_mounted) setState(() {});
  219 + /// return _mounted;
  220 + /// }
220 221
221 @override 222 @override
222 void dispose() { 223 void dispose() {
@@ -24,7 +24,9 @@ import '../../instance/get_instance.dart'; @@ -24,7 +24,9 @@ import '../../instance/get_instance.dart';
24 abstract class GetView<T> extends StatelessWidget { 24 abstract class GetView<T> extends StatelessWidget {
25 const GetView({Key key}) : super(key: key); 25 const GetView({Key key}) : super(key: key);
26 26
27 - T get controller => GetInstance().find<T>(); 27 + final String tag = null;
  28 +
  29 + T get controller => GetInstance().find<T>(tag: tag);
28 30
29 @override 31 @override
30 Widget build(BuildContext context); 32 Widget build(BuildContext context);
@@ -35,6 +37,8 @@ abstract class GetWidget<T> extends StatelessWidget { @@ -35,6 +37,8 @@ abstract class GetWidget<T> extends StatelessWidget {
35 37
36 final Set<T> _value = <T>{}; 38 final Set<T> _value = <T>{};
37 39
  40 + final String tag = null;
  41 +
38 T get controller { 42 T get controller {
39 if (_value.isEmpty) _value.add(GetInstance().find<T>()); 43 if (_value.isEmpty) _value.add(GetInstance().find<T>());
40 return _value.first; 44 return _value.first;
1 -import 'package:flutter/foundation.dart';  
2 -import 'package:flutter/material.dart';  
3 -import 'package:flutter/widgets.dart';  
4 -  
5 -extension ContextExtensionss on BuildContext {  
6 - /// The same of [MediaQuery.of(context).size]  
7 - Size get mediaQuerySize => MediaQuery.of(this).size;  
8 -  
9 - /// The same of [MediaQuery.of(context).size.height]  
10 - /// Note: updates when you rezise your screen (like on a browser or  
11 - /// desktop window)  
12 - double get height => mediaQuerySize.height;  
13 -  
14 - /// The same of [MediaQuery.of(context).size.width]  
15 - /// Note: updates when you rezise your screen (like on a browser or  
16 - /// desktop window)  
17 - double get width => mediaQuerySize.width;  
18 -  
19 - /// Gives you the power to get a portion of the height.  
20 - /// Useful for responsive applications.  
21 - ///  
22 - /// [dividedBy] is for when you want to have a portion of the value you  
23 - /// would get like for example: if you want a value that represents a third  
24 - /// of the screen you can set it to 3, and you will get a third of the height  
25 - ///  
26 - /// [reducedBy] is a percentage value of how much of the height you want  
27 - /// if you for example want 46% of the height, then you reduce it by 56%.  
28 - double heightTransformer({double dividedBy = 1, double reducedBy = 0.0}) {  
29 - return (mediaQuerySize.height -  
30 - ((mediaQuerySize.height / 100) * reducedBy)) /  
31 - dividedBy;  
32 - }  
33 -  
34 - /// Gives you the power to get a portion of the width.  
35 - /// Useful for responsive applications.  
36 - ///  
37 - /// [dividedBy] is for when you want to have a portion of the value you  
38 - /// would get like for example: if you want a value that represents a third  
39 - /// of the screen you can set it to 3, and you will get a third of the width  
40 - ///  
41 - /// [reducedBy] is a percentage value of how much of the width you want  
42 - /// if you for example want 46% of the width, then you reduce it by 56%.  
43 - double widthTransformer({double dividedBy = 1, double reducedBy = 0.0}) {  
44 - return (mediaQuerySize.width - ((mediaQuerySize.width / 100) * reducedBy)) /  
45 - dividedBy;  
46 - }  
47 -  
48 - /// Divide the height proportionally by the given value  
49 - double ratio({  
50 - double dividedBy = 1,  
51 - double reducedByW = 0.0,  
52 - double reducedByH = 0.0,  
53 - }) {  
54 - return heightTransformer(dividedBy: dividedBy, reducedBy: reducedByH) /  
55 - widthTransformer(dividedBy: dividedBy, reducedBy: reducedByW);  
56 - }  
57 -  
58 - /// similar to [MediaQuery.of(context).padding]  
59 - ThemeData get theme => Theme.of(this);  
60 -  
61 - /// similar to [MediaQuery.of(context).padding]  
62 - TextTheme get textTheme => Theme.of(this).textTheme;  
63 -  
64 - /// similar to [MediaQuery.of(context).padding]  
65 - EdgeInsets get mediaQueryPadding => MediaQuery.of(this).padding;  
66 -  
67 - /// similar to [MediaQuery.of(context).padding]  
68 - MediaQueryData get mediaQuery => MediaQuery.of(this);  
69 -  
70 - /// similar to [MediaQuery.of(context).viewPadding]  
71 - EdgeInsets get mediaQueryViewPadding => MediaQuery.of(this).viewPadding;  
72 -  
73 - /// similar to [MediaQuery.of(context).viewInsets]  
74 - EdgeInsets get mediaQueryViewInsets => MediaQuery.of(this).viewInsets;  
75 -  
76 - /// similar to [MediaQuery.of(context).orientation]  
77 - Orientation get orientation => MediaQuery.of(this).orientation;  
78 -  
79 - /// check if device is on landscape mode  
80 - bool get isLandscape => orientation == Orientation.landscape;  
81 -  
82 - /// check if device is on portrait mode  
83 - bool get isPortrait => orientation == Orientation.portrait;  
84 -  
85 - /// similar to [MediaQuery.of(this).devicePixelRatio]  
86 - double get devicePixelRatio => MediaQuery.of(this).devicePixelRatio;  
87 -  
88 - /// similar to [MediaQuery.of(this).textScaleFactor]  
89 - double get textScaleFactor => MediaQuery.of(this).textScaleFactor;  
90 -  
91 - /// get the shortestSide from screen  
92 - double get mediaQueryShortestSide => mediaQuerySize.shortestSide;  
93 -  
94 - /// True if width be larger than 800  
95 - bool get showNavbar => (width > 800);  
96 -  
97 - /// True if the shortestSide is smaller than 600p  
98 - bool get isPhone => (mediaQueryShortestSide < 600);  
99 -  
100 - /// True if the shortestSide is largest than 600p  
101 - bool get isSmallTablet => (mediaQueryShortestSide >= 600);  
102 -  
103 - /// True if the shortestSide is largest than 720p  
104 - bool get isLargeTablet => (mediaQueryShortestSide >= 720);  
105 -  
106 - /// True if the current device is Tablet  
107 - bool get isTablet => isSmallTablet || isLargeTablet;  
108 -  
109 - /// Returns a specific value according to the screen size  
110 - /// if the device width is higher than or equal to 1200 return [desktop]  
111 - /// value.  
112 - /// if the device width is higher than or equal to 600 and less than 1200  
113 - /// return [tablet] value.  
114 - /// if the device width is less than 300 return [watch] value.  
115 - /// in other cases return [mobile] value.  
116 - T responsiveValue<T>({  
117 - T mobile,  
118 - T tablet,  
119 - T desktop,  
120 - T watch,  
121 - }) {  
122 - var deviceWidth = mediaQuerySize.shortestSide;  
123 -  
124 - if (kIsWeb) {  
125 - deviceWidth = mediaQuerySize.width;  
126 - }  
127 - if (deviceWidth >= 1200 && desktop != null) return desktop;  
128 - if (deviceWidth >= 600 && tablet != null) return tablet;  
129 - if (deviceWidth < 300 && watch != null) return watch;  
130 - return mobile;  
131 - }  
132 -}  
@@ -2,6 +2,7 @@ export 'context_extensions.dart'; @@ -2,6 +2,7 @@ export 'context_extensions.dart';
2 export 'double_extensions.dart'; 2 export 'double_extensions.dart';
3 export 'duration_extensions.dart'; 3 export 'duration_extensions.dart';
4 export 'dynamic_extensions.dart'; 4 export 'dynamic_extensions.dart';
  5 +export 'internacionalization.dart';
5 export 'num_extensions.dart'; 6 export 'num_extensions.dart';
6 export 'string_extensions.dart'; 7 export 'string_extensions.dart';
7 export 'widget_extensions.dart'; 8 export 'widget_extensions.dart';
  1 +import '../../core/get_main.dart';
  2 +
  3 +extension Trans on String {
  4 + String get tr {
  5 + // Returns the key if locale is null.
  6 + if (Get.locale?.languageCode == null) return this;
  7 +
  8 + // Checks whether the language code and country code are present, and
  9 + // whether the key is also present.
  10 + if (Get.translations.containsKey(
  11 + "${Get.locale.languageCode}_${Get.locale.countryCode}") &&
  12 + Get.translations["${Get.locale.languageCode}_${Get.locale.countryCode}"]
  13 + .containsKey(this)) {
  14 + return Get.translations[
  15 + "${Get.locale.languageCode}_${Get.locale.countryCode}"][this];
  16 +
  17 + // Checks if there is a callback language in the absence of the specific
  18 + // country, and if it contains that key.
  19 + } else if (Get.translations.containsKey(Get.locale.languageCode) &&
  20 + Get.translations[Get.locale.languageCode].containsKey(this)) {
  21 + return Get.translations[Get.locale.languageCode][this];
  22 + // If there is no corresponding language or corresponding key, return
  23 + // the key.
  24 + } else if (Get.fallbackLocale != null) {
  25 + final fallback = Get.fallbackLocale;
  26 + final key = "${fallback.languageCode}_${fallback.countryCode}";
  27 +
  28 + if (Get.translations.containsKey(key) &&
  29 + Get.translations[key].containsKey(this)) {
  30 + return Get.translations[key][this];
  31 + }
  32 + if (Get.translations.containsKey(fallback.languageCode) &&
  33 + Get.translations[fallback.languageCode].containsKey(this)) {
  34 + return Get.translations[fallback.languageCode][this];
  35 + }
  36 + return this;
  37 + } else {
  38 + return this;
  39 + }
  40 + }
  41 +
  42 + String trArgs([List<String> args]) {
  43 + var key = tr;
  44 + if (args != null) {
  45 + for (final arg in args) {
  46 + key = key.replaceFirst(RegExp(r'%s'), arg.toString());
  47 + }
  48 + }
  49 + return key;
  50 + }
  51 +}