edit

Phrases

Skytells PHP Framework has a build-in Phrases System.


Introduction

This Phrases engine is not required to develop a web application using our framework. But its up to you, we believe in technology, and this believe must be globally, That's why we've developed this engine to our framework.

No need to load this engine

This engine is included in the standard Framework library. So it doesn't need to be loaded in your controller using the engine loader.

Getting Started with Phrases

Step by step we will learn how to use a multiple Phrases on your web application using the framework.

First of all, we have to look at the RAW files of the Phrases 1:

Step TWO : For each language file we need to add our phases2: - This will take sometime we know that.

BUT, at the moment we're trying to make an engine to translate your primary language into 28 language.

Step THREE : Start using the language print method3: on your view.

Phrases Configuration

Of course you need to enable the phrases from your configuration file.

1
Path : Application/Misc/Settings.php

Find :

1
2
3
4
5
6
7
8
9
<?php
// CHANGE THIS TO TRUE TO ENABLE THIS FEATURE.
 $Settings["MULTILANGS_DETECTION"] = TRUE;
 // Use the BUILT-IN Engine as the primary languages engine?
 $Settings["USE_BUILTIN_PHRASES"] = FALSE;
 // THE SESSION ID TO STORE THE SELECTED LANG.
 $Settings["LANG_SESID"] = "SFW_LANGUAGE";
 // THE DEFAULT LANGUAGE FOR YOUR APP ( MUST BE IN THE LANGUAGES DIR. )
 $Settings["DEFAULTLANG"] = "en_US";
NAME DETAILS
MULTILANGS_DETECTION This array key is used for detecting the current language, It must be TRUE incase of using any language engine.
USE_BUILTIN_PHRASES This array key enables or disables the Phrases system.
LANG_SESID The session key where your current language key will be stored on.
DEFAULTLANG The default language for your app.

Now lets Turn the following settings ON :

1
2
3
4
<?php
 $Settings["MULTILANGS_DETECTION"] = TRUE; // <-- TRUE
 $Settings["USE_BUILTIN_PHRASES"] = TRUE; // <-- TRUE
 $Settings["DEFAULTLANG"] = "en_US";

Save your settings and go next..

Locating Phrases Files

1
Path : Application/Misc/Phrases

Map :-

1
2
3
4
5
6
| Application/
| -- Library/
| ----- Phrases/
| -------- en_US.php
| -------- fr_FR.php
| -------- ar_EG.php

Please add your phases inside each language file.

And if you wish to add a new language file, Please read how to add un-existing4: language to your web application.

Adding Phases

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
<?php
  /*
  ------------------
  Language: English
  ------------------
  */
  global $lang;
  $lang['PAGE_TITLE'] = 'Hello World!';
  $lang['HEADER_TITLE'] = 'My website header title';
  $lang['SITE_NAME'] = 'My Website';
  $lang['SLOGAN'] = 'My slogan here';
  $lang['HEADING'] = 'Heading';

You need to redefine and add your phases, Lets say we want to add a new phase named MY_LANG_PHASE So, You'll have to write it as this way.

1
2
<?php
  $lang['MY_LANG_PHASE'] = 'Hazem';

Good? .. Alright, Let's move to the next file and perform the same action to all files listed on this folder.

Displaying Phase

Right Now, Everything is done! Just one step remaining, It's Displaying the language, So when we want to display a language phase on our view we will use a printing method named ( l ).

How? .. See an Example :-

Now go to your view file, And write the following code :

1
2
Hi, <?= l(MY_LANG_PHASE); ?>
// Output : Hi, Hazem

Notice

The following function will not display the language phase until we print it by our selves.
So here we should think about two things.

  1. Displaying the Phase using echo to be like :
1
2
3
<?php
echo Hi, l(MY_LANG_PHASE);
// Output : Hi, Hazem

OR 2. Displaying the phase using the self return display to be like :

1
2
Hi, <?= l(MY_LANG_PHASE); ?>
// Output : Hi, Hazem

Good? .. Lets move..

Changing Phrases

By default, the language system will respond to this action from URL.

1
www.website.com/?lang=en_US

OR

1
www.website.com/?lang=fr_FR

And uses the cookies to store language information and active language.

Creating un existing language

Warning

This method for Advanced programmers only.

The total included Phrases with the framework is 5 or 6, which is not enough as much!

In order to create a new Phrases just create its file in Phrases folder.

1
Application/Misc/Phrases/MyLang.php

Then write the following code:

1
2
3
<?php
global $lang;
$lang['KEY'] = 'VALUE';

Now Your file will be used when you navigate the following URL parameter to the URI.

1
lang?=MyLang

Notice that the file name must be like the given parameter.

Detecting Language

You can detect the current language using this function.

1
detectCurrentLanguage();

And add your language into the switch statement.


  1. All Phrases files are located in this path below : 

  2. For each language file in your language dir, Open the file using your favorite PHP editor. And it will looks like this : 

  3. The (l) function is a shortcut for language, it will return the value of the selected language key. 

  4. BUT! .. You can add your own Phrases to the