1. Go to this page and download the library: Download mmdm/sim-i18n 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/ */
mmdm / sim-i18n example snippets
composer
// to instantiate a translate object
$translate = new translate();
// then you should set directory and file of language
$translate->setTranslateDir('path_to_languages_directory');
$translate->setLocale(ISOLanguageCodes::LANGUAGE_ENGLISH);
// then use methods
$translate->translate($translate_key);
// to create a language file
// de -> German
$translate->createLanguageFile('de', 'path/to/languages/directory');
// this is better
$translate->createLanguageFile(ISOLanguageCodes::LANGUAGE_GERMAN, 'path/to/languages/directory');
// set locale to french
$translate->setLocale('fr');
// this is better
$translate->setLocale(ISOLanguageCodes::LANGUAGE_FRENCH);
$test_label = $translate->translate('labels.test');
// output:
// This is a test.
// simple usage when you configured directory and filename before
$translate->translate('a1');
// change them in runtime
// [this is not so much convenient!]
$translate
->setTranslateDir('direcoty_to_file_1_or_2')
->setLocale('en_or_other_languages')
->translate('a1_or_a2');
// above code with parameter
$translate
->setTranslateDir('direcoty_to_file_1_or_2')
->setLocale('en_or_other_languages')
->translate('c1_or_c2', ['user' => 'MMDM']);
//===================================================
// a convenient way to use above code
// with just change locale filename
$translate->translate('a1_or_a2', 'en_or_other_languages');
// above code with parameter
$translate->translate('c1_or_c2', 'en_or_other_languages', ['user' => 'MMDM']);
// a convenient way to use above code
// with changing directory + filename
$translate->translate('a1_or_a2', 'file:directory/en_or_other_languages');
return [
'choice' => '{0} none|{1} one|{2,} more than one ({count})',
];
echo $translate->translateChoice('choice', 4);
// more than one (4)
echo $translate->translateChoice('choice', 4, ['count' => 66]);
// more than one (66)
// it will return true
ISOLanguageCodes::isInLanguageCode(ISOLanguageCodes::LANGUAGE_CZECH);
// it will return false
// it is Persian-Farsi but in ISO 639-2 code
ISOLanguageCodes::isInLanguageCode('per');
// it will return true
$is_rtl = ISOLanguageCodes::isRtlLanguage(ISOLanguageCodes::LANGUAGE_PERSIAN_FARSI);
// it will return false
$is_rtl = ISOLanguageCodes::isRtlLanguage(ISOLanguageCodes::LANGUAGE_ENGLISH);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.