Skip to content

Commit

Permalink
Added Label
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobaraujo7 committed Oct 8, 2024
1 parent d5b1dd8 commit 619be13
Show file tree
Hide file tree
Showing 65 changed files with 350 additions and 182 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.1.0

* Added Label

## 1.0.1

* Added valid greaterThanOrEqualTo, greaterThan, lessThanOrEqualTo, lessThan, inclusiveBetween and exclusiveBetween
Expand Down
3 changes: 2 additions & 1 deletion example/lib/domain/dtos/register_param_dto.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ class RegisterParamDto extends ChangeNotifier {
_password = password,
_confirmPassword = confirmPassword;

factory RegisterParamDto.empty() => RegisterParamDto(email: '', password: '', phone: '', confirmPassword: '');
factory RegisterParamDto.empty() =>
RegisterParamDto(email: '', password: '', phone: '', confirmPassword: '');

void setEmail(String value) {
_email = value;
Expand Down
12 changes: 8 additions & 4 deletions example/lib/domain/validations/language_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ import 'package:lucid_validation/lucid_validation.dart';

class CustomLanguageManager extends LanguageManager {
CustomLanguageManager() {
addTranslation(Culture('pt', 'BR'), 'passwordEqualTo', "'{PropertyName}' deve ser igual.");
addTranslation(Culture('pt'), 'passwordEqualTo', "'{PropertyName}' deve ser igual.");
addTranslation(Culture('en', 'US'), 'passwordEqualTo', "'{PropertyName}' must be equal.");
addTranslation(Culture('en'), 'passwordEqualTo', "'{PropertyName}' must be equal.");
addTranslation(Culture('pt', 'BR'), 'passwordEqualTo',
"'{PropertyName}' deve ser igual.");
addTranslation(
Culture('pt'), 'passwordEqualTo', "'{PropertyName}' deve ser igual.");
addTranslation(Culture('en', 'US'), 'passwordEqualTo',
"'{PropertyName}' must be equal.");
addTranslation(
Culture('en'), 'passwordEqualTo', "'{PropertyName}' must be equal.");
}
}
6 changes: 4 additions & 2 deletions example/lib/domain/validations/register_param_validation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ class RegisterParamValidation extends LucidValidator<RegisterParamDto> {
ruleFor((registerParamDto) => registerParamDto.password, key: 'password') //
.customValidPassword();

ruleFor((registerParamDto) => registerParamDto.confirmPassword, key: 'confirmPassword') //
ruleFor((registerParamDto) => registerParamDto.confirmPassword,
key: 'confirmPassword') //
.customValidPassword()
.equalTo((registerParamDto) => registerParamDto.password, code: 'passwordEqualTo');
.equalTo((registerParamDto) => registerParamDto.password,
code: 'passwordEqualTo');

ruleFor((registerParamDto) => registerParamDto.phone, key: 'phone') //
.customValidPhone();
Expand Down
6 changes: 4 additions & 2 deletions example/lib/presentation/login_page/login_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ class _LoginPageState extends State<LoginPage> {
return Switch(
value: globalLocale.value.languageCode == 'en',
onChanged: (value) {
globalLocale.value = value ? Locale('en', 'US') : Locale('pt', 'BR');
globalLocale.value =
value ? Locale('en', 'US') : Locale('pt', 'BR');
},
);
}),
Expand Down Expand Up @@ -97,7 +98,8 @@ class _LoginPageState extends State<LoginPage> {
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => const RegisterPage()),
MaterialPageRoute(
builder: (context) => const RegisterPage()),
);
},
child: const Text('Sign up'),
Expand Down
6 changes: 4 additions & 2 deletions example/lib/presentation/register_page/register_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ class _RegisterPageState extends State<RegisterPage> {
/// call to api passing the parameter loginParamDto
ScaffoldMessenger.of(context).showSnackBar(sucessSnackBar());
} else {
ScaffoldMessenger.of(context).showSnackBar(failureSnackBar(result.exceptions.first.message));
ScaffoldMessenger.of(context)
.showSnackBar(failureSnackBar(result.exceptions.first.message));
}
}

