diff --git a/docs/book/filters/alnum.md b/docs/book/filters/alnum.md index 04e35380..72fe4afb 100755 --- a/docs/book/filters/alnum.md +++ b/docs/book/filters/alnum.md @@ -1,7 +1,7 @@ # Alnum -The `Alnum` filter can be used to **return only alphabetic characters and -digits** in the unicode "letter" and "number" categories, respectively. All +The `Alnum` filter can be used to **return only alphabetic characters and +digits** in the unicode "letter" and "number" categories, respectively. All other characters are suppressed. ## Basic Usage @@ -20,10 +20,11 @@ provided by PHP's `Locale` class and the `getDefault()` method. To allow whitespace characters (`\s`) on filtering set the option to `true`; otherwise they are suppressed. + === "Constructor Usage" ```php $filter = new Laminas\I18n\Filter\Alnum(true); - + echo $filter->filter('This is (my) content: 123'); // "This is my content 123" ``` @@ -31,9 +32,10 @@ otherwise they are suppressed. ```php $filter = new Laminas\I18n\Filter\Alnum(); $filter->setAllowWhiteSpace(true); - + echo $filter->filter('This is (my) content: 123'); // "This is my content 123" ``` + ### Get Current Value @@ -52,13 +54,14 @@ suppressed. ## Using Locale -The locale string used in identifying the characters to filter (locale name, +The locale string used in identifying the characters to filter (locale name, e.g. `en_US`). + === "Constructor Usage" ```php $filter = new Laminas\I18n\Filter\Alnum(null, 'en_US'); - + echo $filter->filter('This is (my) content: 123'); // "Thisismycontent123" ``` @@ -66,18 +69,19 @@ e.g. `en_US`). ```php $filter = new Laminas\I18n\Filter\Alnum(); $filter->setLocale('en_US'); - + echo $filter->filter('This is (my) content: 123'); // "Thisismycontent123" ``` === "Locale Class Usage" ```php Locale::setDefault('en_US'); - + $filter = new Laminas\I18n\Filter\Alnum(); - + echo $filter->filter('This is (my) content: 123'); // "Thisismycontent123" ``` + ### Get Current Value diff --git a/docs/book/filters/alpha.md b/docs/book/filters/alpha.md index e7fcb110..f136ee97 100755 --- a/docs/book/filters/alpha.md +++ b/docs/book/filters/alpha.md @@ -19,10 +19,11 @@ provided by PHP's `Locale` class and the `getDefault()` method. To allow whitespace characters (`\s`) on filtering set the option to `true`; otherwise they are suppressed. + === "Constructor Usage" ```php $filter = new Laminas\I18n\Filter\Alpha(true); - + echo $filter->filter('This is (my) content: 123'); // "This is my content" ``` @@ -30,9 +31,10 @@ otherwise they are suppressed. ```php $filter = new Laminas\I18n\Filter\Alpha(); $filter->setAllowWhiteSpace(true); - + echo $filter->filter('This is (my) content: 123'); // "This is my content" ``` + ### Get Current Value @@ -51,13 +53,14 @@ suppressed. ## Using Locale -The locale string used in identifying the characters to filter (locale name, +The locale string used in identifying the characters to filter (locale name, e.g. `en_US`). + === "Constructor Usage" ```php $filter = new Laminas\I18n\Filter\Alpha(null, 'en_US'); - + echo $filter->filter('This is (my) content: 123'); // "Thisismycontent" ``` @@ -65,18 +68,19 @@ e.g. `en_US`). ```php $filter = new Laminas\I18n\Filter\Alpha(); $filter->setLocale('en_US'); - + echo $filter->filter('This is (my) content: 123'); // "Thisismycontent" ``` === "Locale Class Usage" ```php Locale::setDefault('en_US'); - + $filter = new Laminas\I18n\Filter\Alpha(); - + echo $filter->filter('This is (my) content: 123'); // "Thisismycontent" ``` + ### Get Current Value diff --git a/docs/book/filters/introduction.md b/docs/book/filters/introduction.md index 7b32d3e3..21226f1e 100755 --- a/docs/book/filters/introduction.md +++ b/docs/book/filters/introduction.md @@ -2,10 +2,10 @@ laminas-i18n ships with a set of internationalization-related filters. -* [Alnum](alnum.md) -* [Alpha](alpha.md) -* [NumberFormat](number-format.md) -* [NumberParse](number-parse.md) +- [Alnum](alnum.md) +- [Alpha](alpha.md) +- [NumberFormat](number-format.md) +- [NumberParse](number-parse.md) These filters are based on Laminas component for filtering and normalizing data and files: @@ -14,6 +14,7 @@ normalizing data and files: The concept and the basic usage of the filters can be found in the [documentation of laminas-filter](https://docs.laminas.dev/laminas-filter/). + > ### Installation requirements > > The filtering support of laminas-i18n depends on the diff --git a/docs/book/filters/number-parse.md b/docs/book/filters/number-parse.md index 1bdc78d3..8f75e6b3 100755 --- a/docs/book/filters/number-parse.md +++ b/docs/book/filters/number-parse.md @@ -1,6 +1,6 @@ # NumberParse -The `NumberParse` filter can be used to **parse a number from a string**. It +The `NumberParse` filter can be used to **parse a number from a string**. It acts as a wrapper for the `NumberFormatter` class within PHP's internationalization extension (`ext/intl`). @@ -19,13 +19,14 @@ provided by PHP's `Locale` class and the `getDefault()` method. ## Using Locale -The locale string used in identifying the characters to filter (locale name, +The locale string used in identifying the characters to filter (locale name, e.g. `en_US` or `de_DE`). + === "Constructor Usage" ```php $filter = new Laminas\I18n\Filter\NumberParse('de_DE'); - + echo $filter->filter('1.234.567,891'); // 1234567.8912346 ``` @@ -33,18 +34,19 @@ e.g. `en_US` or `de_DE`). ```php $filter = new Laminas\I18n\Filter\NumberParse(); $filter->setLocale('de_DE'); - + echo $filter->filter('1.234.567,891'); // 1234567.8912346 ``` === "Locale Class Usage" ```php Locale::setDefault('de_DE'); - + $filter = new Laminas\I18n\Filter\NumberParse(); - + echo $filter->filter('1.234.567,891'); // 1234567.8912346 ``` + > ### Notice > @@ -68,19 +70,20 @@ provided by PHP's `Locale::getDefault()`. ## Using Style -This option sets the style of the parsing; one of the +This option sets the style of the parsing; one of the [`NumberFormatter` format style constants](http://www.php.net/manual/class.numberformatter.php#intl.numberformatter-constants.unumberformatstyle). + === "Constructor Usage" ```php // Example 1 $filter = new Laminas\I18n\Filter\NumberParse('en_US', NumberFormatter::PERCENT); - + echo $filter->filter('80%'); // 0.80 - + // Example 2 $filter = new Laminas\I18n\Filter\NumberParse('fr_FR', NumberFormatter::SCIENTIFIC); - + echo $filter->filter('1,23456789E-3'); // 0.00123456789 ``` @@ -89,19 +92,20 @@ This option sets the style of the parsing; one of the // Example 1 $filter = new Laminas\I18n\Filter\NumberParse('en_US'); $filter->setStyle(NumberFormatter::PERCENT); - + echo $filter->filter('80%'); // 0.80 - + // Example 2 $filter = new Laminas\I18n\Filter\NumberParse('fr_FR'); $filter->setStyle(NumberFormatter::SCIENTIFIC); - + echo $filter->filter('1,23456789E-3'); // 0.00123456789 ``` + > ### Notice > -> After the first filtering, the style changes will have no effect anymore. +> After the first filtering, the style changes will have no effect anymore. > Create a new instance of the filter to change the style. ### Get Current Value @@ -123,6 +127,7 @@ The default value of this option is `NumberFormatter::DEFAULT_STYLE`. The type speficied the [`NumberFormatter` parsing type](http://www.php.net/manual/class.numberformatter.php#intl.numberformatter-constants.types) to use. + === "Constructor Usage" ```php $filter = new Laminas\I18n\Filter\NumberParse( @@ -130,7 +135,7 @@ to use. NumberFormatter::DEFAULT_STYLE, NumberFormatter::DECIMAL ); - + echo $filter->filter('1.234.567,891'); // 1234567 ``` @@ -139,9 +144,10 @@ to use. $filter = new Laminas\I18n\Filter\NumberParse(); $filter->setLocale('de_DE'); $filter->setType(NumberFormatter::DECIMAL); - + echo $filter->filter('1.234.567,891'); // 1234567 ``` + ### Get Current Value @@ -160,7 +166,7 @@ The default value of this option is `NumberFormatter::TYPE_DOUBLE`. ## Using Custom NumberFormatter ```php -$formatter = new NumberFormatter('en_US', NumberFormatter::PERCENT); +$formatter = new NumberFormatter('en_US', NumberFormatter::PERCENT); $filter = new Laminas\I18n\Filter\NumberParse(); $filter->setFormatter($formatter); ``` diff --git a/docs/book/migration/migration-to-v2.4.md b/docs/book/migration/migration-to-v2.4.md index e65ed3f1..cac6adfb 100755 --- a/docs/book/migration/migration-to-v2.4.md +++ b/docs/book/migration/migration-to-v2.4.md @@ -20,7 +20,7 @@ instead starting in 2.4.0. ### IsInt -In PHP 7, `int` is a reserved keyword, which required renaming the +In PHP 7, `int` is a reserved keyword, which required renaming the `Laminas\I18n\Validator\Int` validator. If you were using the `Laminas\I18n\Validator\Int` validator directly previously, you will now receive an `E_USER_DEPRECATED` notice on instantiation. Please update your code diff --git a/docs/book/translator/caching.md b/docs/book/translator/caching.md index 83e15936..4d74621c 100755 --- a/docs/book/translator/caching.md +++ b/docs/book/translator/caching.md @@ -4,6 +4,7 @@ In production, it makes sense to cache your translations. This not only saves you from loading and parsing the individual formats each time, but also guarantees an optimized loading procedure. + > ### Installation requirements > > The cache support of laminas-i18n depends on the diff --git a/docs/book/translator/events.md b/docs/book/translator/events.md index 9bdd6775..29e9c9f9 100755 --- a/docs/book/translator/events.md +++ b/docs/book/translator/events.md @@ -9,6 +9,7 @@ translations: The typical usage for these events is to log missing translations and track when the loading of messages fails. + > ### Installation requirements > > The event support of laminas-i18n depends on the @@ -88,7 +89,7 @@ $eventManager = $translator->getEventManager(); // instance of Laminas\EventMana ``` > ### Automatic instantiation -> +> > The translator can create an event manager instance independently. If no custom > event manager is set for the translator, the `getEventManager()` method > returns this instance. @@ -120,7 +121,7 @@ $translator->getEventManager()->attach( ### Event Target and Parameters -In the previous code example the variable `$event` contains an instance of +In the previous code example the variable `$event` contains an instance of `Laminas\EventManager\Event` which implements `Laminas\EventManager\EventInterface`. As target of the event the current instance of diff --git a/docs/book/translator/factory.md b/docs/book/translator/factory.md index 54a71be5..7b5dec25 100755 --- a/docs/book/translator/factory.md +++ b/docs/book/translator/factory.md @@ -87,7 +87,7 @@ $translator = Laminas\I18n\Translator\Translator::factory([ ]); ``` -Each remote option array must contain `type`. The option for `text_domain` is +Each remote option array must contain `type`. The option for `text_domain` is optional. The default value for `text_domain` is `default`. ### Adding Translations diff --git a/docs/book/translator/format-examples.md b/docs/book/translator/format-examples.md index 1beb8da2..755bb887 100755 --- a/docs/book/translator/format-examples.md +++ b/docs/book/translator/format-examples.md @@ -100,4 +100,4 @@ identifier1.translation = "voiture" identifier2.message = "train" identifier2.translation = "train" -``` \ No newline at end of file +``` diff --git a/docs/book/validators/alnum.md b/docs/book/validators/alnum.md index 44037602..04b3d176 100755 --- a/docs/book/validators/alnum.md +++ b/docs/book/validators/alnum.md @@ -18,12 +18,13 @@ if ($validator->isValid('Abcd12')) { By default, whitespace is not accepted as it is not part of the alphabet. However, if you want to validate complete sentences or phrases, you may need to allow whitespace; this can be done via the `allowWhiteSpace` option, either at -instantiation or afterwards via the `setAllowWhiteSpace()` method. +instantiation or afterwards via the `setAllowWhiteSpace()` method. + === "Constructor Usage" ```php $validator = new Laminas\I18n\Validator\Alnum(['allowWhiteSpace' => true]); - + if ($validator->isValid('Abcd and 12')) { // Value contains only allowed chars } @@ -33,11 +34,12 @@ instantiation or afterwards via the `setAllowWhiteSpace()` method. ```php $validator = new Laminas\I18n\Validator\Alnum(); $validator->setAllowWhiteSpace(true); - + if ($validator->isValid('Abcd and 12')) { // Value contains only allowed chars } ``` + ### Get Current Value diff --git a/docs/book/validators/alpha.md b/docs/book/validators/alpha.md index b0f7fad4..64ba0cdf 100755 --- a/docs/book/validators/alpha.md +++ b/docs/book/validators/alpha.md @@ -22,10 +22,11 @@ However, if you want to validate complete sentences or phrases, you may need to allow whitespace; this can be done via the `allowWhiteSpace` option, either at instantiation or afterwards via the `setAllowWhiteSpace()` method. + === "Constructor Usage" ```php $validator = new Laminas\I18n\Validator\Alpha(['allowWhiteSpace' => true]); - + if ($validator->isValid('Abcd and efg')) { // Value contains only allowed chars } @@ -35,11 +36,12 @@ instantiation or afterwards via the `setAllowWhiteSpace()` method. ```php $validator = new Laminas\I18n\Validator\Alpha(); $validator->setAllowWhiteSpace(true); - + if ($validator->isValid('Abcd and efg')) { // Value contains only allowed chars } ``` + ### Get Current Value diff --git a/docs/book/validators/date-time.md b/docs/book/validators/date-time.md index d43932b7..741788b1 100755 --- a/docs/book/validators/date-time.md +++ b/docs/book/validators/date-time.md @@ -1,7 +1,7 @@ # DateTime -`Laminas\I18n\Validator\DateTime` allows you to determine if a given value **is a -valid date, time or datetime**. +`Laminas\I18n\Validator\DateTime` allows you to determine if a given value **is a +valid date, time or datetime**. Internally, PHP's `IntlDateFormatter` tries to create a date time for the given value. @@ -24,10 +24,11 @@ the timezone is set to `Europe/London`.) ## Set Locale + === "Constructor Usage" ```php $validator = new Laminas\I18n\Validator\DateTime(['locale' => 'de']); - + var_dump($validator->isValid('29.02.2020')); // true ``` @@ -35,9 +36,10 @@ the timezone is set to `Europe/London`.) ```php $validator = new Laminas\I18n\Validator\DateTime(); $validator->setLocale('de'); - + var_dump($validator->isValid('29.02.2020')); // true ``` + ### Get Current Value @@ -56,10 +58,11 @@ provided by PHP's `Locale::getDefault()`. ## Define Custom Pattern + === "Constructor Usage" ```php $validator = new Laminas\I18n\Validator\DateTime(['pattern' => 'yyyy-MM-DD']); - + var_dump($validator->isValid('2019-02-28')); // true ``` @@ -67,9 +70,10 @@ provided by PHP's `Locale::getDefault()`. ```php $validator = new Laminas\I18n\Validator\DateTime(); $validator->setPattern('yyyy-MM-DD'); - + var_dump($validator->isValid('2019-02-28')); // true ``` + Possible patterns are documented at [http://userguide.icu-project.org/formatparse/datetime](http://userguide.icu-project.org/formatparse/datetime). @@ -90,10 +94,11 @@ The default value of this option is `null`. ## Using Date Type + === "Constructor Usage" ```php $validator = new Laminas\I18n\Validator\DateTime(['date_type' => IntlDateFormatter::MEDIUM]); - + var_dump($validator->isValid('Feb 28, 2020')); // true ``` @@ -101,18 +106,19 @@ The default value of this option is `null`. ```php $validator = new Laminas\I18n\Validator\DateTime(); $validator->setDateType(IntlDateFormatter::MEDIUM); - + var_dump($validator->isValid('Feb 28, 2020')); // true ``` + Possible values for the date type option are the following [constants of PHP's `IntlDateFormatter` class](https://www.php.net/manual/class.intldateformatter.php#intl.intldateformatter-constants): -* `IntlDateFormatter::NONE` - Do not include this element -* `IntlDateFormatter::FULL` - Fullstyle (Tuesday, April 12, 1952 AD) -* `IntlDateFormatter::LONG` - Long style (January 12, 1952) -* `IntlDateFormatter::MEDIUM` - Medium style (Jan 12, 1952) -* `IntlDateFormatter::SHORT` - Short style (12/13/52) +- `IntlDateFormatter::NONE` - Do not include this element +- `IntlDateFormatter::FULL` - Fullstyle (Tuesday, April 12, 1952 AD) +- `IntlDateFormatter::LONG` - Long style (January 12, 1952) +- `IntlDateFormatter::MEDIUM` - Medium style (Jan 12, 1952) +- `IntlDateFormatter::SHORT` - Short style (12/13/52) ### Get Current Value @@ -132,10 +138,11 @@ The default value of this option is `IntlDateFormatter::NONE`. Sets time type to use (none, short, medium, long, full). + === "Constructor Usage" ```php $validator = new Laminas\I18n\Validator\DateTime(['time_type' => IntlDateFormatter::MEDIUM]); - + var_dump($validator->isValid('8:05:40 pm')); // true ``` @@ -143,18 +150,19 @@ Sets time type to use (none, short, medium, long, full). ```php $validator = new Laminas\I18n\Validator\DateTime(); $validator->setTimeType(IntlDateFormatter::MEDIUM); - + var_dump($validator->isValid('8:05:40 pm')); // true ``` + Possible values for the date type option are the following [constants of PHP's `IntlDateFormatter` class](https://www.php.net/manual/class.intldateformatter.php#intl.intldateformatter-constants): -* `IntlDateFormatter::NONE` - Do not include this element -* `IntlDateFormatter::FULL` - Fullstyle (3:30:42pm PST) -* `IntlDateFormatter::LONG` - Long style (3:30:32pm) -* `IntlDateFormatter::MEDIUM` - Medium style (3:30:32pm) -* `IntlDateFormatter::SHORT` - Short style (3:30pm) +- `IntlDateFormatter::NONE` - Do not include this element +- `IntlDateFormatter::FULL` - Fullstyle (3:30:42pm PST) +- `IntlDateFormatter::LONG` - Long style (3:30:32pm) +- `IntlDateFormatter::MEDIUM` - Medium style (3:30:32pm) +- `IntlDateFormatter::SHORT` - Short style (3:30pm) ### Get Current Value @@ -174,6 +182,7 @@ The default value of this option is `IntlDateFormatter::NONE`. To demonstrate the calendar option, additional settings are needed. + === "Constructor Usage" ```php $validator = new Laminas\I18n\Validator\DateTime([ @@ -182,7 +191,7 @@ To demonstrate the calendar option, additional settings are needed. 'locale' => 'de_DE@calendar=buddhist', 'timezone' => 'Europe/Berlin', ]); - + var_dump($validator->isValid('28.02.2562 BE')); // true ``` @@ -193,15 +202,16 @@ To demonstrate the calendar option, additional settings are needed. $validator->setDateType(IntlDateFormatter::MEDIUM); $validator->setLocale('de_DE@calendar=buddhist'); $validator->setTimezone('Europe/Berlin'); - + var_dump($validator->isValid('28.02.2562 BE')); // true ``` + Possible values for the calendar option are the following [constants of PHP's `IntlDateFormatter` class](https://www.php.net/manual/class.intldateformatter.php#intl.intldateformatter-constants): -* `IntlDateFormatter::TRADITIONAL` - Non-Gregorian Calendar -* `IntlDateFormatter::GREGORIAN` - Gregorian Calendar +- `IntlDateFormatter::TRADITIONAL` - Non-Gregorian Calendar +- `IntlDateFormatter::GREGORIAN` - Gregorian Calendar ### Get Current Value @@ -219,10 +229,11 @@ The default value of this option is `IntlDateFormatter::GREGORIAN`. ## Using Timezone + === "Constructor Usage" ```php $validator = new Laminas\I18n\Validator\DateTime(['timezone' => 'Europe/London']); - + var_dump($validator->isValid('20190228 10:00 pm')); // true ``` @@ -230,9 +241,10 @@ The default value of this option is `IntlDateFormatter::GREGORIAN`. ```php $validator = new Laminas\I18n\Validator\DateTime(); $validator->setTimezone('Europe/London'); - + var_dump($validator->isValid('20190228 10:00 pm')); // true ``` + ### Get Current Value diff --git a/docs/book/validators/introduction.md b/docs/book/validators/introduction.md index 19a4a017..0d10431a 100755 --- a/docs/book/validators/introduction.md +++ b/docs/book/validators/introduction.md @@ -3,19 +3,20 @@ laminas-i18n provides a set of validators that use internationalization capabilities. -* [Alnum](alnum.md) -* [Alpha](alpha.md) -* [DateTime](date-time.md) -* [IsFloat](is-float.md) -* [IsInt](is-int.md) -* [PhoneNumber](phone-number.md) -* [PostCode](post-code.md) +- [Alnum](alnum.md) +- [Alpha](alpha.md) +- [DateTime](date-time.md) +- [IsFloat](is-float.md) +- [IsInt](is-int.md) +- [PhoneNumber](phone-number.md) +- [PostCode](post-code.md) These validators are based on Laminas component for validation of data -and files: [laminas-validator](https://docs.laminas.dev/laminas-validator/). +and files: [laminas-validator](https://docs.laminas.dev/laminas-validator/). The documentation of laminas-validator also describes the [translate of the validation messages](https://docs.laminas.dev/laminas-validator/intro/#translating-messages). + > ### Installation requirements > > The validation support of laminas-i18n depends on the diff --git a/docs/book/validators/is-float.md b/docs/book/validators/is-float.md index e9a1a7fb..72f7cdb5 100755 --- a/docs/book/validators/is-float.md +++ b/docs/book/validators/is-float.md @@ -30,10 +30,11 @@ Using a notation not specific to the locale results in a `false` evaluation. ## Using Locale + === "Constructor Usage" ```php $validator = new Laminas\I18n\Validator\IsFloat(['locale' => 'en_US']); - + $validator->isValid(1234.5); // true ``` @@ -41,18 +42,19 @@ Using a notation not specific to the locale results in a `false` evaluation. ```php $validator = new Laminas\I18n\Validator\IsFloat(); $validator->setLocale('en_US'); - + $validator->isValid(1234.5); // true ``` === "Locale Class Usage" ```php Locale::setDefault('en_US'); - + $validator = new Laminas\I18n\Validator\IsFloat(); - + $validator->isValid(1234.5); // true ``` + ### Get Current Value diff --git a/docs/book/validators/is-int.md b/docs/book/validators/is-int.md index 77274bf1..5eae32ac 100755 --- a/docs/book/validators/is-int.md +++ b/docs/book/validators/is-int.md @@ -32,10 +32,11 @@ Using a notation not specific to the locale results in a `false` evaulation. ## Using Locale + === "Constructor Usage" ```php $validator = new Laminas\I18n\Validator\IsInt(['locale' => 'en_US']); - + $validator->isValid(1234); // true ``` @@ -43,18 +44,19 @@ Using a notation not specific to the locale results in a `false` evaulation. ```php $validator = new Laminas\I18n\Validator\IsInt(); $validator->setLocale('en_US'); - + $validator->isValid(1234); // true ``` === "Locale Class Usage" ```php Locale::setDefault('en_US'); - + $validator = new Laminas\I18n\Validator\IsInt(); - + $validator->isValid(1234); // true ``` + ### Get Current Value @@ -75,20 +77,23 @@ provided by PHP's `Locale::getDefault()`. By default, the value's data type is not enforced. + === "Default (Without Strict)" ```php $validator = new Laminas\I18n\Validator\IsInt(); - + $validator->isValid(1234); // true $validator->isValid('1234'); // true ``` + To enforced a strict validation set the `strict` option to `true`. + === "Constructor Usage" ```php $validator = new Laminas\I18n\Validator\IsInt(['strict' => true]); - + $validator->isValid(1234); // true $validator->isValid('1234'); // false ``` @@ -97,10 +102,11 @@ To enforced a strict validation set the `strict` option to `true`. ```php $validator = new Laminas\I18n\Validator\IsInt(); $validator->setStrict(true) - + $validator->isValid(1234); // true $validator->isValid('1234'); // false ``` + ### Get Current Value diff --git a/docs/book/validators/phone-number.md b/docs/book/validators/phone-number.md index f27094b2..c5054d50 100755 --- a/docs/book/validators/phone-number.md +++ b/docs/book/validators/phone-number.md @@ -17,14 +17,15 @@ extract the country code. (The above example assumes that the environment locale is set to `de_DE`.) -## Using Country +## Using Country The ISO 3611 country code can be set for validations. + === "Constructor Usage" ```php $validator = new Laminas\I18n\Validator\PhoneNumber(['country' => 'DE']); - + var_dump($validator->isValid('+4930123456')); // true ``` @@ -32,18 +33,19 @@ The ISO 3611 country code can be set for validations. ```php $validator = new Laminas\I18n\Validator\PhoneNumber(); $validator->setCountry('DE'); - + var_dump($validator->isValid('+4930123456')); // true ``` === "Locale Class Usage" ```php Locale::setDefault('de_DE'); - + $validator = new Laminas\I18n\Validator\PhoneNumber(); - + var_dump($validator->isValid('+4930123456')); // true ``` + ### Get Current Value @@ -63,13 +65,14 @@ the region code. ## Using Allowed Phone Number Patterns + === "Constructor Usage" ```php $validator = new Laminas\I18n\Validator\PhoneNumber([ 'allowed_types' => ['emergency'], 'country' => 'US', ]); - + var_dump($validator->isValid(911)); // true var_dump($validator->isValid(999)); // false ``` @@ -79,10 +82,11 @@ the region code. $validator = new Laminas\I18n\Validator\PhoneNumber(); $validator->allowedTypes(['emergency']); $validator->setCountry('US'); - + var_dump($validator->isValid(911)); // true var_dump($validator->isValid(999)); // false ``` + Possible values for allowed patterns are: @@ -123,13 +127,13 @@ var_dump($validator->allowedTypes()); // ['emergency'] The following phone number patterns are allowed per default: -* `fixed` -* `general` -* `mobile` -* `personal` -* `tollfree` -* `uan` -* `voip` +- `fixed` +- `general` +- `mobile` +- `personal` +- `tollfree` +- `uan` +- `voip` ## Strict Validation @@ -137,6 +141,7 @@ By default, the phone numbers are validated against strict number patterns. To allow validation with all _possible_ phone numbers, the `allow_possible` option can be used. + === "Constructor Usage" ```php $validator = new Laminas\I18n\Validator\PhoneNumber([ @@ -144,7 +149,7 @@ can be used. 'allowed_types' => ['emergency'], 'country' => 'US', ]); - + var_dump($validator->isValid(911)); // true var_dump($validator->isValid(999)); // true var_dump($validator->isValid(9999)); // false @@ -156,11 +161,12 @@ can be used. $validator->allowPossible(true); $validator->allowedTypes(['emergency']); $validator->setCountry('US'); - + var_dump($validator->isValid(911)); // true var_dump($validator->isValid(999)); // true var_dump($validator->isValid(9999)); // false ``` + ### Get Current Value diff --git a/docs/book/validators/post-code.md b/docs/book/validators/post-code.md index 6f961ede..943668e9 100755 --- a/docs/book/validators/post-code.md +++ b/docs/book/validators/post-code.md @@ -32,10 +32,11 @@ instance, the locale `de` is a locale but could not be used with however, would be a valid locale, as it specifies the region code (`AT`, for Austria). + === "Constructor Usage" ```php $validator = new Laminas\I18n\Validator\PostCode(['locale' => 'de_AT']); - + var_dump($validator->isValid(1010)); // true ``` @@ -43,18 +44,19 @@ Austria). ```php $validator = new Laminas\I18n\Validator\PostCode(); $validator->setLocale('de_AT'); - + $validator->isValid(1010); // true ``` === "Locale Class Usage" ```php Locale::setDefault('de_AT'); - + $validator = new Laminas\I18n\Validator\PostCode(); - + var_dump($validator->isValid(1010)); // true ``` + ### Get Current Value @@ -78,10 +80,11 @@ Postal code formats are regular expression strings. When the international postal code format, which is used by setting the locale, does not fit your needs, then you can also manually set a format by calling `setFormat()`. + === "Constructor Usage" ```php $validator = new Laminas\I18n\Validator\PostCode(['format' => 'AT-\d{4}']); - + var_dump($validator->isValid('AT-1010')); // true ``` @@ -89,9 +92,10 @@ needs, then you can also manually set a format by calling `setFormat()`. ```php $validator = new Laminas\I18n\Validator\PostCode(); $validator->setFormat('AT-\d{4}'); - + var_dump($validator->isValid('AT-1010')); // true ``` + ### Conventions for self defined Formats @@ -126,6 +130,7 @@ Internally, the additional validation is done by [laminas-validator's `Callback`](https://docs.laminas.dev/laminas-validator/validators/callback/) class. + === "Constructor Usage" ```php $validator = new Laminas\I18n\Validator\PostCode([ @@ -134,12 +139,12 @@ class. if (in_array($value, range(1010, 1423), false)) { return true; } - + return false; }, - 'locale' => 'de_AT', + 'locale' => 'de_AT', ]); - + var_dump($validator->isValid(1010)); // true var_dump($validator->isValid(1600)); // false ``` @@ -148,18 +153,19 @@ class. ```php $validator = new Laminas\I18n\Validator\PostCode(); $validator->setService(static function ($value) { - // Allow only certain districts in town - if (in_array($value, range(1010, 1423), false)) { - return true; - } - - return false; + // Allow only certain districts in town + if (in_array($value, range(1010, 1423), false)) { + return true; + } + + return false; }); $validator->setLocale('de_AT'); - + var_dump($validator->isValid(1010)); // true var_dump($validator->isValid(1600)); // false ``` + ### Default Value diff --git a/docs/book/view-helpers/currency-format.md b/docs/book/view-helpers/currency-format.md index fd2943f7..b31df3c7 100755 --- a/docs/book/view-helpers/currency-format.md +++ b/docs/book/view-helpers/currency-format.md @@ -18,6 +18,7 @@ locale provided by PHP's `Locale` class and the `getDefault()` method. ## Using Currency Code + === "Invoke Usage" ```php echo $this->currencyFormat(1234.56, 'EUR'); // '1.234,56 €' @@ -26,9 +27,10 @@ locale provided by PHP's `Locale` class and the `getDefault()` method. === "Setter Usage" ```php $this->plugin('currencyFormat')->setCurrencyCode('EUR'); - + echo $this->currencyFormat(1234.56); // '1.234,56 €' ``` + (The above example assumes that the environment locale is set to `de`.) @@ -48,6 +50,7 @@ The default value of this option is `null`. ## Show or hide Decimals + === "Invoke Usage" ```php echo $this->currencyFormat(1234.56, 'EUR', false); // '1.234 €' @@ -56,9 +59,10 @@ The default value of this option is `null`. === "Setter Usage" ```php $this->plugin('currencyFormat')->setShouldShowDecimals(false); - + echo $this->currencyFormat(1234.56); // '1.234 €' ``` + (The above example assumes that the environment locale is set to `de`.) @@ -78,6 +82,7 @@ The default value of this option is `null` that means the decimals are showing. ## Using Locale + === "Invoke Usage" ```php echo $this->currencyFormat(1234.56, 'EUR', null, 'de'); // '1.234,56 €' @@ -89,6 +94,7 @@ The default value of this option is `null` that means the decimals are showing. echo $this->currencyFormat(1234.56, 'EUR'); // '1.234,56 €' ``` + ### Get current Value @@ -107,6 +113,7 @@ locale provided by PHP's `Locale::getDefault()`. ## Define custom Pattern + === "Invoke Usage" ```php echo $this->currencyFormat(1234.56, 'EUR', null, 'de', '#0.# kg'); // '12345678,90 kg' @@ -115,9 +122,10 @@ locale provided by PHP's `Locale::getDefault()`. === "Setter Usage" ```php $this->plugin('currencyformat')->setCurrencyPattern('#0.# kg'); - + echo $this->currencyFormat(1234.56, 'EUR'); // '12345678,90 kg' ``` + (The above example assumes that the environment locale is set to `de`.) diff --git a/docs/book/view-helpers/date-format.md b/docs/book/view-helpers/date-format.md index 570fdb93..e782d7c0 100755 --- a/docs/book/view-helpers/date-format.md +++ b/docs/book/view-helpers/date-format.md @@ -9,10 +9,10 @@ internationalization extension (`ext/intl`). The value for the date must be: -* an object which implements the [`DateTimeInterface`](https://www.php.net/DateTimeInterface), -* an [`IntlCalendar`](https://www.php.net/IntlCalendar) object, -* an integer representing a Unix timestamp value -* or an array in the format returned by [`localtime()` function](https://www.php.net/localtime) +- an object which implements the [`DateTimeInterface`](https://www.php.net/DateTimeInterface), +- an [`IntlCalendar`](https://www.php.net/IntlCalendar) object, +- an integer representing a Unix timestamp value +- or an array in the format returned by [`localtime()` function](https://www.php.net/localtime) Example with a `DateTime` instance: @@ -97,11 +97,11 @@ echo $this->dateFormat(new DateTime(), IntlDateFormatter::MEDIUM); // 'Feb 22, 2 Possible values for the date type option are the following [constants of PHP's `IntlDateFormatter` class](https://www.php.net/manual/class.intldateformatter.php#intl.intldateformatter-constants): -* `IntlDateFormatter::NONE` - Do not include this element -* `IntlDateFormatter::FULL` - Fullstyle (Tuesday, April 12, 1952 AD) -* `IntlDateFormatter::LONG` - Long style (January 12, 1952) -* `IntlDateFormatter::MEDIUM` - Medium style (Jan 12, 1952) -* `IntlDateFormatter::SHORT` - Short style (12/13/52) +- `IntlDateFormatter::NONE` - Do not include this element +- `IntlDateFormatter::FULL` - Fullstyle (Tuesday, April 12, 1952 AD) +- `IntlDateFormatter::LONG` - Long style (January 12, 1952) +- `IntlDateFormatter::MEDIUM` - Medium style (Jan 12, 1952) +- `IntlDateFormatter::SHORT` - Short style (12/13/52) ### Default Value @@ -121,11 +121,11 @@ echo $this->dateFormat(new DateTime(), IntlDateFormatter::NONE, IntlDateFormatte Possible values for the date type option are the following [constants of PHP's `IntlDateFormatter` class](https://www.php.net/manual/class.intldateformatter.php#intl.intldateformatter-constants): -* `IntlDateFormatter::NONE` - Do not include this element -* `IntlDateFormatter::FULL` - Fullstyle (3:30:42pm PST) -* `IntlDateFormatter::LONG` - Long style (3:30:32pm) -* `IntlDateFormatter::MEDIUM` - Medium style (3:30:32pm) -* `IntlDateFormatter::SHORT` - Short style (3:30pm) +- `IntlDateFormatter::NONE` - Do not include this element +- `IntlDateFormatter::FULL` - Fullstyle (3:30:42pm PST) +- `IntlDateFormatter::LONG` - Long style (3:30:32pm) +- `IntlDateFormatter::MEDIUM` - Medium style (3:30:32pm) +- `IntlDateFormatter::SHORT` - Short style (3:30pm) ### Default Value @@ -133,6 +133,7 @@ The default value of this option is `IntlDateFormatter::NONE`. ## Using Locale + === "Invoke Usage" ```php echo $this->dateFormat(new DateTime(), null, null, 'de_DE'); @@ -142,16 +143,17 @@ The default value of this option is `IntlDateFormatter::NONE`. === "Setter Usage" ```php $this->plugin('dateFormat')->setLocale('de_DE'); - + echo $this->dateFormat(new DateTime()); // 'Freitag, 22. Februar 2019 um 21:16:37 GMT' ``` === "Locale Class Usage" ```php Locale::setDefault('de_DE'); - + echo $this->dateFormat(new DateTime()); // 'Freitag, 22. Februar 2019 um 21:16:37 GMT' ``` + ### Get current Value diff --git a/docs/book/view-helpers/introduction.md b/docs/book/view-helpers/introduction.md index 85481080..2145bb29 100755 --- a/docs/book/view-helpers/introduction.md +++ b/docs/book/view-helpers/introduction.md @@ -3,17 +3,18 @@ laminas-i18n ships with a set of laminas-view helper classes related to internationalization. -* [CurrencyFormat](currency-format.md) -* [DateFormat](date-format.md) -* [NumberFormat](number-format.md) -* [Plural](plural.md) -* [Translate](translate.md) -* [TranslatePlural](translate-plural.md) +- [CurrencyFormat](currency-format.md) +- [DateFormat](date-format.md) +- [NumberFormat](number-format.md) +- [Plural](plural.md) +- [Translate](translate.md) +- [TranslatePlural](translate-plural.md) These helpers are based on Laminas component for the view layer: [laminas-view](https://docs.laminas.dev/laminas-view/) and their [helpers](https://docs.laminas.dev/laminas-view/helpers/intro/). + > ### Installation Requirements > > The view-helper support of laminas-i18n depends on the @@ -48,7 +49,7 @@ These helpers are based on Laminas component for the view layer: > ``` > > The `HelperTrait` traits can be chained as many as needed, depending on which -> view helpers from the different Laminas component are used and where the +> view helpers from the different Laminas component are used and where the > auto-completion is to be made. ## Abstract Translator Helper diff --git a/docs/book/view-helpers/number-format.md b/docs/book/view-helpers/number-format.md index 5111592e..dcd53d8e 100755 --- a/docs/book/view-helpers/number-format.md +++ b/docs/book/view-helpers/number-format.md @@ -18,14 +18,15 @@ locale provided by PHP's `Locale` class and the `getDefault()` method. ## Using Format Style -This option sets the style of the formatting; one of the +This option sets the style of the formatting; one of the [`NumberFormatter` format style constants](https://www.php.net/manual/class.numberformatter.php#intl.numberformatter-constants.unumberformatstyle). + === "Constructor Usage" ```php // Example 1 echo $this->numberFormat(0.8, NumberFormatter::PERCENT); // '80%' - + // Example 2 echo $this->numberFormat(0.00123456789, NumberFormatter::SCIENTIFIC); // '1,23456789E-3' ``` @@ -34,14 +35,15 @@ This option sets the style of the formatting; one of the ```php // Example 1 $this->plugin('numberFormat')->setFormatStyle(NumberFormatter::PERCENT); - + echo $this->numberFormat(0.8); // '80%' - + // Example 2 $this->plugin('numberFormat')->setFormatStyle(NumberFormatter::SCIENTIFIC); - + echo $this->numberFormat(0.00123456789); // '1,23456789E-3' ``` + (The above examples assumes that the environment locale is set to `en_US`.) @@ -64,6 +66,7 @@ The default value of this option is `NumberFormatter::DEFAULT_STYLE`. The format type speficied the [`NumberFormatter` formatting type](https://www.php.net/manual/class.numberformatter.php#intl.numberformatter-constants.types) to use. + === "Constructor Usage" ```php echo $this->numberFormat(1234567.89, null, NumberFormatter::TYPE_INT32); // '1.234.567' @@ -72,9 +75,10 @@ to use. === "Setter Usage" ```php $this->plugin('numberFormat')->setFormatType(NumberFormatter::TYPE_INT32); - + echo $this->numberFormat(1234567.89); // '1.234.567' ``` + (The above examples assumes that the environment locale is set to `en_US`.) @@ -94,6 +98,7 @@ The default value of this option is `NumberFormatter::TYPE_DEFAULT`. ## Using Locale + === "Invoke Usage" ```php echo $this->numberFormat(1000, null, null, 'en_US'); // '1,000' @@ -102,16 +107,17 @@ The default value of this option is `NumberFormatter::TYPE_DEFAULT`. === "Setter Usage" ```php $this->plugin('currencyFormat')->setLocale('en_US'); - + echo $this->numberFormat(1000); // '1,000' ``` === "Locale Class Usage" ```php Locale::setDefault('en_US'); - + echo $this->numberFormat(1000); // '1,000' ``` + ### Get current Value @@ -132,6 +138,7 @@ locale provided by PHP's `Locale::getDefault()`. Sets the number of digits beyond the decimal point to display. + === "Invoke Usage" ```php echo $this->numberFormat(1234, null, null, null, 5); // '1,234.00000' @@ -140,9 +147,10 @@ Sets the number of digits beyond the decimal point to display. === "Setter Usage" ```php $this->plugin('currencyFormat')->setDecimals(5); - + echo $this->numberFormat(1234); // '1,234.00000' ``` + (The above examples assumes that the environment locale is set to `en_US`.) @@ -163,10 +171,11 @@ and maximum fraction digits will not be set on the `NumberFormatter`. ## Using Text Attributes -This option sets the text attributes of the formatting, like prefix and suffix +This option sets the text attributes of the formatting, like prefix and suffix for positive and negative numbers. See [`NumberFormatter` text attribute constants](https://www.php.net/manual/class.numberformatter.php#intl.numberformatter-constants.unumberformattextattribute). + === "Invoke Usage" ```php echo $this->numberFormat( @@ -186,9 +195,10 @@ for positive and negative numbers. See $this->plugin('currencyFormat')->setTextAttributes([ NumberFormatter::NEGATIVE_PREFIX => '(minus) ', ]); - + echo $this->numberFormat(-1000); // '(minus) 1,000' ``` + (The above examples assumes that the environment locale is set to `en_US`.) diff --git a/docs/book/view-helpers/plural.md b/docs/book/view-helpers/plural.md index 108ef5f1..fb6f093d 100755 --- a/docs/book/view-helpers/plural.md +++ b/docs/book/view-helpers/plural.md @@ -8,6 +8,7 @@ and "1 voiture") and the plural form otherwise ("3 voitures"). Therefore we often need to handle plural cases even without translation (mono-lingual application). The `Plural` helper was created for this. + > ### Plural Helper does not translate > > If you need to handle both plural cases *and* translations, you must use the @@ -73,4 +74,4 @@ echo $this->plural(['voiture', 'voitures'], 2); // 'voitures' ```php echo $this->plural(['car', 'cars'], 0); // 'cars' echo $this->plural(['car', 'cars'], 1); // 'car' -``` \ No newline at end of file +``` diff --git a/docs/book/view-helpers/translate-plural.md b/docs/book/view-helpers/translate-plural.md index 0f145b44..12ebe651 100755 --- a/docs/book/view-helpers/translate-plural.md +++ b/docs/book/view-helpers/translate-plural.md @@ -35,6 +35,7 @@ echo $this->translatePlural('car', 'cars', 4); // 'Autos' The text domain defines the domain of the translation. + === "Invoke Usage" ```php echo $this->translatePlural('monitor', 'monitors', 1, 'customDomain'); // 'Bildschirm' @@ -43,9 +44,10 @@ The text domain defines the domain of the translation. === "Setter Usage" ```php $this->plugin('currencyFormat')->setTranslatorTextDomain('customDomain'); - + echo $this->translatePlural('monitor', 'monitors', 1); // 'Bildschirm' ``` + (The above example assumes that the environment locale is set to `de_DE`.) diff --git a/docs/book/view-helpers/translate.md b/docs/book/view-helpers/translate.md index 594e0618..097094e9 100755 --- a/docs/book/view-helpers/translate.md +++ b/docs/book/view-helpers/translate.md @@ -22,6 +22,7 @@ echo $this->translate('Some translated text.'); // Etwas übersetzter Text The text domain defines the domain of the translation. + === "Invoke Usage" ```php echo $this->translate('monitor', 'customDomain'); // 'Monitor' @@ -30,9 +31,10 @@ The text domain defines the domain of the translation. === "Setter Usage" ```php $this->plugin('currencyFormat')->setTranslatorTextDomain('customDomain'); - + echo $this->translate('monitor'); // 'Monitor' ``` + (The above example assumes that the environment locale is set to `de_DE`.)