Skip to content

Commit

Permalink
config,loader,pagination,translate
Browse files Browse the repository at this point in the history
  • Loading branch information
netstu committed Dec 28, 2012
1 parent 80d61cc commit 2d89bb5
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 68 deletions.
16 changes: 8 additions & 8 deletions zh/reference/config.rst
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
Reading Configuration
=====================
:doc:`Phalcon\\Config <../api/Phalcon_Config>` is a component used to read configuration files of various formats (using adapters) into PHP objects for use in an application.
:doc:`Phalcon\\Config <../api/Phalcon_Config>` 使用相应的适配器读取配置文件,转换为面像对象的方式进行操作配置文件。

File Adapters
-------------
The adapters available are:
可用的适配器:

+-----------+---------------------------------------------------------------------------------------------------+
| File Type | Description |
Expand All @@ -14,9 +14,9 @@ The adapters available are:
| Array | Uses PHP multidimensional arrays to store settings. This adapter offers the best performance. |
+-----------+---------------------------------------------------------------------------------------------------+

Native Arrays
原生数组
-------------
The next example shows how to convert native arrays into Phalcon\\Config objects. This option offers the best performance since no files are read during this request.
下面的示例演示了如何把原生PHP数组转化为 Phalcon\\Config 对象。下面的示例提供了最佳性能,因为在此请求期间,未发生文件读取。

.. code-block:: php
Expand Down Expand Up @@ -44,7 +44,7 @@ The next example shows how to convert native arrays into Phalcon\\Config objects
echo $config->database->username, "\n";
echo $config->mysetting, "\n";
If you want to better organize your project you can save the array in another file and then read it.
如果你想更好的组织你的项目结构,你可以把数组保存到一个单独的文件中,然后读取它。

.. code-block:: php
Expand All @@ -53,9 +53,9 @@ If you want to better organize your project you can save the array in another fi
require "config/config.php";
$config = new \Phalcon\Config($settings);
Reading INI Files
读取INI文件
-----------------
Ini files are a common way to store settings. Phalcon\\Config uses the optimized PHP function parse_ini_file to read these files. Files sections are parsed into sub-settings for easy access.
INI文件是一种常见的方式来存储设置。Phalcon\\Config 使用优化的PHP函数parse_ini_file读取这些文件。INI文件中的sections部分被解析成子设定,以方便使用。

.. code-block:: ini
Expand All @@ -74,7 +74,7 @@ Ini files are a common way to store settings. Phalcon\\Config uses the optimized
[models]
metadata.adapter = "Memory"
You can read the file as follows
你可以按以下方式读取配件文件:

.. code-block:: php
Expand Down
46 changes: 16 additions & 30 deletions zh/reference/loader.rst
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
Universal Class Loader
万能的类文件加载器
======================
:doc:`Phalcon\\Loader <../api/Phalcon_Loader>` is a component that allows you to load project classes automatically, based on some predefined rules.
Since this component is written in C, it provides the lowest overhead in reading and interpreting external PHP files.
:doc:`Phalcon\\Loader <../api/Phalcon_Loader>` 这个组件允许你根据预定义规则自动加载项目中的类文件。
此组件采用C语言编写,在读取和解析PHP文件方面,使用了最低的性能开销。

The behavior of this component is based on the PHP's capability of `autoloading classes`_. If a class that does not exist is used in any part of the
code, a special handler will try to load it. :doc:`Phalcon\\Loader <../api/Phalcon_Loader>` serves as the special handler for this operation. By
loading classes on a need to load basis, the overall performance is increased since the only file reads that occur are for the files needed. This
technique is called `lazy initialization`_.
此组件功能是基于PHP自身的 `autoloading classes`_ 实现的。如果在任何代码部分未找到类,那么它将尝试使用特殊的处理加载它,:doc:`Phalcon\\Loader <../api/Phalcon_Loader>` 就是用于处理这种任务的。加载类文件采用按需加载的方式,只有需要某个类文件时,才会进行加载及文件读取。这种技术被称为延时初始化( `lazy initialization`_ )。

