2828from ..publish .messages import RideSettingsChanged
2929
3030
31+ def obtain_bdd_prefixes (language ):
32+ from robotide .lib .compat .parsing .language import Language
33+ lang = Language .from_name (language [0 ] if isinstance (language , list ) else language )
34+ bdd_prefixes = lang .bdd_prefixes
35+ return list (bdd_prefixes )
36+
37+
3138_PREFERRED_POPUP_SIZE = (200 , 400 )
3239_AUTO_SUGGESTION_CFG_KEY = "enable auto suggestions"
3340
3441
3542class _ContentAssistTextCtrlBase (wx .TextCtrl ):
3643
37- def __init__ (self , suggestion_source , ** kw ):
44+ def __init__ (self , suggestion_source , language = 'En' , ** kw ):
3845 super ().__init__ (** kw )
3946 from ..preferences import RideSettings
4047 _settings = RideSettings ()
@@ -45,6 +52,7 @@ def __init__(self, suggestion_source, **kw):
4552 self .color_secondary_foreground = self .general_settings ['secondary foreground' ]
4653 self .color_background_help = self .general_settings ['background help' ]
4754 self .color_foreground_text = self .general_settings ['foreground text' ]
55+ self .language = language
4856 self ._popup = ContentAssistPopup (self , suggestion_source )
4957 self .Bind (wx .EVT_KEY_DOWN , self .on_key_down )
5058 self .Bind (wx .EVT_CHAR , self .on_char )
@@ -308,9 +316,13 @@ def _populate_content_assist(self):
308316 (self .gherkin_prefix , value ) = self ._remove_bdd_prefix (value )
309317 return self ._popup .content_assist_for (value , row = self ._row )
310318
311- @staticmethod
312- def _remove_bdd_prefix (name ):
313- for match in ['given ' , 'when ' , 'then ' , 'and ' , 'but ' ]:
319+ def _remove_bdd_prefix (self , name ):
320+ bdd_prefix = []
321+ if self .language .lower () not in ['en' , 'english' ]:
322+ bdd_prefix = [f"{ x .lower ()} " for x in obtain_bdd_prefixes (self .language )]
323+ bdd_prefix += ['given ' , 'when ' , 'then ' , 'and ' , 'but ' ]
324+ # print(f"DEBUG: contentassist.py ContentAssistTextCtrlBase _remove_bdd_prefix bdd_prefix={bdd_prefix}")
325+ for match in bdd_prefix :
314326 if name .lower ().startswith (match ):
315327 return name [:len (match )], name [len (match ):]
316328 return '' , name
@@ -341,11 +353,11 @@ def dismiss(self):
341353
342354class ExpandingContentAssistTextCtrl (_ContentAssistTextCtrlBase , ExpandoTextCtrl ):
343355
344- def __init__ (self , parent , plugin , controller ):
356+ def __init__ (self , parent , plugin , controller , language = 'En' ):
345357 """ According to class MRO, super().__init__ in _ContentAssistTextCtrlBase will init ExpandoTextCtrl
346358 instance """
347359
348- _ContentAssistTextCtrlBase .__init__ (self , SuggestionSource (plugin , controller ),
360+ _ContentAssistTextCtrlBase .__init__ (self , SuggestionSource (plugin , controller ), language = language ,
349361 parent = parent , size = wx .DefaultSize ,
350362 style = wx .WANTS_CHARS | wx .TE_NOHIDESEL )
351363 self .SetBackgroundColour (context .POPUP_BACKGROUND )
@@ -356,8 +368,8 @@ def __init__(self, parent, plugin, controller):
356368
357369class ContentAssistTextCtrl (_ContentAssistTextCtrlBase ):
358370
359- def __init__ (self , parent , suggestion_source , size = wx .DefaultSize ):
360- super ().__init__ (suggestion_source , parent = parent ,
371+ def __init__ (self , parent , suggestion_source , language = 'En' , size = wx .DefaultSize ):
372+ super ().__init__ (suggestion_source , language = language , parent = parent ,
361373 size = size , style = wx .WANTS_CHARS | wx .TE_NOHIDESEL )
362374 self .SetBackgroundColour (Colour (self .color_background_help ))
363375 # self.SetOwnBackgroundColour(Colour(self.color_background_help))
@@ -367,8 +379,8 @@ def __init__(self, parent, suggestion_source, size=wx.DefaultSize):
367379
368380class ContentAssistTextEditor (_ContentAssistTextCtrlBase ):
369381
370- def __init__ (self , parent , suggestion_source , pos , size = wx .DefaultSize ):
371- super ().__init__ (suggestion_source ,
382+ def __init__ (self , parent , suggestion_source , pos , language = 'En' , size = wx .DefaultSize ):
383+ super ().__init__ (suggestion_source , language = language ,
372384 parent = parent , id = - 1 , value = "" , pos = pos , size = size ,
373385 style = wx .WANTS_CHARS | wx .BORDER_NONE | wx .WS_EX_TRANSIENT | wx .TE_PROCESS_ENTER |
374386 wx .TE_NOHIDESEL )
0 commit comments