Expand All @@ -67,7 +68,8 @@ class _RegisterPageState extends State<RegisterPage> {
return Switch(
value: globalLocale.value.languageCode == 'en',
onChanged: (value) {
globalLocale.value = value ? Locale('en', 'US') : Locale('pt', 'BR');
globalLocale.value =
value ? Locale('en', 'US') : Locale('pt', 'BR');
},
);
}),
Expand Down
6 changes: 3 additions & 3 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.0.7"
version: "1.0.1"
matcher:
dependency: transitive
description:
Expand Down Expand Up @@ -224,10 +224,10 @@ packages:
dependency: transitive
description:
name: vm_service
sha256: f652077d0bdf60abe4c1f6377448e8655008eef28f128bc023f7b5e8dfeb48fc
sha256: "5c5f338a667b4c644744b661f309fb8080bb94b18a7e91ef1dbd343bed00ed6d"
url: "https://pub.dev"
source: hosted
version: "14.2.4"
version: "14.2.5"
sdks:
dart: ">=3.4.3 <4.0.0"
flutter: ">=3.18.0-18.0.pre.54"
3 changes: 2 additions & 1 deletion lib/src/localization/culture.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ class Culture {
bool operator ==(covariant Culture other) {
if (identical(this, other)) return true;

return other.languageCode == languageCode && other.countryCode == countryCode;
return other.languageCode == languageCode &&
other.countryCode == countryCode;
}

@override
Expand Down
51 changes: 34 additions & 17 deletions lib/src/localization/language.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,34 +37,51 @@ abstract class Language {

final _translations = <String, String>{
code.equalTo: "'{PropertyName}' must be equal to '{ComparisonValue}'.",
code.greaterThan: "'{PropertyName}' must be greater than '{ComparisonValue}'.",
code.greaterThan:
"'{PropertyName}' must be greater than '{ComparisonValue}'.",
code.isEmpty: "'{PropertyName}' must be empty.",
code.isNotNull: "'{PropertyName}' must not be null.",
code.isNull: "'{PropertyName}' must be null.",
code.lessThan: "'{PropertyName}' must be less than '{ComparisonValue}'.",
code.matchesPattern: "'{PropertyName}' is not in the correct format.",
code.max: "'{PropertyName}' must be less than or equal to {MaxValue}. You entered {PropertyValue}.",
code.maxLength: "The length of '{PropertyName}' must be {MaxLength} characters or fewer. You entered {TotalLength} characters.",
code.min: "'{PropertyName}' must be greater than or equal to {MinValue}. You entered {PropertyValue}.",
code.minLength: "The length of '{PropertyName}' must be at least {MinLength} characters. You entered {TotalLength} characters.",
code.mustHaveLowercase: "'{PropertyName}' must have at least one lowercase letter.",
code.mustHaveNumber: "'{PropertyName}' must have at least one digit ('0'-'9').",
code.mustHaveSpecialCharacter: "'{PropertyName}' must have at least one non-alphanumeric character.",
code.mustHaveUppercase: "'{PropertyName}' must have at least one uppercase letter.",
code.max:
"'{PropertyName}' must be less than or equal to {MaxValue}. You entered {PropertyValue}.",
code.maxLength:
"The length of '{PropertyName}' must be {MaxLength} characters or fewer. You entered {TotalLength} characters.",
code.min:
"'{PropertyName}' must be greater than or equal to {MinValue}. You entered {PropertyValue}.",
code.minLength:
"The length of '{PropertyName}' must be at least {MinLength} characters. You entered {TotalLength} characters.",
code.mustHaveLowercase:
"'{PropertyName}' must have at least one lowercase letter.",
code.mustHaveNumber:
"'{PropertyName}' must have at least one digit ('0'-'9').",
code.mustHaveSpecialCharacter:
"'{PropertyName}' must have at least one non-alphanumeric character.",
code.mustHaveUppercase:
"'{PropertyName}' must have at least one uppercase letter.",
code.notEmpty: "'{PropertyName}' must not be empty.",
code.notEqualTo: "'{PropertyName}' must not be equal to '{ComparisonValue}'.",
code.range: "'{PropertyName}' must be between {From} and {To}. You entered {PropertyValue}.",
code.notEqualTo:
"'{PropertyName}' must not be equal to '{ComparisonValue}'.",
code.range:
"'{PropertyName}' must be between {From} and {To}. You entered {PropertyValue}.",
code.validCEP: "'{PropertyName}' is not a valid CEP.",
code.validCPF: "'{PropertyName}' is not a valid CPF.",
code.validCNPJ: "'{PropertyName}' is not a valid CNPJ.",
code.validCreditCard: "'{PropertyName}' is not a valid credit card number.",
code.validEmail: "'{PropertyName}' is not a valid email address.",
code.greaterThanOrEqualToDateTime: "'{PropertyName}' must be greater than or equal to date '{ComparisonValue}'.",
code.greaterThanDatetime: "'{PropertyName}' must be greater than date '{ComparisonValue}'.",
code.lessThanOrEqualToDateTime: "'{PropertyName}' must be less than or equal to date '{ComparisonValue}'.",
code.lessThanDateTime: "'{PropertyName}' must be less than date '{ComparisonValue}'.",
code.inclusiveBetweenDatetime: "'{PropertyName}' must be greater than or equal to '{StartValue}' date and less than or equal to '{EndValue}' date.",
code.exclusiveBetweenDatetime: "'{PropertyName}' must be greater than the '{StartValue}' date and less than the '{EndValue}' date."
code.greaterThanOrEqualToDateTime:
"'{PropertyName}' must be greater than or equal to date '{ComparisonValue}'.",
code.greaterThanDatetime:
"'{PropertyName}' must be greater than date '{ComparisonValue}'.",
code.lessThanOrEqualToDateTime:
"'{PropertyName}' must be less than or equal to date '{ComparisonValue}'.",
code.lessThanDateTime:
"'{PropertyName}' must be less than date '{ComparisonValue}'.",
code.inclusiveBetweenDatetime:
"'{PropertyName}' must be greater than or equal to '{StartValue}' date and less than or equal to '{EndValue}' date.",
code.exclusiveBetweenDatetime:
"'{PropertyName}' must be greater than the '{StartValue}' date and less than the '{EndValue}' date."
};

String? getTranslation(String key) => _translations[key];
Expand Down
11 changes: 8 additions & 3 deletions lib/src/localization/language_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,19 @@ abstract class LanguageManager {
}

bool isSupported(String languageCode, String? countryCode) {
return _avaliableLanguages.containsKey(Culture(languageCode, countryCode ?? ''));
return _avaliableLanguages
.containsKey(Culture(languageCode, countryCode ?? ''));
}

String translate(String key, {Map<String, String> parameters = const {}, String? defaultMessage}) {
String translate(String key,
{Map<String, String> parameters = const {}, String? defaultMessage}) {
final culture = LucidValidation.global.culture;
final currentLanguage = getLanguage(culture);
final translations = _globalTranslations[culture] ?? {};
var message = defaultMessage ?? translations[key] ?? currentLanguage.getTranslation(key) ?? key;
var message = defaultMessage ??
translations[key] ??
currentLanguage.getTranslation(key) ??
key;
for (var key in parameters.keys) {
final value = parameters[key]!;
message = message.replaceAll('{$key}', value);
Expand Down
66 changes: 44 additions & 22 deletions lib/src/localization/languages/portuguese_brazillian_language.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,56 @@ import '../language.dart';
class PortugueseBrasillianLanguage extends Language {
PortugueseBrasillianLanguage()
: super({
Language.code.equalTo: "'{PropertyName}' deve ser igual a '{ComparisonValue}'.",
Language.code.greaterThan: "'{PropertyName}' deve ser maior que '{ComparisonValue}'.",
Language.code.equalTo:
"'{PropertyName}' deve ser igual a '{ComparisonValue}'.",
Language.code.greaterThan:
"'{PropertyName}' deve ser maior que '{ComparisonValue}'.",
Language.code.isEmpty: "'{PropertyName}' deve estar vazio.",
Language.code.isNotNull: "'{PropertyName}' não pode ser nulo.",
Language.code.isNull: "'{PropertyName}' deve ser nulo.",
Language.code.lessThan: "'{PropertyName}' deve ser menor que '{ComparisonValue}'.",
Language.code.matchesPattern: "'{PropertyName}' não está no formato correto.",
Language.code.max: "'{PropertyName}' deve ser menor ou igual a {MaxValue}. Você digitou {PropertyValue}.",
Language.code.maxLength: "O tamanho de '{PropertyName}' deve ser de {MaxLength} caracteres ou menos. Você digitou {TotalLength} caracteres.",
Language.code.min: "'{PropertyName}' deve ser maior ou igual a {MinValue}. Você digitou {PropertyValue}.",
Language.code.minLength: "O tamanho de '{PropertyName}' deve ser de pelo menos {MinLength} caracteres. Você digitou {TotalLength} caracteres.",
Language.code.mustHaveLowercase: "'{PropertyName}' deve ter pelo menos uma letra minúscula.",
Language.code.mustHaveNumber: "'{PropertyName}' deve ter pelo menos um dígito ('0'-'9').",
Language.code.mustHaveSpecialCharacter: "'{PropertyName}' deve ter pelo menos um caractere não alfanumérico.",
Language.code.mustHaveUppercase: "'{PropertyName}' deve ter pelo menos uma letra maiúscula.",
Language.code.lessThan:
"'{PropertyName}' deve ser menor que '{ComparisonValue}'.",
Language.code.matchesPattern:
"'{PropertyName}' não está no formato correto.",
Language.code.max:
"'{PropertyName}' deve ser menor ou igual a {MaxValue}. Você digitou {PropertyValue}.",
Language.code.maxLength:
"O tamanho de '{PropertyName}' deve ser de {MaxLength} caracteres ou menos. Você digitou {TotalLength} caracteres.",
Language.code.min:
"'{PropertyName}' deve ser maior ou igual a {MinValue}. Você digitou {PropertyValue}.",
Language.code.minLength:
"O tamanho de '{PropertyName}' deve ser de pelo menos {MinLength} caracteres. Você digitou {TotalLength} caracteres.",
Language.code.mustHaveLowercase:
"'{PropertyName}' deve ter pelo menos uma letra minúscula.",
Language.code.mustHaveNumber:
"'{PropertyName}' deve ter pelo menos um dígito ('0'-'9').",
Language.code.mustHaveSpecialCharacter:
"'{PropertyName}' deve ter pelo menos um caractere não alfanumérico.",
Language.code.mustHaveUppercase:
"'{PropertyName}' deve ter pelo menos uma letra maiúscula.",
Language.code.notEmpty: "'{PropertyName}' não pode estar vazio.",
Language.code.notEqualTo: "'{PropertyName}' não pode ser igual a '{ComparisonValue}'.",
Language.code.range: "'{PropertyName}' deve estar entre {From} e {To}. Você digitou {PropertyValue}.",
Language.code.notEqualTo:
"'{PropertyName}' não pode ser igual a '{ComparisonValue}'.",
Language.code.range:
"'{PropertyName}' deve estar entre {From} e {To}. Você digitou {PropertyValue}.",
Language.code.validCEP: "'{PropertyName}' não é um CEP válido.",
Language.code.validCPF: "'{PropertyName}' não é um CPF válido.",
Language.code.validCNPJ: "'{PropertyName}' não é um CNPJ válido.",
Language.code.validCreditCard: "'{PropertyName}' não é um número de cartão de crédito válido.",
Language.code.validEmail: "'{PropertyName}' não é um endereço de e-mail válido.",
Language.code.greaterThanOrEqualToDateTime: "'{PropertyName}' deve ser maior ou igual à data '{ComparisonValue}'.",
Language.code.greaterThanDatetime: "'{PropertyName}' deve ser maior que a data '{ComparisonValue}'.",
Language.code.lessThanOrEqualToDateTime: "'{PropertyName}' deve ser menor ou igual à data '{ComparisonValue}'.",
Language.code.lessThanDateTime: "'{PropertyName}' deve ser menor que a data '{ComparisonValue}'.",
Language.code.inclusiveBetweenDatetime: "'{PropertyName}' deve ser maior ou igual à data '{StartValue}' e menor ou igual à data '{EndValue}'.",
Language.code.exclusiveBetweenDatetime: "'{PropertyName}' deve ser maior que a data '{StartValue}' e menor que a data '{EndValue}'."
Language.code.validCreditCard:
"'{PropertyName}' não é um número de cartão de crédito válido.",
Language.code.validEmail:
"'{PropertyName}' não é um endereço de e-mail válido.",
Language.code.greaterThanOrEqualToDateTime:
"'{PropertyName}' deve ser maior ou igual à data '{ComparisonValue}'.",
Language.code.greaterThanDatetime:
"'{PropertyName}' deve ser maior que a data '{ComparisonValue}'.",
Language.code.lessThanOrEqualToDateTime:
"'{PropertyName}' deve ser menor ou igual à data '{ComparisonValue}'.",
Language.code.lessThanDateTime:
"'{PropertyName}' deve ser menor que a data '{ComparisonValue}'.",
Language.code.inclusiveBetweenDatetime:
"'{PropertyName}' deve ser maior ou igual à data '{StartValue}' e menor ou igual à data '{EndValue}'.",
Language.code.exclusiveBetweenDatetime:
"'{PropertyName}' deve ser maior que a data '{StartValue}' e menor que a data '{EndValue}'."
});
}
Loading

0 comments on commit 619be13

Please sign in to comment.