phizzl/codeception-translations

此包已被弃用,不再维护。未建议替代包。

1.0.1 2017-06-15 00:05 UTC

This package is auto-updated.

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


README

该模块允许你在套件配置中添加翻译。当与多语言网站一起工作时,这可能很有用。

你可以将你的翻译定义为模块配置

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

当然,你也可以使用环境来拥有不同的翻译。

你还可以从单独的yaml文件加载翻译。你不必用数组结构填充translations选项,而是可以添加一个文件

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

如果你不使用绝对路径,所提供的文件将在你的配置数据目录中搜索。

现在你可以在你的Cest文件中翻译字符串。

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);
}