This repository was archived by the owner on Mar 13, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +59
-0
lines changed
Expand file tree Collapse file tree 2 files changed +59
-0
lines changed Original file line number Diff line number Diff line change 3939
4040- [ Choice] ( 03-rules_choice.md )
4141- [ Country] ( 03-rules_country.md )
42+ - [ Language] ( 03-rules_language.md )
4243
4344## Iterable Rules
4445
Original file line number Diff line number Diff line change 1+ # Language
2+
3+ Validates that a value is a valid language code.
4+
5+ ``` php
6+ Language(
7+ string $code = 'alpha-2',
8+ ?string $message = null
9+ );
10+ ```
11+
12+ ## Basic Usage
13+
14+ ``` php
15+ // default alpha-2 code
16+ Validator::language()->validate('pt'); // true
17+
18+ // alpha-3 code
19+ Validator::language(code: 'alpha-3')->validate('por'); // true
20+ ```
21+
22+ > [ !NOTE]
23+ > An ` UnexpectedValueException ` will be thrown when the ` code ` value is not a valid option.
24+
25+ > [ !NOTE]
26+ > An ` UnexpectedValueException ` will be thrown when the input value is not a ` string ` .
27+
28+ ## Options
29+
30+ ### ` code `
31+
32+ type: ` string ` default: ` alpha-2 `
33+
34+ Set code type to validate the language.
35+ Check the [ official language codes] ( https://en.wikipedia.org/wiki/List_of_ISO_639_language_codes ) list for more information.
36+
37+ Available options:
38+
39+ - ` alpha-2 ` : two-letter code
40+ - ` alpha-3 ` : three-letter code
41+
42+ ### ` message `
43+
44+ type: ` ?string ` default: ` The {{ name }} value is not a valid language, {{ value }} given. `
45+
46+ Message that will be shown if the input value is not a valid language code.
47+
48+ The following parameters are available:
49+
50+ | Parameter | Description |
51+ | ---------------| ---------------------------|
52+ | ` {{ value }} ` | The current invalid value |
53+ | ` {{ name }} ` | Name of the invalid value |
54+ | ` {{ code }} ` | Selected code type |
55+
56+ ## Changelog
57+
58+ - ` 1.1.0 ` Created
You can’t perform that action at this time.
0 commit comments