Skip to content
Nikolai Plath edited this page Jul 17, 2018 · 4 revisions

At a very minimal do the following:

  1. Create a composer project
  2. Add the library
  3. Create a /test.php file at the root of your repository (for demo purpose)
  4. Create the directories /someDir/someExtension/g11n/de-DE
  5. Create a language file de-DE.someExtension.po (see screen shot)
  6. Create a /cache directory

files-2

test.php

#!/usr/bin/env php
<?php

use ElKuKu\G11n\G11n;
use ElKuKu\G11n\Support\ExtensionHelper;

include 'vendor/autoload.php';

// Set the language cache directory
ExtensionHelper::setCacheDir('cache');

// Set the language path(s)
ExtensionHelper::addDomainPath('someName', 'someDir');

// Set the current language
G11n::setCurrent('de-DE');

// Do a check here if you are in dev mode
if (true /* dev mode */)
{
    ExtensionHelper::cleanCache();
}

// Load the language file(s)
G11n::loadLanguage('someExtension', 'someName');

echo g11n3t('Hello test');

de-DE.someExtension.po

msgid ""
msgstr ""
"Language: de-DE\n"

msgid "Hello test"
msgstr "Hallo Test"

Run the script.

$ ./test.php
Hallo Test

The output should be: Hallo Test

Note that language files will be parsed and cached, so you have to run the command

ExtensionHelper::cleanCache();

To see the changes.

Read about some more advanced Usage.