PHP Classes

XML Dictionary: Retrieve text translations from XML files

Recommend this page to a friend!
  Info   View files Example   Demos   View files View files (4)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 207 All time: 8,384 This week: 423Up
Version License PHP version Categories
xml-dictionary 1GNU General Publi...5.3XML, Localization, PHP 5, Templates
Description 

Author

This package can retrieve text translations from XML files.

It can parse a given XML file and extract translations of text for one or more languages.

The class can return the translations of individual text strings for a specific supported language or for the default language.

It can also replace some marks in the text with some formatting HTML tags like bold, italic, underscore and line break.

Picture of Ricky Scotti
  Performance   Level  
Name: Ricky Scotti <contact>
Classes: 3 packages by
Country: Switzerland Switzerland
Age: 44
All time rank: 190121 in Switzerland Switzerland
Week rank: 362 Up2 in Switzerland Switzerland Up

Recommendations

Extract XML tag values
Parse a XML document and extract the values

Example

<?php
   
   
require_once((__DIR__).'/lib/class.Language.php');
   
   
//file XML
   
$fileNameXML = (__DIR__).'/lang/translation.xml';
   
   
//Variable for Output HTML
   
$separatorPhp = "<hr>".PHP_EOL;
   
   
   
//Call Language XML Class
    # @param : $fileNameXML = XML file location
    # @param (optional) : $speakerLanguage = language format (used in XML : "it","en","de" ...)
   
$language = new Dictonary\Translation($fileNameXML,'en');

   
//Output Translation:
    # function word()
    # @param : $wordToTranslate = XML word to translate in specific section
    # @param (optional) : $pageName = section/page name where get translation in XML
    # @param (optional) : $toLang = translate word NOT in default setted language

    #-------------------------------------------------------------------------------------------#

    /*
    EXAMPLE 1;
        get word "Example PHP Classes" in example section (file name example.php)
        a) in language "en" (setted in class definition,)
        b) in language "it"
        c) in language "de" (not exist in XML!, get default setted language: "en")
        d) in language "klingon" (is not translated, warning returned)

    */
   
echo 'a) '.$language->word('Example PHP Classes').$separatorPhp;
    echo
'b) '.$language->word('Example PHP Classes',null,'it').$separatorPhp;
    echo
'c) '.$language->word('Example PHP Classes',null,'de').$separatorPhp;
    echo
'd) '.$language->word('Example PHP Classes',null,'klingon').$separatorPhp;
   
   
/*
    EXAMPLE 2;
        get word "Hello" in "House" section
        e) in language "klingon"
    */
   
echo 'e) '.$language->word('Hello','House','klingon').$separatorPhp;
   
   
/*
    EXAMPLE 3 for printf;
        get word "Exampme Parameters" in file php section
        g) in language default
    */
   
printf('g) '.$language->word('Exampme Parameters').$separatorPhp,'parameter',12);
   
   
//Output ALL Languages founded in XML file
    # function listLanguages()
    # @param (optional) : $sort = 0-1(default) Sorting array language found in xml
    # 0: found in XML
    # 1: alphabetical order
    #-------------------------------------------------------------------------------------------#
   
foreach ($language->listLanguages() as $value) {
        echo
$value.'; ';
    }


  Files folder image Files  
File Role Description
Files folder imagelang (1 file)
Files folder imagelib (1 file)
Plain text file example.php Example Example file
Image file FileXML.jpg Screen XML file structure

  Files folder image Files  /  lang  
File Role Description
  Plain text file translation.xml Data XML Dictonary

  Files folder image Files  /  lib  
File Role Description
  Plain text file class.Language.php Class Class Dictonary

 Version Control Unique User Downloads Download Rankings  
 0%
Total:207
This week:0
All time:8,384
This week:423Up