2424"""
2525
2626from collections import OrderedDict
27- from os import path as op
27+ from os import path as op , environ
2828import codecs
2929import re
3030import sys
3131import textwrap
3232
33+ import gettext
3334import glob2
3435import six
3536
3637from . import types
3738from . import exceptions
3839
40+ BASE_DIR = op .dirname (op .realpath (__file__ ))
41+ STEP_PARAM_RE = re .compile (r"\<(.+?)\>" )
42+ COMMENT_RE = re .compile (r'(^|(?<=\s))#' )
3943
4044# Global features dictionary
4145features = {}
46+ _step_prefixes = None
4247
4348
44- STEP_PREFIXES = [
45- ("Feature: " , types .FEATURE ),
46- ("Scenario Outline: " , types .SCENARIO_OUTLINE ),
47- ("Examples: Vertical" , types .EXAMPLES_VERTICAL ),
48- ("Examples:" , types .EXAMPLES ),
49- ("Scenario: " , types .SCENARIO ),
50- ("Background:" , types .BACKGROUND ),
51- ("Given " , types .GIVEN ),
52- ("When " , types .WHEN ),
53- ("Then " , types .THEN ),
54- ("@" , types .TAG ),
55- # Continuation of the previously mentioned step type
56- ("And " , None ),
57- ("But " , None ),
58- ]
49+ def set_step_prefixes (languages = None ):
50+ global _step_prefixes
5951
60- STEP_PARAM_RE = re .compile (r"\<(.+?)\>" )
61- COMMENT_RE = re .compile (r'(^|(?<=\s))#' )
52+ if _step_prefixes is None or languages :
53+ if languages is None :
54+ languages = environ .get ('PYTEST_BDD_LANGS' , 'en' )
55+
56+ _ = gettext .translation (
57+ 'step-prefixes' ,
58+ localedir = op .join (BASE_DIR , 'locales' ),
59+ languages = languages .split (',' ),
60+ ).gettext
61+
62+ _step_prefixes = [
63+ (_ ("Feature: " ), types .FEATURE ),
64+ (_ ("Scenario Outline: " ), types .SCENARIO_OUTLINE ),
65+ (_ ("Examples: Vertical" ), types .EXAMPLES_VERTICAL ),
66+ (_ ("Examples:" ), types .EXAMPLES ),
67+ (_ ("Scenario: " ), types .SCENARIO ),
68+ (_ ("Background:" ), types .BACKGROUND ),
69+ (_ ("Given " ), types .GIVEN ),
70+ (_ ("When " ), types .WHEN ),
71+ (_ ("Then " ), types .THEN ),
72+ ("@" , types .TAG ),
73+ # Continuation of the previously mentioned step type
74+ (_ ("And " ), None ),
75+ (_ ("But " ), None ),
76+ ]
77+
78+ return _step_prefixes
79+
80+
81+ set_step_prefixes ()
82+
83+
84+ def get_step_prefixes ():
85+ return _step_prefixes
6286
6387
6488def get_step_type (line ):
@@ -68,7 +92,7 @@ def get_step_type(line):
6892
6993 :return: SCENARIO, GIVEN, WHEN, THEN, or `None` if can't be detected.
7094 """
71- for prefix , _type in STEP_PREFIXES :
95+ for prefix , _type in get_step_prefixes () :
7296 if line .startswith (prefix ):
7397 return _type
7498
@@ -93,7 +117,7 @@ def parse_line(line):
93117
94118 :return: `tuple` in form ("<prefix>", "<Line without the prefix>").
95119 """
96- for prefix , _ in STEP_PREFIXES :
120+ for prefix , _ in get_step_prefixes () :
97121 if line .startswith (prefix ):
98122 return prefix .strip (), line [len (prefix ):].strip ()
99123 return "" , line
0 commit comments