Translate modifier's docs

This commit is contained in:
Ivan Shalganov 2014-01-29 10:01:31 +02:00
parent 5e4b7f3051
commit dc287f08b2
10 changed files with 64 additions and 57 deletions

View File

@ -1,21 +1,19 @@
Modifier date_format [RU] Modifier date_format
========================= ====================
Модификатор позволят вывести дату в произвольном формате, согласно форматированию [strftime()](http://docs.php.net/strftime).
Модификатор принимает timestamp или строку, которую можно преобразовать через [strtotime()](http://docs.php.net/strtotime).
Формат по умолчанию: `%b %e, %Y`.
**[Допустимые квантификаторы](http://docs.php.net/strftime#refsect1-function.strftime-parameters) в формате даты**
This formats a date and time into the given [strftime()](http://docs.php.net/strftime) format.
Dates can be passed to Fenom as unix timestamps, DateTime objects or any string made up of month day year, parsable by [strftime()](http://docs.php.net/strftime).
By default format is: `%b %e, %Y`.
```smarty ```smarty
{var $ts = time()} {var $ts = time()}
{$ts|date_format:"%Y/%m/%d %H:%M:%s"} output like 2013/02/08 21:01:43 {$ts|date_format:"%Y/%m/%d %H:%M:%s"} outputs 2013/02/08 21:01:43
{$ts|date_format:"-1 day"} output like 2013/02/07 21:01:43 {$ts|date_format:"-1 day"} outputs 2013/02/07 21:01:43
{var $date = "2008-12-08"} {var $date = "2008-12-08"}
{$ts|date_format:"%Y/%m/%d %H:%M:%s"} output like 2008/12/08 00:00:00 {$ts|date_format:"%Y/%m/%d %H:%M:%s"} outputs 2008/12/08 00:00:00
``` ```
[Allowed quantificators](http://docs.php.net/strftime#refsect1-function.strftime-parameters) in **date_format**

View File

@ -1,15 +1,20 @@
Modifier escape [RU] Modifier escape
==================== ===============
Используется для кодирования / экранирования спецсимволов по алгоритмам экранирования HTML, URL'ов. По умолчанию активирован режим экранирования HTML. The modifier escapes a string for safe insertion into the output.
It supports different escaping strategies depending on the template context.
By default, it uses the HTML escaping strategy:
```smarty ```smarty
{$html_data|escape:'HTML'} {$post.title|escape:'html'}
``` ```
Возможные режимы экранирования The modifier supports the following escaping strategies:
* HTML * html: escapes a string for the HTML body context.
* URL * url: escapes a string for the URI or parameter contexts.
* js: escapes a string for the JavaScript context.
для простоты, модификатор обладает коротким псевдонимом `|e` For convenience, the `e` modifier is defined as an alias of `escape` modifier.
Second parameter is charset.

View File

@ -1,10 +1,10 @@
Modifier in [RU] Modifier in
================ ===========
Булевый модификатор, позволяющий проверить наличие значения переменной в массиве: The modifier is implementation of `in` operator (performs containment test).
```smarty ```smarty
{if $number|in:[1, 3, 55]} {if $number|in:[1, 3, 42]}
... ...
{/if} {/if}
``` ```

View File

@ -1,9 +1,10 @@
Modifier length [RU] Modifier length
==================== ===============
Модификатор возвращает длину значения переменной The modifier returns the number of items of a sequence or mapping, or the length of a string (works with UTF8 without `mbstring`)
* если массив - длина массива ```smarty
* если итератор - длина итератора {if $images|length > 5}
* если строка - длина строки (поддерживается UTF8 и не требует `mbstring`) to many images
* для других значений возвращается 0 {/if}
```

View File

@ -1,5 +1,5 @@
Modifier |lower Modifier lower
=============== ==============
Modifier is used to lowercase a variable or string. Have short alias `low` Modifier is used to lowercase a variable or string. Have short alias `low`
This is equivalent to the PHP [strtolower()](http://docs.php.net/lower) function. This is equivalent to the PHP [strtolower()](http://docs.php.net/lower) function.

View File

@ -1,13 +1,13 @@
Modifier strip [RU] Modifier strip
=================== ==============
Для удаления символы пробелов при использовании переменной используйте можификатор `|strip` This replaces all repeated spaces and tabs with a single space, or with the supplied string.
```smarty ```smarty
{" one two "|strip} => 'one two' {" one two "|strip} => 'one two'
``` ```
Что бы убрать переносы строк укажите **TRUE** первым аргументом модификатора Optional boolean parameter tell to the modifier strip also newline
```smarty ```smarty
{" multi {" multi

View File

@ -1,16 +1,16 @@
Modifier truncate [RU] Modifier truncate
======================= =================
Обрезает строку до указанной длины. Может обрезать как ровно по символу так и завершивемогуся слову, где итоговоя строка не привыет указанной длины. Modifier truncates a variable to a character length.
```smarty ```smarty
{$long_string|truncate:$length:$etc:$by_words:$middle} {$long_string|truncate:$length:$etc:$by_words:$middle}
``` ```
* `$length` обязательный параметр, указывающий максимальную длину выводимой сроки * `$length`, required. Parameter determines how many characters to truncate to.
* `$etc`, по умолчанию `...`, содержащий строку которой будет заменены "лишние" символы. * `$etc`, by default `...`. This is a text string that replaces the truncated text.
* `$by_word`, по умолчанию **FALSE**. Флаг указывает модификатору не разбивать слово, а найти ближайший (в меньшую строну) пробельный символ, после которого строка буде обрезана * `$by_word`, by default **FALSE**. This determines whether or not to truncate at a word boundary with TRUE, or at the exact character with FALSE.
* `$middle`, по умочанию **FALSE**. Включенный флаг, который указывает, что "лишние" данные нужно вырезать из середины строки, а не из конца. * `$middle`, by default **FALSE**. This determines whether the truncation happens at the end of the string with FALSE, or in the middle of the string with TRUE.
```smarty ```smarty
{var $str = "very very long string"} {var $str = "very very long string"}
@ -19,4 +19,4 @@ Modifier truncate [RU]
{$str|truncate:5:" ... ":true:true} output: very ... string {$str|truncate:5:" ... ":true:true} output: very ... string
``` ```
Модификатор работает отлично с UTF8 и не требует расширения `mbstring` Modifier do not use `mbstring` when works with UTF8.

View File

@ -1,5 +1,5 @@
Modifier unescape [RU] Modifier unescape
====================== =================
Модификатор, обратный модификатору [escape](./escape.md) `Unescape` is used to decode entity, html, js and URI. See [escape](./escape.md)

View File

@ -1,13 +1,13 @@
Modifier |upper Modifier upper
=============== ==============
Modifier is used to uppercase a variable or string. Have short alias `up` Modifier is used to uppercase a variable or string. Have short alias `up`.
This is equivalent to the PHP [strtoupper()](http://docs.php.net/strtoupper) function. This is equivalent to the PHP [strtoupper()](http://docs.php.net/strtoupper) function.
```smarty ```smarty
{var $name = "Bzick"} {var $name = "Bzick"}
{$name} output Bzick {$name} outputs Bzick
{$name|upper} output BZICK {$name|upper} outputs BZICK
{$name|up} output BZICK too {$name|up} outputs BZICK too
``` ```

View File

@ -51,15 +51,18 @@ class Modifier
* *
* @param string $text * @param string $text
* @param string $type * @param string $type
* @param string $charset
* @return string * @return string
*/ */
public static function escape($text, $type = 'html') public static function escape($text, $type = 'html', $charset = 'UTF-8')
{ {
switch (strtolower($type)) { switch (strtolower($type)) {
case "url": case "url":
return urlencode($text); return urlencode($text);
case "html"; case "html";
return htmlspecialchars($text, ENT_COMPAT, 'UTF-8'); return htmlspecialchars($text, ENT_COMPAT, $charset);
case "js":
return json_encode($text, 64 | 256); // JSON_UNESCAPED_SLASHES = 64, JSON_UNESCAPED_UNICODE = 256
default: default:
return $text; return $text;
} }