With this component you can load files from other projects or vendors, this autoloader is `PSR-0 <https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md>`_ compliant.
使用此组件,你可以从其他项目或vendors(不知道是什么,应该指的是其他服务器)加载文件,autoloader 采用 `PSR-0 <https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md>`_ 标准。

:doc:`Phalcon\\Loader <../api/Phalcon_Loader>` offers four options to autoload classes. You can use them one at a time or combine them.
:doc:`Phalcon\\Loader <../api/Phalcon_Loader>` 提供四种方式自动加载类文件,你可以一次只使用其中一个,或者混合使用。

Registering Namespaces
----------------------
If you're organizing your code using namespaces, or external libraries do so, the registerNamespaces() provides the autoloading mechanism. It
takes an associative array, which keys are namespace prefixes and their values are directories where the classes are located in. The namespace
separator will be replaced by the directory separator when the loader try to find the classes. Remember always to add a trailing slash at
the end of the paths.
如果你的代码使用了命名空间或外部库文件,可以使用registerNamespaces(),它提供了一种自动加载机制,可以通过传递一个关联数组,key是命名空间前辍,value是类文件存放的目录。当加载并试图查找类文件时,分隔符被替换成目录分隔符,以便正确加载类文件。还有一点请注意,value末尾一定要以"/"结尾。

.. code-block:: php
Expand All @@ -44,9 +38,7 @@ the end of the paths.
Registering Prefixes
----------------------
This strategy is similar to the namespaces strategy. It takes an associative array, which keys are prefixes and their values are directories
where the classes are located in. The namespace separator and the "_" underscore character will be replaced by the directory separator when
the loader try to find the classes. Remember always to add a trailing slash at the end of the paths.
这种策略非常类似上面讲到的命名空间的加载机制。它也需要一个关联数组,key是前辍,value是类所在的目录。加载的时候,命名空间分隔符和下划线"_"将要被替换为目录分隔符。还是请注意,value的结尾一定要以"/"作为结束符。

.. code-block:: php
Expand All @@ -73,9 +65,7 @@ the loader try to find the classes. Remember always to add a trailing slash at t
Registering Directories
-----------------------
The second option is to register directories, in which classes could be found. This option is not recommended in terms of performance,
since Phalcon will need to perform a significant number of file stats on each folder, looking for the file with the same name as the class.
It's important to register the directories in relevance order. Remember always add a trailing slash at the end of the paths.
第三种方式是注册目录,在注册的目录中找到类文件。在性能方面,不建议使用此种方式,因为Phalcon将对注册的所有目录及文件进行查找,直接查找具有相同名称的类文件。注册目录时的顺序是非常重要的。请注意,结尾以"/"结束。

.. code-block:: php
Expand Down Expand Up @@ -104,10 +94,7 @@ It's important to register the directories in relevance order. Remember always a
Registering Classes
-------------------
The last option is to register the class name and its path. This autoloader can be very useful when the folder convention of the
project does not allow for easy retrieval of the file using the path and the class name. This is the fastest method of autoloading.
However the more your application grows, the more classes/files need to be added to this autoloader, which will effectively make
maintenance of the class list very cumbersome and it is not recommended.
最后一种方式是注册类的名称和路径。这种加载方面是最快的一种加载方式。然而,随着应用程序的增长,更多的类及文件需要加载,这将使维护工作变得非常麻烦,因为不太建议使用。

.. code-block:: php
Expand All @@ -132,10 +119,9 @@ maintenance of the class list very cumbersome and it is not recommended.
// i.e. library/OtherComponent/Other/Some.php
$some = new Some();
Additional file extensions
其他扩展名文件的加载
--------------------------
Some autoloading strategies such as "prefixes", "namespaces" or "directories" automatically append the "php" extension at the end of the checked file. If you
are using additional extensions you could set it with the method "setExtensions". Files are checked in the order as it were defined:
一些自动加载策略,如"prefixes","namespaces",或"directories"都会自动加载扩展名为".php"的文件。如果你想自动加载其他扩展类型的文件时,你可以使用"setExtensions"方法。示例如下:

