Behat MutlilingualExtension
Write tests once, test on multiple languages
Behat extension to help you do less work when you have multilanguage environment., (*1)
MultilingualExtension is a Behat extension designed to ease the work with multilingual sites. English language is used as a base and translations for each string are stored in a user defined file.
The main idea is to write your tests in English language and then run them against sites with different language than English. The website language is defined in YML profile., (*2)
Note that it is in very early version so some features may not work properly., (*3)
, (*4)
Installation
curl -sS https://getcomposer.org/installer | php
vim composer.json
{
"require": {
"kolev/multilingual-extension": "dev-master"
},
"config": {
"bin-dir": "bin"
}
}
Usage
MultilingualExtension is easy to use. First you need to add the extension to your profile in behat.yml
configuration file., (*5)
german_profile:
suites:
default:
contexts: {}
extensions:
Behat\MinkExtension:
files_path: %paths.base%/files
kolev\MultilingualExtension:
default_language: de
translations: translations.yml
The default_language
variable is used to define the website's default language.
The translations
variable is used to define the path to the translations file. The path is relative to the files_path
variable. So in this case the translations.yml
file should be placed in /files
folder., (*6)
The translations.yml
file structure is easy to read too., (*7)
"carrot":
de: "karrote"
fr: "carrote"
"cabbage":
de: "kohl"
fr: "chou"
The user can list as many words as he/she wants. Also many different languages for each word can be added., (*8)
It is important to use the same language prefix in translations.yml
file and when configuring the profile. For example define site's language as de
and add translations with de
., (*9)
Then it's time to write your test porperly in order to use the localized version of the string. For example:, (*10)
Feature: Multilingual Extension example feature
Scenario: Example of a Scenario for testing multilingual extension
Given I go to "/"
And I should see localized "carrot"
In this case if your run the test with german_profile
it will open the homepage and look for de
version of the word carrot
which in our case is karrote
., (*11)
FAQ
What if I have more than one language installed?
Language detection based on URL is introduced with version 0.0.2
. The extension tries to detect site's language based on URL. For example if you go to page http://example.com/de/ it will look for German translation of the string, if no language code found it will use the default_language
. It works for both clean and non-clean URLs., (*12)
What are the availabe languages supported?
List of all languages ISO codes can be found here, (*13)
Author
Contributors