-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
40aa858
commit 7d0eeed
Showing
18 changed files
with
322 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
abstract class Language { | ||
final String culture; | ||
|
||
static const code = ( | ||
equalTo: 'equalTo', | ||
greaterThan: 'greaterThan', | ||
isEmpty: 'isEmpty', | ||
isNotNull: 'isNotNull', | ||
isNull: 'isNull', | ||
lessThan: 'lessThan', | ||
matchesPattern: 'matchesPattern', | ||
max: 'max', | ||
maxLength: 'maxLength', | ||
min: 'min', | ||
minLength: 'minLength', | ||
mustHaveLowercase: 'mustHaveLowercase', | ||
mustHaveNumber: 'mustHaveNumber', | ||
mustHaveSpecialCharacter: 'mustHaveSpecialCharacter', | ||
mustHaveUppercase: 'mustHaveUppercase', | ||
notEmpty: 'notEmpty', | ||
notEqualTo: 'notEqualTo', | ||
range: 'range', | ||
validCEP: 'validCEP', | ||
validCPF: 'validCPF', | ||
validCNPJ: 'validCNPJ', | ||
validCreditCard: 'validCreditCard', | ||
validEmail: 'validEmail', | ||
); | ||
|
||
Language(this.culture); | ||
|
||
final _translations = <String, String>{ | ||
code.equalTo: "'{PropertyName}' must be equal to '{ComparisonValue}'.", | ||
code.greaterThan: "'{PropertyName}' must be greater than '{ComparisonValue}'.", | ||
code.isEmpty: "'{PropertyName}' must be empty.", | ||
code.isNotNull: "'{PropertyName}' must not be empty.", | ||
code.isNull: "'{PropertyName}' must be empty.", | ||
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.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.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.", | ||
}; | ||
|
||
String? getTranslation(String key) => _translations[key]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import '../../lucid_validation.dart'; | ||
|
||
abstract class LanguageManager { | ||
final _globalTranslations = <String, Map<String, String>>{}; | ||
|
||
Language get currentLanguage => LucidValidation.global.language; | ||
|
||
void addTranslation(String culture, String code, String value) { | ||
if (!_globalTranslations.containsKey(culture)) { | ||
_globalTranslations[culture] = {}; | ||
} | ||
_globalTranslations[culture]![code] = value; | ||
} | ||
|
||
String translate(String key, [Map<String, String> parameters = const {}]) { | ||
final culture = currentLanguage.culture; | ||
final translations = _globalTranslations[culture] ?? {}; | ||
var message = translations[key] ?? currentLanguage.getTranslation(key) ?? key; | ||
for (var key in parameters.keys) { | ||
final value = parameters[key]!; | ||
message = message.replaceAll('{$key}', value); | ||
} | ||
return message; | ||
} | ||
} | ||
|
||
class DefaultLanguageManager extends LanguageManager {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import '../language.dart'; | ||
|
||
class EnglishLanguage extends Language { | ||
EnglishLanguage() : super('en'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export 'language.dart'; | ||
export 'language_manager.dart'; | ||
export 'languages/english_language.dart'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.