.. code-block:: php
Expand All @@ -149,7 +135,7 @@ are using additional extensions you could set it with the method "setExtensions"
Modifying current strategies
----------------------------
Additional data could be added to the existing values for strategies in the following way:
通过下面的方式可以把需要后来加载的其他文件合并到上述加载策略中:

.. code-block:: php
Expand All @@ -164,11 +150,11 @@ Additional data could be added to the existing values for strategies in the foll
true
);
Passing "true" as second parameter will merge the current values with new ones in any strategy.
通过传递第二个参数"true",可以让新的目录或类文件合并到上述四种加载策略中。

Autoloading Events
------------------
In the following example, the EventsManager is working with the class loader, allowing us to obtain debugging information regarding the flow of operation:
在下面的例子中,EventsManager与类加载器协同工作,使我们能够获得操作流程的调试信息:

.. code-block:: php
Expand All @@ -195,7 +181,7 @@ In the following example, the EventsManager is working with the class loader, al
$loader->register();
Some events when returning boolean false could stop the active operation. The following events are supported:
当事件返回布尔值false时,可以停止激活的操作。支持以下一些事件:

+------------------+---------------------------------------------------------------------------------------------------------------------+---------------------+
| Event Name | Triggered | Can stop operation? |
Expand Down
19 changes: 9 additions & 10 deletions zh/reference/pagination.rst
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
Data Pagination
数据分页
===============
The process of pagination takes place when we need to present big groups of arbitrary data gradually. Phalcon\\Paginator offers a
fast and convenient way to split these sets of data browsable pages.
当有一大组数据需要呈现时,我们需要用到数据分页。Phalcon\\Paginator 提供了一个快捷,方便的方法对大组数据进行分割,以达到分页浏览的效果。

Data Adapters
-------------
This component makes use of adapters to encapsulate different sources of data:
这个组件使用不同的适配器来封装不同的数据源:

+--------------+-------------------------------------------------------+
| Adapter | Description |
Expand All @@ -17,7 +16,7 @@ This component makes use of adapters to encapsulate different sources of data:

Using Paginators
----------------
In the example below, the paginator will use as its source data the result of a query from a model, and limit the displayed data to 10 records per page:
在下面的例子中,paginator将从model中读取数据作为其数据源,并限制每页显示10条记录:

.. code-block:: php
Expand All @@ -44,7 +43,7 @@ In the example below, the paginator will use as its source data the result of a
// Get the paginated results
$page = $paginator->getPaginate();
Variable $currentPage controls the page to be displayed. The $paginator->getPaginate() returns a $page object that contains the paginated data. It can be used for generating the pagination:
变量 $currentPage 控制将显示哪一页。 $paginator->getPaginate() 返回一个包含分页数据的 $page 对象,它将用于生成分页:

.. code-block:: html+php

Expand All @@ -63,7 +62,7 @@ Variable $currentPage controls the page to be displayed. The $paginator->getPagi
<?php } ?>
</table>

The $page object also contains navigation data:
$page对象还包含以下数据:

.. code-block:: html+php

Expand All @@ -74,9 +73,9 @@ The $page object also contains navigation data:

<?php echo "You are in page ", $page->current, " of ", $page->total_pages; ?>

Page Attributes
Page 属性
---------------
The $page object has the following attributes:
$page对象包含以下一些属性:

+---------+--------------------------------------------------------+
| Adapter | Description |
Expand All @@ -90,7 +89,7 @@ The $page object has the following attributes:
| last | The last page in the set of records |
+---------+--------------------------------------------------------+

Implementing your own adapters
实现自定义的分页适配器
------------------------------
The :doc:`Phalcon\\Paginator\\AdapterInterface <../api/Phalcon_Paginator_AdapterInterface>` interface must be implemented in order to create your own paginator adapters or extend the existing ones:

Expand Down
31 changes: 11 additions & 20 deletions zh/reference/translate.rst
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
Multi-lingual Support
多语言支持
=====================
The component :doc:`Phalcon\\Translate <../api/Phalcon_Translate>` aids in creating multilingual applications. Applications using this component,
display content in different languages, based on the user's chosen language supported by the application.
在应用程序开发中,可使用:doc:`Phalcon\\Translate <../api/Phalcon_Translate>` 组件帮助实现多语言。使用此组件,可根据用户选择的语言提供相应的语言支持。

Adapters
适配器
--------
This component makes use of adapters to read translation messages from different sources in a unified way.
该组件使用适配器,以统一的方式读取相应的语言文件。

+-------------+-----------------------------------------------------------------------------------------+
| Adapter | Description |
Expand All @@ -15,8 +14,7 @@ This component makes use of adapters to read translation messages from different

Component Usage
---------------
Translation strings are stored in files. The structure of these files could vary depending of the adapter used. Phalcon gives you the freedom
to organize your translation strings. A simple structure could be:
翻译的字符串存储在文件中,这些文件的结构可能会有所不同,具体取决于你所使用的适配器。Phalcon允许你自由的组织翻译,简单的结构可能是这样:

.. code-block:: bash
Expand All @@ -25,8 +23,7 @@ to organize your translation strings. A simple structure could be:
app/messages/fr.php
app/messages/zh.php
Each file contains an array of the translations in a key/value manner. For each translation file, keys are unique. The same array is used in
different files, where keys remain the same and values contain the translated strings depending on each language.
每个翻译文件都包含一个由key/value组成的数组。对于每一个翻译文件,key都是唯一的,相同的数组需要使用不同的文件,保持key不变,value值根据每种语言进行翻译即可。

.. code-block:: php
Expand All @@ -52,11 +49,9 @@ different files, where keys remain the same and values contain the translated st
"song" => "La chanson est %song%"
);
Implementing the translation mechanism in your application is trivial but depends on how you wish to implement it. You can use an
automatic detection of the language from the user's browser or you can provide a settings page where the user can select their language.
在应用程序中实现语言转化机制并不难,关键取决于你想如何实现它。你可以根据检测用户的浏览器语言为用户提供相应的语言支持或者提供一个设置页面供用户自己选择他们想要的语言。

A simple way of detecting the user's language is to parse the $_SERVER['HTTP_ACCEPT_LANGUAGE'] contents, or if you wish, access it
directly by calling $this->request->getBestLanguage() from an action/controller:
一个简单的用于检测客户端用户语言的方式是通过 $_SERVER['HTTP_ACCEPT_LANGUAGE'],或者也可以在controller/action中直接调用 $this->request->getBestLanguage() 也可。

.. code-block:: php
Expand Down Expand Up @@ -94,27 +89,23 @@ directly by calling $this->request->getBestLanguage() from an action/controller:
}
The _getTranslation method is available for all actions that require translations. The $t variable is passed to the views, and with it,
we can translate strings in that layer:
本例中的 _getTranslation 适用于整个控制器,通过变量 $t 传递翻译字符到视图,并且使用它。我们可以在视图层这样使用翻译字符串:

.. code-block:: html+php

<!-- welcome -->
<!-- String: hi => 'Hello' -->
<p><?php echo $t->_("hi"), " ", $name; ?></p>

The "_" function is returning the translated string based on the index passed. Some strings need to incorporate placeholders for
calculated data i.e. Hello %name%. These placeholders can be replaced with passed parameters in the "_ function. The passed parameters
are in the form of a key/value array, where the key matches the placeholder name and the value is the actual data to be replaced:
函数"_"通过传递的key返回翻译后的字符串。一些字符串中可能包含有占位符,如 Hello %name%。这些点位符可以通过函数"_"来传递参数进行替换,传递的参数是一个key/value的数组,其中的key是占位符名称,值是被替换的数据:

.. code-block:: html+php

<!-- welcome -->
<!-- String: hi-user => 'Hello %name%' -->
<p><?php echo $t->_("hi-user", array("name" => $name)); ?></p>

Some applications implement multilingual on the URL such as http://www.mozilla.org/**es-ES**/firefox/. Phalcon can implement
this by using a :doc:`Router <routing>`.
一些应用程序实现了基于URL的多语言,如 http://www.mozilla.org/**es-ES**/firefox/. Phalcon 通过使用 :doc:`Router <routing>` 也可以实现一样的效果。

Implementing your own adapters
------------------------------
Expand Down

0 comments on commit 2d89bb5

Please sign in to comment.