PHP Classes

PHP Locale Kit: Get application locale texts from Google Translate

Recommend this page to a friend!
  Info   View files Example   View files View files (12)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 100 All time: 9,800 This week: 455Up
Version License PHP version Categories
php-locale-kit 1.0.0Custom (specified...5Localization, PHP 5, Databases, Web s...
Description 

Author

This package can get application locale texts from Google Translate.

It can take given application texts for a given language and returns the texts translated to the current user language using Google Translate API.

The translated texts are cached locally using a SQLite database.

Picture of Enrico Sola
Name: Enrico Sola <contact>
Classes: 5 packages by
Country: Italy Italy
Age: 30
All time rank: 3211121 in Italy Italy
Week rank: 250 Up9 in Italy Italy Up

Example

<?php
require dirname(__FILE__) . '/../php-locale-kit.php';
//require dirname(__FILE__) . '/../php-tiny-cacher.php';
   
use PHPTinyCacher\PHPTinyCacher;
use
PHPLocaleKit\Package;

$path = 'demo.db';

if (
in_array('--cache', $argv) === true ){
   
$cache = new PHPTinyCacher();
   
//Setting up cache.
   
echo 'Running the test script with caching enabled...' . PHP_EOL;
   
$cache->setStrategy(PHPTinyCacher::STRATEGY_REDIS)->setNamespace('demo')->setVerbose(true)->connectToRedis('127.0.0.1', 6379, 0);
}
$start = microtime(true);
$package = new Package();
$package->setVerbose(true);
if ( isset(
$cache) === true ){
   
$package->setCache(true)->setCacheHandler($cache);
}
//Setting the path to the package.
echo 'Setting package path...' . PHP_EOL;
$package->setPath($path);
echo
'Connected to package, trying to set "en-US" as locale...' . PHP_EOL;
//Setting the locale code...
$package->setLocale('en-US', false);
//Checking if the locale that has been set is a fallback or is the same that has been specified.
if ( $package->isFallback() === true ){
    echo
'"en-US" appears to be not supported by the package, falling back to another English variant if available...' . PHP_EOL;
   
//Getting the fallback locale selected by the library.
   
echo 'Locale has been set to "' . $package->getLocale() . '", now getting labels with IDs 1, 2 and 3...' . PHP_EOL;
}else{
    echo
'Locale has been set, now getting labels with IDs 1, 2 and 3...' . PHP_EOL;
}
//Getting the labels by their IDs.
$lables = $package->getLabels(array(1, 2, 3));
echo
'Labels fetched, here you are the label with ID 2: ' . $lables[2] . PHP_EOL;
echo
'Fetching all languages supported by this package...' . PHP_EOL;
//Getting the list of all the languages supproted by the package.
$locales = $package->getSupportedLocales();
$locales = array_map(function($element){
    return
$element['locale'];
},
$locales);
echo
'This package supports these locales: ' . implode(', ', $locales) . '.' . PHP_EOL;
echo
'Checking if Italian is supported by the package...' . PHP_EOL;
//Checking if a specific locale is supported by the package.
echo 'Is Italian supported? ' . ( $package->isLocaleSupported('it') === true ? 'Yes' : 'No' ) . '.' . PHP_EOL;
if ( isset(
$cache) === true ){
    echo
'Invalidating the cache...' . PHP_EOL;
   
//Removing all cached data.
   
$cache->invalidate();
}
echo
'Demo completed in ' . ( microtime(true) - $start ) . ' seconds.' . PHP_EOL;


Details

php-locale-kit


  Files folder image Files  
File Role Description
Files folder imagedemo (2 files)
Accessible without login Plain text file changelog.md Data Auxiliary data
Accessible without login Plain text file cli.md Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file database.sql Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file LICENSE.md Lic. License text
Plain text file php-locale-kit Class Class source
Plain text file php-locale-kit.php Class Class source
Accessible without login Plain text file README.md Doc. Documentation
Accessible without login Plain text file todo.txt Doc. Documentation

  Files folder image Files  /  demo  
File Role Description
  Accessible without login Plain text file demo-package.php Example Example script
  Accessible without login Plain text file demo-translate.php Example Example script

 Version Control Unique User Downloads Download Rankings  
 100%
Total:100
This week:0
All time:9,800
This week:455Up