phizzl/codeception-translations

This package is abandoned and no longer maintained. No replacement package was suggested.

1.0.1 2017-06-15 00:05 UTC

This package is auto-updated.

Last update: 2022-11-12 23:25:52 UTC


README

The module allows you to add translations in your suite config. This may be usefull when working with a multilingual website.

You may define your translations as module config

actor: AcceptanceTester
modules:
    enabled:
        - \Phizzl\Codeception\Modules\Translations\TranslationsModule
    config:
        \Phizzl\Codeception\Modules\Translations\TranslationsModule:
            translations:
                "Welcome friend": "Willkommen Freund"
                "good": "gut"

Of course you can also use environments to have different translations.

You're also able to load translations from a separate yaml file. Instead filling the translations option with an array structure you can add a file

actor: AcceptanceTester
modules:
    enabled:
        - \Phizzl\Codeception\Modules\Translations\TranslationsModule
    config:
        \Phizzl\Codeception\Modules\Translations\TranslationsModule:
            translations: "lang_en.yml"

If you dont use an absolute path the given file will be searched in your configured data directory.

Now you are able to translate strings in your Cest files.

public function tryToTest(AcceptanceTester $I)
{
    $welcomeText = $I->translate("Welcome friend"); // result: Willkommen Freund
    
    $I->amOnPage('/');
    $I->see($welcomeText);
    
    /* You are also able to translate only placeholder within a string using the defined keys. Just use the ${key} expression in your string. */
    $statusText = $I->translate("Status: \${good}"); // result: Status: gut
    
    $I->see($statusText);
}