PHP code example of mistralys / application-localization
1. Go to this page and download the library: Download mistralys/application-localization 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/ */
mistralys / application-localization example snippets
use AppLocalize\Localization;
Localization::addAppLocale('de_DE');
Localization::addAppLocale('fr_FR');
use AppLocalize\Localization;
$source = Localization::addSourceFolder(
'source-slug', // Must be unique: used in file names and to access the source programmatically
'Source label', // Human readable label
'Group label', // Group labels are used to group sources in the UI
'/path/to/ini/files/', // The localization files will be stored here
'/path/to/source/files/' // The PHP and JavaScript source files to search through are here
);
$source->excludeFolder('foldername');
$source->excludeFile('jquery'); // any file with "jquery" in its name
$source->excludeFile('jquery-ui.min.js'); // by exact file name match
use AppLocalize\Localization;
Localization::configure(
'/path/to/analysis/cache.json', // Where the text information cache may be saved
'/path/to/javascript/
use AppLocalize\Localization;
Localization::selectAppLocale('de_DE');
use function AppLocalize\t;
use function AppLocalize\pt;
use function AppLocalize\pts;
use function AppLocalize\tex;
use function AppLocalize\ptex;
use function AppLocalize\ptexs;
$amount = 50;
$text = t('We found %1$s entries.', $amount);
use function AppLocalize\ptex;
// Context information comes directly after the text.
ptex(
'Text to translate',
'Context explanation for translators.'
);
// Placeholder values come after the context information.
ptex(
'%1$s records',
'The placeholder contains the amount of records.',
42
);
use function AppLocalize\t;
$text = t('This is %1$sbold%2$s text.', '<strong>', '</strong>');
use function AppLocalize\t;
$textWithLink = t(
'Please refer to the %1$sdocumentation%2$s for further details.',
'<a href="http://...">',
'</a>'
);
use function AppLocalize\t;
$template = t('Entry number %1$s', '%1$s');
use function AppUtils\sb;
$html = (string)sb()
->bold(t('Easy string concatenation'))
->nl()
->t('For more information, see here:')
->link(t('Application Utils'), 'https://github.com/Mistralys/application-utils');
use AppLocalize\Localization;
use AppLocalize\Localization\Event\LocaleChanged;
Localization::onLocaleChanged(function(LocaleChanged $event) {
// do something
});
use AppLocalize\Localization;
use AppLocalize\Localization_Country_ES;
$countries = Localization::createCountries();
// Get a country by its two-letter ISO code
$germany = $countries->getByISO('de');
// Every country has a constant for its ISO code
$spain = $countries->getByISO(Localization_Country_ES::ISO_CODE);
// Or use the predefined list using choose():
$france = $countries->choose()->fr();
use AppLocalize\Localization;
use AppLocalize\Localization_Currency_EUR;
$currencies = Localization::createCurrencies();
// Get a currency by its three-letter ISO code
$dollar = $currencies->getByISO('USD');
// Every currency has a constant for its ISO code
$euro = $currencies->getByISO(Localization_Currency_EUR::ISO_CODE);
// Or use the predefined list using choose():
$pound = $currencies->choose()->gbp();
use AppLocalize\Localization;
$eurDE = Localization::createCountries()
->choose()
->de()
->getCurrency();
echo $eurDE->makeReadable(1445.42);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.