Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Info
titleRequires:
  • phpFox 4.5+

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:

...

languageactionscript3
themeMidnight
titlephrase.json
linenumberstrue

...

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
php

<?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
actionscript3
actionscript3
<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
php
php
$module->addComponentNames('block', [
 "es" : "Spanish Phrase text", 
 'todo.recent_items' => Block\RecentItems::class,
]);

Update Install.php, change setComponent() and setComponentBlock()

Code Block
php
php

    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
languageactionscript3
titleEasiest define
linenumberstrue
{       "Manage Video" : "recent_items"  } 

Use:

Code Block
languagephp
titleEasiest define - Using
linenumberstrue
<?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
languageactionscript3
titleVar name define
linenumberstrue
{ => "",
      "manage_video" : "Manage Video"  } 

Use:

Code Block
languagephp
titleVar name define - Using
linenumberstrue
<?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
languageactionscript3
titleMulti-language define
linenumberstrue
{ 
	"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
languagephp
titleMulti-language define - Using
linenumberstrue
<?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
languageactionscript3
titleVar name multi-language define
linenumberstrue
{ 
	"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
languagephp
titleVar name multi-language define - Using
linenumberstrue
<?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
languagephp
titleuse _p
<?php _p('var_name', $attr)

Smarty:

Code Block
languagexml
titlesmarty _p
{_p var="var_name" $attr}

Twig

Code Block
languagexml
titleTwig
linenumberstrue
{{ _p("var_name", $arrt) }}

Javascript

Code Block
languagejs
linenumberstrue
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
languageactionscript3
linenumberstrue
{
	"total_people_liked_this_blog" : "{total} people liked this blog
}

Use:

Code Block
languageactionscript3
linenumberstrue
<?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:

Image Added