Info | ||
---|---|---|
| ||
|
All phrases that used on your apps should be defined before using. The below instructions will help you:
How to to define?
Add file phrase.json on root path of your apps.
Example:
...
language | actionscript3 |
---|---|
theme | Midnight |
title | phrase.json |
linenumbers | true |
...
Block Component
Block is a component helps developer separate a complex layout to varieties components in re-usage way.
Each block contains its own logic and template.
Create your first block
Create php class RecentItems under directory ./PF.Site/Apps/FirstApp/Block/
paste following code
Code Block | ||||
---|---|---|---|---|
| ||||
<?php namespace Apps\TodoList\Block; // RecentMembers block must be child of \Phpfox_Components // class RecentItems extends \Phpfox_Component { // this method will be invoked by phpfox public function process() "en" :{ "", // assign variables to template $this->template() "es" : "Spanish Phrase text", ->assign([ 'sHeader' => 'Recent "ot" : "Other language phrase text"Items', // block title 'aItems' => ['Item 1', 'Item 2', }'Item 3'], "var_name" : {]); return 'block'; } } |
Create php template file recent_items.html.php under directory ./PF.Site/Apps/FirstApp/Block/
Code Block | ||||
---|---|---|---|---|
| ||||
<ul> {foreach from=$aItems item=item} <li "en" : "Phrase text", class="category"> <p> {$item} </p> {/foreach} </ul> |
Update start.php, paste following code
Code Block | ||||
---|---|---|---|---|
| ||||
$module->addComponentNames('block', [ "es" : "Spanish Phrase text", 'todo.recent_items' => Block\RecentItems::class, ]); |
Update Install.php, change setComponent() and setComponentBlock()
Code Block | ||||
---|---|---|---|---|
| ||||
protected function setComponent() { "ot" : "Other language phrase text" $this->component = [ "block" => [ }, } |
We have 4 ways to define a phrase:
- The easiest way: Put phrase on key, put blank on value (of json).
Example:
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
{ "Manage Video" : "recent_items" } |
Use:
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
<?php
echo _p("Manage Video"); |
It will show: Manage Video
- Var_name define: Put var_name on key, put phrase on value (of json).
Example:
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
{ => "", "manage_video" : "Manage Video" } |
Use:
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
<?php
echo _p("manage_video"); |
It will show: Manage Video
Info |
---|
With first and second way, we will use phrase "Manage Video" for all available languages on your site. |
- Easy Multi-language define:
Example:
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
{ "Phrase text" : { ], "controller" => [ "enindex" : => "todo.index", ] ]; "es" :} "Spanish Phrase text", protected function setComponentBlock() { $this->component_block = [ "ot" : "Other language phrase text "Recent Items" => [ "type_id" }, } |
Use:
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
<?php
echo _p("Phrase text"); |
"en": can be missed
Info |
---|
Clients' site have to installed language package with id "es", if not, es phrase will by pass. It's the same for other language package. |
It will show: Phrase text (if default language of user is en)
It will show: Spanish Phrase text (If default language of user is es)
...
- Var name multi-language define:
Example:
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
{ "phrase_text" : { => "0", "m_connection" => "todo.index", "en" : "Phrase text", "component" => "recent_items", "es" : "Spanishlocation" Phrase text", => "3", "is_active" => "ot1", : "Other language phrase text" "ordering" => "1" }, } |
Use:
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
<?php echo _p("phrase_text"); |
"en": is required (can not be missed)
Info |
---|
Clients' site have to installed language package with id "es", if not, es phrase will by pass. It's the same for other language package. |
It will show: Phrase text (if default language of user is en)
It will show: Spanish Phrase text (If default language of users is es)
....
How to use
General:
Code Block | ||||
---|---|---|---|---|
| ||||
<?php _p('var_name', $attr) |
Smarty:
Code Block | ||||
---|---|---|---|---|
| ||||
{_p var="var_name" $attr} |
Twig
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
{{ _p("var_name", $arrt) }} |
Javascript
Code Block | ||||
---|---|---|---|---|
| ||||
oTranslations['var_name', arrt] |
With $arrt is variables of phrase.
Use Phrase with variable
The variables can be included in a phrase. Example:
Code Block | ||||
---|---|---|---|---|
| ||||
{
"total_people_liked_this_blog" : "{total} people liked this blog
} |
Use:
Code Block | ||||
---|---|---|---|---|
| ||||
<?php
echo _p("total_people_liked_this_blog", ["total" => 5]); |
It will show: 5 people liked this blog
...
],
];
}
|
Then update your app to apply your modification. Open browser again, see result: