1. Go to this page and download the library: Download niirrty/niirrty.translation library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
niirrty / niirrty.translation example snippets
use \Niirrty\Locale\Locale;
use \Niirrty\Translation\Sources\PHPFileSource;
use \Niirrty\Translation\Translator;
try
{
// Init the locale
$locale = Locale::Create(
// The fallback locale if no other was found
new Locale( 'de', 'de', 'UTF-8' ),
// Check also the URL path for an locale or language part?
true,
// This are the names of the parameters, accepted from $_POST, $_GET and $_SESSION
[ 'lc', 'locale', 'language', 'lang', 'lng' ]
);
// Init the translator instance with defined locale
$translator = new Translator( $locale );
// Define the templates source directory. There is also a JSONFileSource and a XMLFileSource
$translatorSource = new PHPFileSource( __DIR__ . '/translations', $locale );
// ...and add the source to template engine
$translator->addSource( $translatorSource );
// If you want access the Translator instance globally
$translator->setAsGlobalInstance();
// Example output
echo Translator::GetInstance()->read( 'Hello1', 'MyApp', 'Hello people!' ), "\n",
$translator->read( 'NiceTM', 'MyApp', 'NiceToMeetYouM!' );
}
catch ( \Throwable $ex )
{
// TODO: Do some error handling
}