1. Go to this page and download the library: Download utopia-php/locale 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/ */
utopia-php / locale example snippets
topia\Locale\Locale;
// Init translations
Locale::setLanguageFromArray('en-US', [
'hello' => 'Hello',
'world' => 'World',
'likes' => 'You have {{likesAmount}} likes and {{commentsAmount}} comments.'
]); // Set English
Locale::setLanguageFromArray('he-IL', ['hello' => 'שלום',]); // Set Hebrew
Locale::setLanguageFromJSON('hi-IN', 'path/to/translations.json'); // Set Hindi
// Create locale instance
$locale = new Locale('en-US'); // en-US will be set as default language
// Get translation
echo $locale->getText('hello'); // prints "Hello"
echo $locale->getText('world'); // prints "World"
// Use placeholders
echo $locale->getText('likes', [ 'likesAmount' => 12, 'commentsAmount' => 55 ]); // prints "You have 12 likes and 55 comments."
echo $locale->getText('likes'); // prints "You have {{likesAmount}} likes and {{commentsAmount}} comments.". If you don't provide placeholder value, the string is returned unchanged.
// Get translation of different language
$locale->setDefault('he-IL');
echo $locale->getText('hello'); // prints "שלום"
$translations = [
'app.landing.title' => 'Welcome to My App.',
'app.landing.cta' => 'Click Here!',
]
bash
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.