PHP Classes

AlText: Translate texts extracted from code into INI files

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 170 All time: 8,841 This week: 79Up
Version License PHP version Categories
altext 1.0GNU General Publi...5Localization, PHP 5, Parsers
Description 

Author

This package can translate texts extracted from code into INI files.

It provides classes that can parse PHP code and extract text strings to be translated by detecting calls to the function altext().

The extracted texts are stored in .INI files that can be loaded by the application scripts to get the localized texts into different idioms.

The altext() function is similar to the PHP gettext() function. It uses text defined in an INI file with translations for the texts and returns the respective translated text using an hash of the requested text.

There is also a class that can merge existing translations with new ones extracted from more up to date source code.

Picture of Everton da Rosa
  Performance   Level  
Name: Everton da Rosa <contact>
Classes: 17 packages by
Country: Brazil Brazil
Age: 43
All time rank: 78555 in Brazil Brazil
Week rank: 47 Up3 in Brazil Brazil Up
Innovation award
Innovation award
Nominee: 3x

Recommendations

Example

<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
        <?php
       
/**
         * The variable $LANG should receive the result of {@link http://php.net/parse_ini_file parse_ini_file()}. The @ in early suppresses the error message if the INI file is not found. $LANG is a standardized variable name. If you want to use another variable name, you must change the {@link altext()} function in the file {@link altext.php}
         */
       
$LANG = @parse_ini_file('en_US.ini');
       
       
/*
         * include altext library
         */
       
require_once 'altext.php';
       
       
/**
         * The translation is done by {@link altext()} function. If you want to use another name function, keep in mind that "altext" is used by the parser to search for messages to translate.
If you want to change the function name (for gettext, for example), also change the {@link altext.php} files and {@link altext.parser.php}.
In {@link altext.php}, just change the name of the function.
In {@link altext.parser.php} file, change the line <code>preg_match_all ("/altext\(\'(.*)\'\)/", $data, $matches)</code> exchanging "altext" with the name of the desired function. This will make the parser search for the new function name and not by "altext".
         */
       
echo altext('Esta mensagem será traduzida');
        echo
altext("Outra mensagem para traduzir");//Only messages in single quotes are identified by the parser. This is necessary to prevent variables are interpreted during the execution of the source code and are not identified in the INI files.
       
echo sprintf(//We need to place multiple lines because the parser is confused with)
               
altext('Hoje é dia %s')
                ,
date('d'));
       
       
?>
</body>
</html>


  Files folder image Files (9)  
File Role Description
Plain text file altext.merge.php Class Auxiliary class
Plain text file altext.parser.php Class Auxiliary class
Accessible without login Plain text file altext.php Aux. Main script file
Accessible without login Plain text file index.php Example Example of use
Accessible without login Plain text file merge.php Aux. Auxiliary file
Accessible without login Plain text file merger.bat Data Auxiliary file
Accessible without login Plain text file parse.bat Data Auxiliary file
Accessible without login Plain text file parser.php Aux. Auxiliary file
Accessible without login Plain text file pt_BR.ini Data Example of use

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 0%
Total:170
This week:0
All time:8,841
This week:79Up