Download the PHP package samsonos/php_i18n without Composer
On this page you can find all versions of the php package samsonos/php_i18n. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download samsonos/php_i18n
More information about samsonos/php_i18n
Files in samsonos/php_i18n
Package php_i18n
Short Description SamsonPHP internalization module
License Open Software License (OSL) v 3.0
Homepage http://samsonphp.com/
Informations about the package php_i18n
Internalization(i18n) module for SamsonPHP framework
Module gives uses special global functions to give localization features for a web-application
Module default locale is empty string , its value is stored at constant. This gives ability to use any locale as default without specifying it.
Setting supported locales
For adding localization support to your web-application special global function must be called:
Where parameters are:
- , and other supported locales by
Usually this function is called in web-application starter script before , for example :
Switching locales
To switch system to another supported locale(defined by ) you should add locale prefix to url, for example if we have domain we must redirect user to for switching system to localized version. This url suffix is ignored by all SamsonPHP components and actually is invisible in URL dispatcher and in all other components. The only module who handles this suffix is (this module).
If you specify not supported locale suffix (you did not specified it in before SamsonPHP is started), URL dispatcher will handle it as regular module controller request.
Using localized views
When you switch to other supported locale then default locale, automatic system view rendering mechanism is changed. First of all system searches necessary view in localized view path, using default settings, system view path is . localized view path in this case is , where .
So if you want to have separate view files for different locales you can create two view files with the same names, for example we have english view file located at :
And russian view file located at :
Also we have regular simple controller file located at :
And default view template file located at who renders current module:
And if you try to visit URL you will get rendered instead of .
The logic is: If system does not find localized view it will use regular view.
Dictionary localization
If we don't want to create separate views for every supported locale, as they match each other in HTML markup and only differs in some words you can use dictionary localization logic.
For using global dictionary for your web-application , using default settings, you have to create special dictionary file located in with generic special function defined:
Where parameters are:
- and other supported locales by samsonos\core\SamsonLocale
- any string value to outputted and translated. This key must match in all locales for translation
- (translation to russian) string 'Translate me' in current locale array
We use function to avoid bugs when compressing web-application to a snapshot via samsonos/php_compressor
Using dictionary in views
To use dictionary created above in a view view file you should use special global function
Where parameters are:
-
- Any string value to outputted and translated. This key must match in all locales for translation
-
- If true - the translation will be returned otherwise echoed
So if we have view file(or template view file) localized string output will be:
And we don't need to create separate view files for localization.
Automatic dictionary file generation
You can use special controller to perform automatic creation of dictionary file. By default this file will be located at .
When you enter URL system automatically scans all your views/controllers/models for pattern matching function and build key value lists for every locale. So you do not have to create this dictionary manually, you add translation function to your views/controllers/modules and when finished call which will create dictionary file for you, what is left to do is fill in the translation for generated keys.
Don't worry to call several times, it won't rewrite your existing dictionary file, it will analyze it and add only new keys for translation
Generic rendering of supported locales list
We have added generic controller action for this module to simplify of rendering locale switcher in your web-application. In your template view file (or simple view file), for example you can use:
This controller action will render unordered list of supported locales and special CSS class for styling:
This is default LESS example to style this locale switcher file:
Creating multilingual alternate links
For creating alternate links, that shows, which languages you can get in your web-site, you can use following code:
Developed by SamsonOS