-
Notifications
You must be signed in to change notification settings - Fork 0
Complete Example
Nikolai Plath edited this page Jul 17, 2018
·
7 revisions
Install the libraries
composer require elkuku/g11n
npm install elkuku/g11n-js
Setup your directories like so:
msgid ""
msgstr ""
"Language: de-DE\n"
msgid "Hello test"
msgstr "Hallo Test"
msgid "Hello %param% test"
msgstr "Hallo %param% Test"
msgid "There is one monkey in the box."
msgid_plural "There are %d monkeys in the box."
msgstr[0] "Es ist ein Affe in der Schachtel."
msgstr[1] "Es sind %d Affen in der Schachtel."
msgid ""
msgstr ""
"Language: de-DE\n"
msgid "Hello test"
msgstr "Hallo Test"
msgid "Hello %param% test"
msgstr "Hallo %param% Test"
msgid "There is one monkey in the box."
msgid_plural "There are %d monkeys in the box."
msgstr[0] "Es ist ein Affe in der Schachtel."
msgstr[1] "Es sind %d Affen in der Schachtel."
<?php
use ElKuKu\G11n\G11n;
use ElKuKu\G11n\Language\Debugger;
use ElKuKu\G11n\Support\ExtensionHelper;
include 'vendor/autoload.php';
$dev = true;
// Set the language cache directory
ExtensionHelper::setCacheDir('cache');
// Set the language path(s)
ExtensionHelper::addDomainPath('someName', 'translations');
// Set the current language
G11n::setCurrent('de-DE');
// Debugging
G11n::setDebug($dev);
// Do a check here if you are in dev mode and clean the cache
if ($dev)
{
ExtensionHelper::cleanCache();
}
// Load the language file(s)
G11n::loadLanguage('mytest', 'someName');
?>
<table>
<tr>
<th>PHP</th>
<th>JS</th>
</tr>
<tr>
<td>
<?php
echo g11n3t('Hello test') . '<br>';
echo g11n3t('Hello nono test') . '<br>';
// Parameters
echo g11n3t('Hello %param% test', ['%param%' => 'ACME']) . '<br>';
echo g11n3t('Hello %param% nono', ['%param%' => 'ACME']) . '<br>';
// Pluralization
for ($count = 0; $count < 4; $count++)
{
echo sprintf(
g11n4t(
'There is one monkey in the box.',
'There are %d monkeys in the box.',
$count
),
$count
)
. '<br>';
}
echo g11n4t(
'There is nonono monkey in the box.',
'There are %d monkeys in the box.',
1
)
. '<br>';
?>
</td>
<td>
<script src="node_modules/g11n-js/dist/g11n-pack.js"></script>
<script><?php echo G11n::getJavaScript() ?></script>
<script>
document.write(g11n3t('Hello test'));
document.write('<br>');
document.write(g11n3t('Hello nono test'));
document.write('<br>');
// Parameters
document.write(g11n3t('Hello %param% test', {'%param%': 'ACME'}));
document.write('<br>');
document.write(g11n3t('Hello %param% nono', {'%param%': 'ACME'}));
document.write('<br>');
// Pluralization
for (i = 0; i < 4; i++) {
document.write(g11n4t(
'There is one monkey in the box.',
'There are %d monkeys in the box.',
i
).replace('%d', i));
document.write('<br>');
}
document.write(g11n4t(
'There is nonono monkey in the box.',
'There are %d monkeys in the box.',
1
));
</script>
</td>
</tr>
</table>
<hr/>
<?php
if ($dev)
{
Debugger::debugPrintTranslateds();
var_dump(G11n::getEvents());
}